Beispiel #1
0
    def test_init(self):
        with self.subTest(desc="name empty"):
            with self.assertRaises(ValueError) as rai:
                PluginInfo('', '1.0.0', 'example.com')
            self.assertEqual('Plugin name cannot be empty.', str(rai.exception))

        with self.subTest(desc="host empty"):
            with self.assertRaises(ValueError) as rai:
                PluginInfo('Blub', '1.0.0', '')
            self.assertEqual('Plugin host cannot be empty.', str(rai.exception))

        with self.subTest(desc="invalid version"):
            version = '1.0.0.dd'
            with self.assertRaises(InvalidVersion) as rai:
                PluginInfo('Blub', version, 'example.com')
            self.assertEqual('Plugin version is not PEP440 conform: {version}'.format(version=version),
                             str(rai.exception))
Beispiel #2
0
 def test_equality(self):
     with self.subTest(desc="different type"):
         self.assertFalse(self.info == "blub")
         self.assertTrue(self.info != "blub")
     with self.subTest(desc="equal"):
         plugin = PluginInfo('Blub', '1.0.0', 'example.com')
         self.assertTrue(self.info == plugin)
         self.assertFalse(self.info != plugin)
     with self.subTest(desc="unequal"):
         plugin = PluginInfo('Whatever', '1.0.0', 'example.com')
         self.assertFalse(self.info == plugin)
         self.assertTrue(self.info != plugin)
         plugin = PluginInfo('Blub', '2.4.5', 'example.com')
         self.assertFalse(self.info == plugin)
         self.assertTrue(self.info != plugin)
         plugin = PluginInfo('Blub', '1.0.0', 'example.org')
         self.assertFalse(self.info == plugin)
         self.assertTrue(self.info != plugin)
 def test_equality(self):
     with self.subTest(desc="different type"):
         self.assertFalse(self.plugin == "blub")
         self.assertTrue(self.plugin != "blub")
     with self.subTest(desc="equal"):
         plugin = Plugin(PluginInfo('test', '1.0.0', 'raw.githubusercontent.com'))
         self.assertTrue(self.plugin == plugin)
         self.assertFalse(self.plugin != plugin)
     with self.subTest(desc="unequal"):
         plugin = Plugin(PluginInfo('blub', '1.0.0', 'raw.githubusercontent.com'))
         self.assertFalse(self.plugin == plugin)
         self.assertTrue(self.plugin != plugin)
         plugin = Plugin(PluginInfo('test', '2.0.0', 'raw.githubusercontent.com'))
         self.assertFalse(self.plugin == plugin)
         self.assertTrue(self.plugin != plugin)
         plugin = Plugin(PluginInfo('test', '1.0.0', 'www.example.com'))
         self.assertFalse(self.plugin == plugin)
         self.assertTrue(self.plugin != plugin)
    def test_load_save_savestate(self):
        with self.subTest(desc="default return"):
            result = SaveState(dynamic_data.SAVE_STATE_VERSION,
                               PluginInfo('test', '1.0.0', 'raw.githubusercontent.com'), datetime(1970, 1, 1), {})
            self.assertEqual(result, self.plugin.load_save_state())

        with self.subTest(desc="load without errors"):
            self.plugin.save_save_state(self.eg_data)
            save_state = self.plugin.load_save_state()
            result = SaveState(dynamic_data.SAVE_STATE_VERSION, self.plugin.info, self.plugin.last_update, self.eg_data)
            self.assertEqual(save_state, result)

        with self.subTest(desc="different save state version"):
            plugin = Plugin(PluginInfo("test", "1.0.0", "host"))
            plugin.save_save_state(self.eg_data)
            dynamic_data.SAVE_STATE_VERSION = Version('0.4.2')
            with self.assertRaises(PluginException):
                plugin.load_save_state()
            self.setUp()

        with self.subTest(desc="different plugin version"):
            plugin = Plugin(PluginInfo("test", "1.0.0", "host"))
            plugin.save_save_state(self.eg_data)
            plugin = Plugin(PluginInfo("test", "2.0.0", "host"))
            with self.assertRaises(PluginException):
                plugin.load_save_state()

        with self.subTest(desc="different plugin name"):
            plugin = Plugin(PluginInfo("test", "1.0.0", "host"))
            plugin.save_save_state(self.eg_data)
            plugin._info.name = "different"
            with self.assertRaises(PluginException):
                plugin.load_save_state()

        with self.subTest(desc="json parse error"):
            create_test_file(self.plugin._save_state_file)
            with self.assertRaises(PluginException):
                self.plugin.load_save_state()

        with self.subTest(desc="json parse error"):
            with open(self.plugin._save_state_file, 'wb') as writer:
                writer.write(str.encode('{}'))
            with self.assertRaises(PluginException):
                self.plugin.load_save_state()
    def from_protobuf(cls, proto: SaveStateProto) -> 'SaveState':
        """
        Constructor from protobuf. Can raise ValueErrors from called from_protobuf() parsers.

        :param proto: protobuf structure
        :type proto: ~unidown.plugin.protobuf.save_state_pb2.SaveStateProto
        :return: the SaveState
        :rtype: ~unidown.plugin.save_state.SaveState
        :raises ValueError: version of SaveState does not exist or is empty inside the protobuf
        :raises ~packaging.version.InvalidVersion: version is not PEP440 conform
        """
        data_dict = {}
        for key, link_item in proto.data.items():
            data_dict[key] = LinkItem.from_protobuf(link_item)
        if proto.version == "":
            raise ValueError("version of SaveState does not exist or is empty inside the protobuf.")
        try:
            version = Version(proto.version)
        except InvalidVersion:
            raise InvalidVersion('Plugin version is not PEP440 conform: {version}'.format(version=proto.version))
        return cls(version, PluginInfo.from_protobuf(proto.plugin_info), Timestamp.ToDatetime(proto.last_update),
                   data_dict)
 def test_equality(self):
     with self.subTest(desc="different type"):
         self.assertFalse(self.save == "blub")
         self.assertTrue(self.save != "blub")
     with self.subTest(desc="equal"):
         save = SaveState(Version('1'),
                          PluginInfo('Blub', '1.0.0', 'example.com'),
                          datetime(1996, 12, 4),
                          {'item': LinkItem('blub', datetime(1996, 12, 4))})
         self.assertTrue(self.save == save)
         self.assertFalse(self.save != save)
     with self.subTest(desc="unequal"):
         save = SaveState(Version('2'),
                          PluginInfo('Blub', '1.0.0', 'example.com'),
                          datetime(1996, 12, 4),
                          {'item': LinkItem('blub', datetime(1996, 12, 4))})
         self.assertFalse(self.save == save)
         self.assertTrue(self.save != save)
         save = SaveState(Version('1'),
                          PluginInfo('whatever', '1.0.0', 'example.com'),
                          datetime(1996, 12, 4),
                          {'item': LinkItem('blub', datetime(1996, 12, 4))})
         self.assertFalse(self.save == save)
         self.assertTrue(self.save != save)
         save = SaveState(Version('1'),
                          PluginInfo('Blub', '1.0.0', 'example.com'),
                          datetime(2000, 12, 4),
                          {'item': LinkItem('blub', datetime(1996, 12, 4))})
         self.assertFalse(self.save == save)
         self.assertTrue(self.save != save)
         save = SaveState(
             Version('1'), PluginInfo('Blub', '1.0.0', 'example.com'),
             datetime(1996, 12, 4),
             {'item2': LinkItem('blub', datetime(1996, 12, 4))})
         self.assertFalse(self.save == save)
         self.assertTrue(self.save != save)
         save = SaveState(Version('1'),
                          PluginInfo('Blub', '1.0.0', 'example.com'),
                          datetime(1996, 12, 4),
                          {'item': LinkItem('blub', datetime(2000, 12, 4))})
         self.assertFalse(self.save == save)
         self.assertTrue(self.save != save)
