Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changed the way
Serializable
classes are handled:Here is how a basic
Serializable
class looks like:The
Serializable
class must implement the following methods:serialize_to(buf: Buffer) -> None
: Serializes the object to a buffer.deserialize(buf: Buffer) -> Serializable
: Deserializes the object from a buffer.validate() -> None
: Validates the object's attributes, raising an exception if they are invalid.Added a test generator for
Serializable
classes:The
gen_serializable_test
function generates tests forSerializable
classes. It takes the following arguments:context
: The dictionary containing the context in which the generated test class will be placed (e.g.globals()
).cls
: TheSerializable
class to generate tests for.fields
: A list of fields where the test values will be placed.test_data
: A list of tuples containing either:((field1_value, field2_value, ...), expected_bytes)
: The values of the fields and the expected serialized bytes. This needs to work both ways, i.e.cls(field1_value, field2_value, ...) == cls.deserialize(expected_bytes).
((field1_value, field2_value, ...), exception)
: The values of the fields and the expected exception when validating the object.(exception, bytes)
: The expected exception when deserializing the bytes and the bytes to deserialize.The
gen_serializable_test
function generates a test class with the following tests:The generated test class will have the following tests:
Also this has 100% test coverage for all data types and packets.