-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Serializables (v3) #285
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ItsDrike
added
p: 2 - normal
Normal priority
a: API
Related to exposed core API of the project
t: optimization
Optimizations to the code (performance improvements, code cleanup, or other general optimizations)
labels
May 14, 2024
LiteApplication
force-pushed
the
nbt-serializable
branch
from
May 15, 2024 19:53
50be7bd
to
8506b2e
Compare
LiteApplication
force-pushed
the
nbt-serializable
branch
2 times, most recently
from
May 16, 2024 15:32
fabe6b3
to
be65798
Compare
Open
ItsDrike
requested changes
May 18, 2024
LiteApplication
force-pushed
the
nbt-serializable
branch
4 times, most recently
from
May 21, 2024 19:20
53d137f
to
bbab587
Compare
ItsDrike
requested changes
May 23, 2024
LiteApplication
force-pushed
the
nbt-serializable
branch
4 times, most recently
from
May 25, 2024 16:48
fc59b46
to
d6f2921
Compare
LiteApplication
force-pushed
the
nbt-serializable
branch
2 times, most recently
from
June 6, 2024 07:08
ffe24c8
to
deacc62
Compare
ItsDrike
requested changes
Jun 6, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one small nitpick and this should be good to go
Provide a way to test serialization, deserialization, validation and deserialization errors easily. This fixes Avoid repetition in tests for serialize+deserialize tests py-mine#64 and makes it easier to add new data types
- Added a `transform` method for type conversions and more. - Include NBT and Serializable into the Sphinx documentation. - Added more explicit error messages to serializable tests. - Added the possibility to specify the error message/arguments in the tests. - Added pytest to the docs requirements to list the test function in the docs.
- Split the changelog - Use TypeGuard correctly - Remove `transform` in favor of `__attrs_post_init__` to allow for a more personalized use of `validate` - Remove `define` from the docs, change format in changelog
LiteApplication
force-pushed
the
nbt-serializable
branch
from
June 7, 2024 15:53
d9396a3
to
0a5220c
Compare
ItsDrike
approved these changes
Jun 7, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
a: API
Related to exposed core API of the project
p: 2 - normal
Normal priority
t: optimization
Optimizations to the code (performance improvements, code cleanup, or other general optimizations)
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.
This uses the
Serializable
(#273) methods to validate and use the data in theNBTags
(#257) subclasses.The tests also make use of the new test generator introduced in #273.
EDIT : Let's merge this with 273 !
Original PR description :
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.