예제 #1
0
 def test_small_bitmap(self):
     """
     Tests initializing with a bitmap that is too small
     (e.g. less than or equal to the extra_buffer() size)
     """
     with pytest.raises(ValueError):
         cBloom(Bitmap(cBloom.extra_buffer()), 3)
예제 #2
0
    def test_close_does_flush(self):
        """
        Tests that a close does flush
        """
        bitmap = Bitmap(1024, "testccloseflush.mmap")
        bf = cBloom(bitmap, 2)
        [bf.add("test%d" % x) for x in xrange(1000)]
        bf.close()

        # Make a new bitmap
        bitmap = Bitmap(1024, "testccloseflush.mmap")
        bf = cBloom(bitmap, 20)
        assert bf.k_num == 2  # Should restore
        assert len(bf) == 1000
        assert all([bf.__contains__("test%d" % x) for x in xrange(1000)])
        bf.close()
예제 #3
0
 def test_flushclose(self):
     """
     Tests that a flush and close does not cause issues
     """
     bitmap = Bitmap(1024, "testflushclose.mmap")
     bf = cBloom(bitmap, 2)
     bf.flush()
     bf.close()
예제 #4
0
 def test_doubleclose(self):
     """
     Tests that a double close does not cause problems
     """
     bitmap = Bitmap(1024, "testdoubleclose.mmap")
     bf = cBloom(bitmap, 2)
     bf.close()
     bf.close()
예제 #5
0
    def test_flush(self):
        """
        Tests that a flushes flushes the contents
        """
        bitmap = Bitmap(1024, "testcflush.mmap")
        bf = cBloom(bitmap, 2)
        [bf.add("test%d" % x) for x in xrange(1000)]
        bf.flush()

        # Make a new bitmap
        bitmap2 = Bitmap(1024, "testcflush.mmap")
        bf1 = cBloom(bitmap2, 20)
        assert bf1.k_num == 2  # Should restore
        assert len(bf1) == 1000
        assert all([bf1.__contains__("test%d" % x) for x in xrange(1000)])

        bf1.close()
        bf.close()
예제 #6
0
    def test_swap_2(self):
        """
        Swaps the mmap files from one implementation to another,
        check that things work. Start with pyBloom, then cBloom.
        """
        bytes, k = pyBloom.params_for_capacity(2e4, 1e-3)
        bitmap = Bitmap(bytes, "testswap2.mmap")
        bf1 = pyBloom(bitmap, k)
        [bf1.add("foo%d" % x) for x in xrange(20000)]
        bf1.close()

        # Make a new bitmap
        bitmap = Bitmap(bytes, "testswap2.mmap")
        bf2 = cBloom(bitmap, 50)
        assert len(bf2) == 20000  # Should reload size and k
        assert bf2.k_num == k

        # Check all the entries
        assert all([bf2.__contains__("foo%d" % x) for x in xrange(20000)])
        bf2.close()
예제 #7
0
    def test_equality_2(self):
        """
        Tests that the two implementation generate matching mmaps
        """
        bytes, k = cBloom.params_for_capacity(2e4, 1e-3)
        bitmap = Bitmap(bytes, "testcompatc2.mmap")
        bf1 = cBloom(bitmap, k)
        [bf1.add("foo%d" % x) for x in xrange(20000)]

        # Make a new bitmap
        bitmap = Bitmap(bytes, "testcompatpy2.mmap")
        bf2 = pyBloom(bitmap, k)
        [bf2.add("foo%d" % x) for x in xrange(20000)]

        # Check the lengths
        assert len(bf1) == len(bf2)
        bf1.close()
        bf2.close()

        # Compare the mmap files
        self.compare_files("testcompatc2.mmap", "testcompatpy2.mmap")
예제 #8
0
 def test_sane_k(self):
     """
     Test the k value is sanity checked
     """
     with pytest.raises(ValueError):
         cBloom(Bitmap(16), 0)
예제 #9
0
 def test_no_bitmap(self):
     """
     Tests the constructor complains when there is no bitmap
     """
     with pytest.raises(ValueError):
         cBloom(None, 3)