def test_circular_ref(self): foo = FooArchive('herp', timestamp(9001), 42, ['strawberries', 'dragonfruit'], {'key': 'value'}, False, None) foo.recursive = foo plist = bplist.loads( archiver.dumps(foo, class_map={'crap.Foo': FooArchive})) foo_obj = plist['$objects'][1] self.assertEqual(uid(1), foo_obj['recurse'])
def test_file_api(self): obj = {'foo': 42} data = bplist.dumps(obj) with io.BytesIO() as f: bplist.dump(obj, f) self.assertEqual(f.getvalue(), data) f.seek(0) restored = bplist.load(f) self.assertEqual(obj, restored) restored = bplist.loads(data) self.assertEqual(obj, restored)
def test_opaque(self): klass = archiver.OpaqueClassMap(archiver.ClassMap()).get_python_class( ['XXCustomObject', 'NSObject']) foo = klass() foo.foo = 'abc' foo.bar = 42 plist = bplist.loads(archiver.dumps(foo, opaque=True)) foo_obj = plist['$objects'][1] self.assertEqual('abc', plist['$objects'][foo_obj['foo']]) self.assertEqual(42, foo_obj['bar']) klass_uid = foo_obj['$class'] self.assertEqual(len(foo_obj), 3) class_obj = plist['$objects'][klass_uid] self.assertEqual('XXCustomObject', class_obj['$classname']) self.assertEqual(['XXCustomObject', 'NSObject'], class_obj['$classes'])
def unpack_archive_header(self): plist = bplist.loads(self.input) archiver = plist.get('$archiver') if archiver != 'NSKeyedArchiver': raise UnsupportedArchiver(archiver) version = plist.get('$version') if version != NSKeyedArchiveVersion: raise UnsupportedArchiveVersion(version) top = plist.get('$top') if not isinstance(top, dict): raise MissingTopObject(plist) self.top_uid = top.get('root') if not isinstance(self.top_uid, uid): raise MissingTopObjectUID(top) self.objects = plist.get('$objects') if not isinstance(self.objects, list): raise MissingObjectsArray(plist)
def test_parse_unknown(self): with self.assertRaisesRegex(TypeError, "expected bytes, module found"): bplist.loads(bplist)
def generate_and_parse(self, obj): self.assertEqual(obj, bplist.loads(bplist.dumps(obj)))
def test_parses_equivalent_to_plistlib(self): data = self.fixture('AccessibilityDefinitions') self.assertDictEqual(plistlib.loads(data), bplist.loads(data))
def test_generates_equivalent_accessibility_info(self): dict = plistlib.loads(self.fixture('AccessibilityDefinitions')) self.assertDictEqual(dict, bplist.loads(bplist.dumps(dict)))
def parse(self, plist): return bplist.loads(self.fixture(plist))