structo 0.0.5__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {structo-0.0.5 → structo-0.0.6}/PKG-INFO +1 -1
  2. {structo-0.0.5 → structo-0.0.6}/structo/__init__.py +1 -1
  3. {structo-0.0.5 → structo-0.0.6}/structo/serialise.py +1 -1
  4. structo-0.0.6/tests/test_object.py +54 -0
  5. {structo-0.0.5 → structo-0.0.6}/.gitignore +0 -0
  6. {structo-0.0.5 → structo-0.0.6}/LICENSE +0 -0
  7. {structo-0.0.5 → structo-0.0.6}/README.md +0 -0
  8. {structo-0.0.5 → structo-0.0.6}/examples/custom_serializer.py +0 -0
  9. {structo-0.0.5 → structo-0.0.6}/examples/iterable_serializer.py +0 -0
  10. {structo-0.0.5 → structo-0.0.6}/examples/wav.py +0 -0
  11. {structo-0.0.5 → structo-0.0.6}/pyproject.toml +0 -0
  12. {structo-0.0.5 → structo-0.0.6}/pytest.ini +0 -0
  13. {structo-0.0.5 → structo-0.0.6}/structo/object.py +0 -0
  14. {structo-0.0.5 → structo-0.0.6}/structo/packed.py +0 -0
  15. {structo-0.0.5 → structo-0.0.6}/structo/serializer.py +0 -0
  16. {structo-0.0.5 → structo-0.0.6}/structo/types/__init__.py +0 -0
  17. {structo-0.0.5 → structo-0.0.6}/structo/types/array.py +0 -0
  18. {structo-0.0.5 → structo-0.0.6}/structo/types/blob.py +0 -0
  19. {structo-0.0.5 → structo-0.0.6}/structo/types/buffer.py +0 -0
  20. {structo-0.0.5 → structo-0.0.6}/structo/types/list.py +0 -0
  21. {structo-0.0.5 → structo-0.0.6}/structo/types/literal.py +0 -0
  22. {structo-0.0.5 → structo-0.0.6}/structo/types/object.py +0 -0
  23. {structo-0.0.5 → structo-0.0.6}/structo/types/packed.py +0 -0
  24. {structo-0.0.5 → structo-0.0.6}/structo/types/primatives.py +0 -0
  25. {structo-0.0.5 → structo-0.0.6}/structo/types/string.py +0 -0
  26. {structo-0.0.5 → structo-0.0.6}/structo/utils.py +0 -0
  27. {structo-0.0.5 → structo-0.0.6}/tests/test_array.py +0 -0
  28. {structo-0.0.5 → structo-0.0.6}/tests/test_packed.py +0 -0
  29. {structo-0.0.5 → structo-0.0.6}/tests/test_primatives.py +0 -0
  30. {structo-0.0.5 → structo-0.0.6}/tests/test_size.py +0 -0
  31. {structo-0.0.5 → structo-0.0.6}/tests/utils.py +0 -0
  32. {structo-0.0.5 → structo-0.0.6}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: structo
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: Structify
5
5
  Author-email: Ben Brady <benbradybusiness@gmail.com>
6
6
  License-Expression: MIT
@@ -2,7 +2,7 @@
2
2
  Structify
3
3
  """
4
4
 
5
- __version__ = "0.0.5"
5
+ __version__ = "0.0.6"
6
6
 
7
7
  from .serializer import Serializer, Serialiable
8
8
  from .serialise import get_serializer
@@ -12,7 +12,7 @@ def get_serializer(format: type) -> Serializer:
12
12
 
13
13
  return serializer
14
14
 
15
- if isinstance(format, Serialiable):
15
+ if issubclass(format, Serialiable):
16
16
  return format.serializer()
17
17
 
18
18
  # Nicely formatted errors:
@@ -0,0 +1,54 @@
1
+ from utils import test
2
+ import typing as t
3
+
4
+ import structo as st
5
+
6
+
7
+ @test("SerialiableObject: object")
8
+ def _():
9
+ class Foo(st.SerializableObject):
10
+ a: t.Annotated[int, st.uint8]
11
+
12
+ obj = Foo(a=1)
13
+ assert obj == Foo.from_bytes(obj.to_bytes())
14
+
15
+
16
+ @test("SerialiableObject: multiple attributes")
17
+ def _():
18
+ class Foo(st.SerializableObject):
19
+ a: t.Annotated[int, st.uint8]
20
+ b: t.Annotated[int, st.uint16_BE]
21
+
22
+ obj = Foo(a=1, b=256)
23
+ assert obj == Foo.from_bytes(obj.to_bytes())
24
+
25
+
26
+ @test("SerialiableObject: sizeof")
27
+ def _():
28
+
29
+ class Foo(st.SerializableObject):
30
+ a: t.Annotated[int, st.uint8]
31
+ b: t.Annotated[str, st.uint8]
32
+
33
+ assert Foo.sizeof() == 2
34
+
35
+
36
+ @test("SerialiableObject: sizeof unknowable")
37
+ def _():
38
+ class Foo(st.SerializableObject):
39
+ a: t.Annotated[int, st.uint8]
40
+ b: t.Annotated[str, st.String(st.uint8)]
41
+
42
+ assert Foo.sizeof() is None
43
+
44
+
45
+ @test("SerialiableObject: nested object")
46
+ def _():
47
+ class Foo(st.SerializableObject):
48
+ a: t.Annotated[int, st.uint8]
49
+
50
+ class Bar(st.SerializableObject):
51
+ foo: Foo
52
+
53
+ obj = Bar(foo=Foo(1))
54
+ assert obj == Bar.from_bytes(obj.to_bytes())
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes