File: simpletest.py

package info (click to toggle)
pybloomfiltermmap 0.3.11-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,656 kB
  • ctags: 835
  • sloc: ansic: 1,127; python: 297; makefile: 7
file content (55 lines) | stat: -rwxr-xr-x 1,689 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import unittest
import tempfile

import pybloomfilter

from tests import with_test_file

class SimpleTestCase(unittest.TestCase):
    @with_test_file
    def test_number(self, filename):
        bf = pybloomfilter.BloomFilter(100, 0.01, filename)
        bf.add(1234)
        self.assertEquals(1234 in bf, True)

    @with_test_file
    def test_string(self, filename):
        bf = pybloomfilter.BloomFilter(100, 0.01, filename)
        bf.add("test")
        self.assertEquals("test" in bf, True)

    @with_test_file
    def test_others(self, filename):
        bf = pybloomfilter.BloomFilter(100, 0.01, filename)
        for elem in (1.2, 2343L, (1, 2), object(), u'\u2131\u3184'):
            bf.add(elem)
            self.assertEquals(elem in bf, True)

    def test_number_nofile(self):
        bf = pybloomfilter.BloomFilter(100, 0.01)
        bf.add(1234)
        self.assertEquals(1234 in bf, True)

    def test_string_nofile(self):
        bf = pybloomfilter.BloomFilter(100, 0.01)
        bf.add("test")
        self.assertEquals("test" in bf, True)

    def test_others_nofile(self):
        bf = pybloomfilter.BloomFilter(100, 0.01)
        for elem in (1.2, 2343L, (1, 2), object(), u'\u2131\u3184'):
            bf.add(elem)
            self.assertEquals(elem in bf, True)

    #@unittest.skip("unfortunately large files cannot be tested on Travis")
    @with_test_file
    def _test_large_file(self, filename):
        bf = pybloomfilter.BloomFilter(400000000, 0.01, filename)
        bf.add(1234)
        self.assertEquals(1234 in bf, True)

def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(SimpleTestCase))
    return suite