Example #1
0
    def test_unique_violation(self):
        arr = [43, 23, 12, 22, -10, 47, 0, 47, 104, 65]
        store1 = SmallUniqueKeyStore(self.io, IntegerType(), initialize=True)
        with pytest.raises(PyDBUniqueKeyViolation) as ex:
            for x in arr:
                store1.insert(x)

        assert ex.value.message == "Unique key violation: 47"
Example #2
0
    def test_read_write_header(self):
        store1 = SmallUniqueKeyStore(self.io, IntegerType(), initialize=True)
        for x in range(10):
            store1.insert(x)

        assert store1.count == 10

        self.reopen_file()

        store2 = SmallUniqueKeyStore(self.io, IntegerType())
        assert store2.count == 10
Example #3
0
    def test_remove_center_elem(self):
        arr = [43, 23, 12, 22, -10, 47, 0, 46, 104, 65]
        store1 = SmallUniqueKeyStore(self.io, IntegerType(), initialize=True)
        for x in arr:
            store1.insert(x)

        store1.remove(47)
        assert store1.get_data() == [x for x in sorted(arr) if x != 47]
Example #4
0
    def test_sorted_data(self):
        arr = [43, 23, 12, 22, -10, 48, 0, 99, 104, 65]
        store1 = SmallUniqueKeyStore(self.io, IntegerType(), initialize=True)
        for x in arr:
            store1.insert(x)

        assert store1.count == 10
        assert store1.get_data() == sorted(arr)

        self.reopen_file()

        store2 = SmallUniqueKeyStore(self.io, IntegerType())
        assert store2.get_data() == sorted(arr)
        assert store2.count == 10
Example #5
0
    def test_not_exist_center(self):
        arr = [43, 23, 12, 22, -10, 47, 0, 46, 104, 65]
        store1 = SmallUniqueKeyStore(self.io, IntegerType(), initialize=True)
        for x in arr:
            store1.insert(x)

        with pytest.raises(PyDBKeyNotFoundError) as ex:
            store1.remove(51)
        assert ex.value.message == "Not found: 51"