Exemple #1
0
    def test_complains_about_unmapped_classes(self):
        del archiver.UNARCHIVE_CLASS_MAP['crap.Foo']

        with self.assertRaises(archiver.MissingClassMapping):
            self.unarchive('simple')

        archiver.update_class_map({'crap.Foo': FooArchive})
Exemple #2
0
 def test_dataclass_not_fully_mapped(self):
     archiver.update_class_map({
         'FooDataclass': DataclassMissingFields,
     })
     try:
         with self.assertRaises(archive_types.Error):
             self.unarchive('dataclass')
     finally:
         # Restore mapping.
         archiver.update_class_map({
             'FooDataclass': FooDataclass,
         })
Exemple #3
0
 def test_dataclass_ignore_not_fully_mapped(self):
     archiver.update_class_map({
         'FooDataclass': DataclassIgnoreMissingFields,
     })
     try:
         expected = DataclassIgnoreMissingFields(int_field=5)
         actual = self.unarchive('dataclass')
         self.assertEqual(actual, expected)
     finally:
         # Restore mapping.
         archiver.update_class_map({
             'FooDataclass': FooDataclass,
         })
Exemple #4
0
class NSNull:
    @staticmethod
    def decode_archive(archive_obj):
        return None


class NSError:
    @staticmethod
    def decode_archive(archive_obj):
        raise DvtException(archive_obj.decode('NSUserInfo')['NSLocalizedDescription'])


archiver.update_class_map({'DTSysmonTapMessage': DTTapMessage,
                           'DTTapHeartbeatMessage': DTTapMessage,
                           'DTTapStatusMessage': DTTapMessage,
                           'DTKTraceTapMessage': DTTapMessage,
                           'DTActivityTraceTapMessage': DTTapMessage,
                           'NSNull': NSNull,
                           'NSError': NSError})


class Channel(int):
    @classmethod
    def create(cls, value: int, service):
        channel = cls(value)
        channel._service = service
        return channel

    def receive_plist(self):
        return self._service.recv_plist(self)[0]
Exemple #5
0
        archive.encode('empty', obj.empty)
        archive.encode('recurse', obj.recursive)

    @staticmethod
    def decode_archive(archive):
        title = archive.decode('title')
        stamp = archive.decode('stamp')
        count = archive.decode('count')
        cats = archive.decode('categories')
        meta = archive.decode('metadata')
        empty = archive.decode('empty')
        recurse = archive.decode('recursive')
        return FooArchive(title, stamp, count, cats, meta, empty, recurse)


archiver.update_class_map({'crap.Foo': FooArchive})


@dataclasses.dataclass
class FooDataclass(archive_types.DataclassArchiver):
    int_field: int = 0
    str_field: str = ""
    float_field: float = -1.1
    list_field: list = dataclasses.field(default_factory=list)


@dataclasses.dataclass
class DataclassMissingFields(archive_types.DataclassArchiver):
    int_field: int = 0