2020
2121import typedstream .archiving
2222import typedstream .stream
23+ import typedstream .types .foundation
2324
2425
2526DATA_DIR = pathlib .Path (__file__ ).parent / "data"
2930 "Empty2D macOS 13.gcx" ,
3031]
3132
33+ STRING_TEST_DATA = b"\x04 \x0b streamtyped\x81 \xe8 \x03 \x84 \x01 @\x84 \x84 \x84 \x08 NSString\x01 \x84 \x84 \x08 NSObject\x00 \x85 \x84 \x01 +\x0c string value\x86 "
34+
3235
3336class TypedstreamReadTests (unittest .TestCase ):
34- def test_read_stream (self ) -> None :
37+ def test_read_data_stream (self ) -> None :
38+ """Some simple test data can be read as a low-level stream."""
39+
40+ with typedstream .stream .TypedStreamReader .from_data (STRING_TEST_DATA ) as ts :
41+ events = list (ts )
42+
43+ self .assertEqual (events , [
44+ typedstream .stream .BeginTypedValues ([b"@" ]),
45+ typedstream .stream .BeginObject (),
46+ typedstream .stream .SingleClass (name = b"NSString" , version = 1 ),
47+ typedstream .stream .SingleClass (name = b"NSObject" , version = 0 ),
48+ None ,
49+ typedstream .stream .BeginTypedValues ([b"+" ]),
50+ b"string value" ,
51+ typedstream .stream .EndTypedValues (),
52+ typedstream .stream .EndObject (),
53+ typedstream .stream .EndTypedValues (),
54+ ])
55+
56+ def test_read_data_unarchive (self ) -> None :
57+ """Some simple test data can be unarchived into an object."""
58+
59+ root = typedstream .unarchive_from_data (STRING_TEST_DATA )
60+ self .assertEqual (type (root ), typedstream .types .foundation .NSString )
61+ self .assertEqual (root .value , "string value" )
62+
63+ def test_read_file_stream (self ) -> None :
3564 """All the test files can be read as a low-level stream."""
3665
3766 for name in READ_TEST_FILE_NAMES :
@@ -40,7 +69,7 @@ def test_read_stream(self) -> None:
4069 for _ in ts :
4170 pass
4271
43- def test_read_unarchive (self ) -> None :
72+ def test_read_file_unarchive (self ) -> None :
4473 """All the test files can be unarchived into objects."""
4574
4675 for name in READ_TEST_FILE_NAMES :
0 commit comments