Beispiel #7
0
    def test_from_protobuf(self):
        with self.subTest(desc="name empty"):
            proto = PluginInfoProto()
            proto.name = ""
            with self.assertRaises(ValueError):
                PluginInfo.from_protobuf(proto)

        with self.subTest(desc="version empty"):
            proto = PluginInfoProto()
            proto.name = "blub"
            proto.version = ""
            with self.assertRaises(ValueError):
                PluginInfo.from_protobuf(proto)

        with self.subTest(desc="host empty"):
            proto = PluginInfoProto()
            proto.name = "blub"
            proto.version = "1.0.0"
            proto.host = ""
            with self.assertRaises(ValueError):
                PluginInfo.from_protobuf(proto)
 def setUp(self):
     self.save = SaveState(
         Version('1'), PluginInfo('Blub', '1.0.0', 'example.com'),
         datetime(1996, 12,
                  4), {'item': LinkItem('blub', datetime(1996, 12, 4))})
Beispiel #9
0
 def setUp(self):
     self.info = PluginInfo('Blub', '1.0.0', 'example.com')
Beispiel #10
0
 def __init__(self, info: PluginInfo = None):
     if info is None:
         super().__init__(
             PluginInfo('test', '1.0.0', 'raw.githubusercontent.com'))
     else:
         super().__init__(info)