コード例 #1
0
ファイル: test_cmph.py プロジェクト: pombredanne/cmph-cffi
def test_each_algo_defaults(tmpdir, algo):
    if algo == "brz":
        pytest.skip("brz is known to segfault on some machines")

    test_data = _words
    if algo == "bmz8":
        test_data = _words8

    with open(test_data) as test_input:
        mph = cmph.generate_hash(test_input, algorithm=algo)

    out = tmpdir.ensure("%s.mph" % algo)

    with out.open("w") as test_output:
        mph.save(test_output)

    with out.open() as saved_mph:
        mph2 = cmph.load_hash(saved_mph)

    with open(test_data) as test_input:
        for word in test_input:
            assert mph(word) == mph2(word)

    # Check that nothing untoward happens in __del__
    del mph
    del mph2
コード例 #2
0
def test_each_algo_defaults(tmpdir, algo):
    if algo == 'brz':
        pytest.skip("brz is known to segfault on some machines")

    test_data = _words
    if algo == 'bmz8':
        test_data = _words8

    with open(test_data) as test_input:
        mph = cmph.generate_hash(test_input, algorithm=algo)

    out = tmpdir.ensure('%s.mph' % algo)

    with out.open('w') as test_output:
        mph.save(test_output)

    with out.open() as saved_mph:
        mph2 = cmph.load_hash(saved_mph)

    with open(test_data) as test_input:
        for word in test_input:
            assert mph(word) == mph2(word)

    # Check that nothing untoward happens in __del__
    del mph
    del mph2
コード例 #3
0
ファイル: test_cmph.py プロジェクト: pombredanne/cmph-cffi
def test_filename_usage(tmpdir):
    mph = cmph.generate_hash(_words)
    out = tmpdir.ensure("out.mph")
    mph.save(out.strpath)

    mph2 = cmph.load_hash(out.strpath)

    with open(_words) as test_input:
        for word in test_input:
            assert mph(word) == mph2(word)
コード例 #4
0
def test_filename_usage(tmpdir):
    mph = cmph.generate_hash(_words)
    out = tmpdir.ensure('out.mph')
    mph.save(out.strpath)

    mph2 = cmph.load_hash(out.strpath)

    with open(_words) as test_input:
        for word in test_input:
            assert mph(word) == mph2(word)
コード例 #5
0
    def __init__(self, path, keys=None, log=DUMMY_LOG):
        self._path = path
        self.log = log
        self._data = None
        self._mph = None
        self._mph_path = os.path.join(path, "mph")

        if keys:
            self._data, self._mph = self._storedata(path, keys)
        else:
            self._data = VarArray(path)
            self._mph = cmph.load_hash(open(self._mph_path, "rb"))
コード例 #6
0
ファイル: test_cmph.py プロジェクト: pombredanne/cmph-cffi
def test_str_input2(tmpdir):
    data = open(_words).readlines()
    mph = cmph.generate_hash(data)
    out = tmpdir.ensure("out.mph")

    with out.open("w") as test_output:
        mph.save(test_output)

    with out.open() as saved_mph:
        mph2 = cmph.load_hash(saved_mph)

    for word in data:
        assert mph(word) == mph2(word)
コード例 #7
0
ファイル: test_cmph.py プロジェクト: pombredanne/cmph-cffi
def test_str_input(tmpdir):
    data = "This is a string list test".split()
    mph = cmph.generate_hash(data)
    out = tmpdir.ensure("out.mph")

    with out.open("w") as test_output:
        mph.save(test_output)

    with out.open() as saved_mph:
        mph2 = cmph.load_hash(saved_mph)

    for word in data:
        assert mph(word) == mph2(word)
コード例 #8
0
def test_str_input2(tmpdir):
    data = open(_words).readlines()
    mph = cmph.generate_hash(data)
    out = tmpdir.ensure('out.mph')

    with out.open('w') as test_output:
        mph.save(test_output)

    with out.open() as saved_mph:
        mph2 = cmph.load_hash(saved_mph)

    for word in data:
        assert mph(word) == mph2(word)
コード例 #9
0
def test_str_input(tmpdir):
    data = 'This is a string list test'.split()
    mph = cmph.generate_hash(data)
    out = tmpdir.ensure('out.mph')

    with out.open('w') as test_output:
        mph.save(test_output)

    with out.open() as saved_mph:
        mph2 = cmph.load_hash(saved_mph)

    for word in data:
        assert mph(word) == mph2(word)
コード例 #10
0
ファイル: test_cmph.py プロジェクト: pombredanne/cmph-cffi
def test_simple_usage(tmpdir):
    with open(_words) as test_input:
        mph = cmph.generate_hash(test_input)

    out = tmpdir.ensure("out.mph")

    with out.open("w") as test_output:
        mph.save(test_output)

    with out.open() as saved_mph:
        mph2 = cmph.load_hash(saved_mph)

    with open(_words) as test_input:
        for word in test_input:
            assert mph(word) == mph2(word)
コード例 #11
0
def test_simple_usage(tmpdir):
    with open(_words) as test_input:
        mph = cmph.generate_hash(test_input)

    out = tmpdir.ensure('out.mph')

    with out.open('w') as test_output:
        mph.save(test_output)

    with out.open() as saved_mph:
        mph2 = cmph.load_hash(saved_mph)

    with open(_words) as test_input:
        for word in test_input:
            assert mph(word) == mph2(word)