Example #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):
         pyBloom(Bitmap(pyBloom.extra_buffer()), 3)
Example #2
0
    def test_close_does_flush(self):
        """
        Tests that a close does flush
        """
        bitmap = Bitmap(1024, "testpycloseflush.mmap")
        bf = pyBloom(bitmap, 2)
        [bf.add("test%d" % x) for x in xrange(1000)]
        bf.close()

        # Make a new bitmap
        bitmap = Bitmap(1024, "testpycloseflush.mmap")
        bf = pyBloom(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()
Example #3
0
 def test_flushclose(self):
     """
     Tests that a flush and close does not cause issues
     """
     bitmap = Bitmap(1024, "testflushclose.mmap")
     bf = pyBloom(bitmap, 2)
     bf.flush()
     bf.close()
Example #4
0
 def test_doubleclose(self):
     """
     Tests that a double close does not cause problems
     """
     bitmap = Bitmap(1024, "testdoubleclose.mmap")
     bf = pyBloom(bitmap, 2)
     bf.close()
     bf.close()
Example #5
0
    def test_flush(self):
        """
        Tests that a flushes flushes the contents
        """
        bitmap = Bitmap(1024, "testpyflush.mmap")
        bf = pyBloom(bitmap, 2)
        [bf.add("test%d" % x) for x in xrange(1000)]
        bf.flush()

        # Make a new bitmap
        bitmap2 = Bitmap(1024, "testpyflush.mmap")
        bf1 = pyBloom(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()
Example #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()
Example #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")
Example #8
0
 def test_sane_k(self):
     """
     Test the k value is sanity checked
     """
     with pytest.raises(ValueError):
         pyBloom(Bitmap(16), 0)
Example #9
0
 def test_no_bitmap(self):
     """
     Tests the constructor complains when there is no bitmap
     """
     with pytest.raises(ValueError):
         pyBloom(None, 3)