Пример #1
0
    def test_initial_value_values_are_retrieved(self):
        expected_dict = {"one": 1, "two": 2, "three": 3, "four": 4}
        sut = PersistentDict(self.storage_path, initial_dict=expected_dict)

        actual_values_set = set()
        for value in sut.values():
            actual_values_set.add(value)

        self.assertSetEqual(set(expected_dict.values()), actual_values_set)
Пример #2
0
    def test_initial_value_is_retrieved(self):
        expected_dict = {"one": 1, "two": 2, "three": 3, "four": 4}
        sut = PersistentDict(self.storage_path, initial_dict=expected_dict)

        actual_dict = {}
        for key, value in sut.items():
            actual_dict[key] = value

        self.assertDictEqual(expected_dict, actual_dict)
Пример #3
0
    def test_remove_item(self):
        initial_dict = {"one": 1, "two": 2, "three": 3, "four": 4}
        item_to_remove = "three"
        expected_dict = {"one": 1, "two": 2, "four": 4}
        sut = PersistentDict(self.storage_path, initial_dict=initial_dict)

        sut.pop(item_to_remove)

        actual_values_set = set()
        for value in sut.values():
            actual_values_set.add(value)

        self.assertSetEqual(set(expected_dict.values()), actual_values_set)
Пример #4
0
    def test_get_item(self):
        expected_item = "expected item"
        key = "new key"
        sut = PersistentDict(self.storage_path)

        sut[key] = expected_item

        self.assertEqual(expected_item, sut[key])
Пример #5
0
    def test_initial_value_keys_are_retrieved_directly(self):
        expected_dict = {"one": 1, "two": 2, "three": 3, "four": 4}
        sut = PersistentDict(self.storage_path, initial_dict=expected_dict)

        actual_keys_set = set()
        for key in sut:
            actual_keys_set.add(key)

        self.assertSetEqual(set(expected_dict.keys()), actual_keys_set)
Пример #6
0
    def test_set_item(self):
        sut = PersistentDict(self.storage_path)

        sut["new_key"] = "new item"
Пример #7
0
 def test_initial_value_is_not_a_dict_raise(self):
     self.assertRaises(TypeError,
                       lambda: PersistentDict(self.storage_path, int()))
Пример #8
0
    def test_create(self):
        sut = PersistentDict(self.storage_path)

        self.assertIsInstance(sut, PersistentDict)