def test_str_and_not_str_id(self):
        info = object_util.get_info_by_id(self.info_by_id, 1,
                                          self.property_names)
        info2 = object_util.get_info_by_id(self.info_by_id, "1",
                                           self.property_names)

        self.assertEqual(info, info2)
        self.assertIs(info, info2)
    def test_empty_args(self):
        # None without info_by_id
        info = object_util.get_info_by_id(None, None)
        expected = None

        self.assertEqual(info, expected)

        # None without info_by_id
        info = object_util.get_info_by_id(None, "1")
        expected = None

        self.assertEqual(info, expected)
    def test_aliases(self):
        info = object_util.get_info_by_id(self.info_by_id, 1,
                                          self.property_names)
        # By alias
        info2 = object_util.get_info_by_id(self.info_by_id, 4,
                                           self.property_names)
        # Alias cached
        info3 = self.info_by_id["4"]

        self.assertEqual(info, info2)
        self.assertIs(info, info2)
        self.assertEqual(info, info3)
        self.assertIs(info, info3)
    def test_get_info_from_array(self):
        info = object_util.get_info_by_id(self.info_by_id, "3",
                                          self.property_names)
        # expected = [3, "Lobby 3", [6, 7, 8]]
        expected = {"lobby_id": 3, "lobby_name": "Lobby 3", "rooms": [6, 7, 8]}

        self.assertEqual(info, expected)
        self.assertIs(info, self.info_by_id["3"])
示例#5
0
 def get_backend_info(self, backend=None):
     value = object_util.get_info_by_id(self._backend_info_by_backend,
                                        backend)
     if not value:
         self.logging.warning(
             "C WARNING! (get_backend_info) There is no backend_info in backends.json for "
             "backend: %s", backend)
     return value
    def test_inheritance(self):
        info = object_util.get_info_by_id(self.info_by_id, "2",
                                          self.property_names)
        # Resolved cached
        info2 = self.info_by_id["2"]
        expected = {"lobby_id": 2, "lobby_name": "Lobby 2", "rooms": [6, 7, 8]}

        self.assertEqual(info, expected)
        self.assertEqual(info, info2)
        self.assertIs(info, info2)
    def test_get_info_from_object(self):
        info = object_util.get_info_by_id(self.info_by_id, "simple",
                                          self.property_names)
        expected = {
            "lobby_id": "simple",
            "lobby_name": "Lobby S",
            "rooms": [1, 2]
        }

        self.assertEqual(info, expected)
        self.assertIs(info, self.info_by_id["simple"])
    def test_nested_inheritance_and_aliases(self):
        info = object_util.get_info_by_id(self.info_by_id, "4",
                                          self.property_names)
        # Resolved cached
        info1 = self.info_by_id["1"]
        info2 = self.info_by_id["2"]
        info3 = self.info_by_id["3"]
        # Result cached
        info4 = self.info_by_id["4"]
        expected1 = {
            "lobby_id": "11",
            "lobby_name": "Lobby 2",
            "rooms": [6, 7, 8]
        }
        expected2 = {
            "lobby_id": 2,
            "lobby_name": "Lobby 2",
            "rooms": [6, 7, 8]
        }
        # -expected3 = [
        #     3,
        #     "Lobby 3",
        #     [6, 7, 8]
        # ]
        expected3 = {
            "lobby_id": 3,
            "lobby_name": "Lobby 3",
            "rooms": [6, 7, 8]
        }

        self.assertEqual(info1, expected1)
        self.assertEqual(info2, expected2)
        self.assertEqual(info3, expected3)
        self.assertEqual(info, info1)
        self.assertEqual(info, info4)
        self.assertIs(info, info1)
        self.assertIs(info, info4)
示例#9
0
 def get_info_by_id(self, id=None):
     return object_util.get_info_by_id(self._info_by_id, id,
                                       self._property_names)