Example #1
0
def test_Tree_exists_zero(data):
    from pymvptree import Tree, Point

    p = Point(b'', data)
    t = Tree()

    assert not t.exists(p)
Example #2
0
def test_Tree_filter_all_points_in_threshold(data, target_data, threshold):
    from pymvptree import Tree, Point

    target = Point(b'', target_data)

    def hamming(p_a, p_b): 
        return sum(bin(a ^ b).count("1") for a, b in zip(p_a.data, p_b.data))

    t = Tree()

    all_points = {Point(d, d) for d in data}
    accepted_points = []
    for p in all_points:
        try:
            t.add(p)
        except:
            assume(False)
        else:
            accepted_points.append(p)

    matching_points = {p.point_id
                       for p in accepted_points
                       if hamming(p, target) <= threshold}

    current_points = {p.point_id for p in t.filter(target.data, threshold)}

    assert current_points == matching_points
Example #3
0
def test_Tree_get_zero():
    from pymvptree import Tree, Point

    t = Tree()

    with pytest.raises(ValueError):
        t.get(Point(b'', b''))
Example #4
0
def test_Tree_add_returns_False_on_non_added():
    from pymvptree import Tree, Point

    t = Tree()
    p = Point(b'', b'')
    t.add(p)
    assert t.add(p) is False
Example #5
0
def test_Tree_save_to_file_impossible():
    from pymvptree import Tree
    from tempfile import TemporaryDirectory

    t = Tree()
    with TemporaryDirectory() as filename:
        with pytest.raises(RuntimeError):
            t.to_file(filename)
Example #6
0
def test_Tree_exists_one_equal(p1_data):
    from pymvptree import Tree, Point

    t = Tree()
    p = Point(b'', p1_data)
    t.add(p)

    assert t.exists(Point(b'', p1_data))
Example #7
0
def test_Tree_add_returns_same_number(numpoints):
    from pymvptree import Tree, Point
    from hashlib import md5

    t = Tree()
    for i in range(numpoints):
        t.add(Point(('p%d' % i).encode('ascii'),
                    md5(bytes(i)).digest()))

    assert len(list(t.filter(bytes(16), 16*8))) == numpoints
Example #8
0
def test_Tree_exists_one_different(p1_data, p2_data):
    from pymvptree import Tree, Point

    assume(p1_data != p2_data)

    p = Point(b'p1', p1_data)
    t = Tree()
    t.add(p)

    assert not t.exists(Point(b'p2', p2_data))
Example #9
0
def test_Tree_get_from_memory(data):
    from pymvptree import Tree, Point

    p = Point(b'', data)
    t = Tree()
    t.add(p)

    found = t.get(p) 

    assert found == p
Example #10
0
def test_issue_5():
    d = {'\U0006e45900': b'\x00\x00\x00', '\U000be846\U000be846\U000683df': b'X\x9c?', '\U0008f52a\U0005b687\U0006e459': b'\x9c\x9cX', '\U000683df\U0007a4d8\U0007a4d8': b'X\x9c\x9c', '0\U0007a4d80': b'\x00\x00\x00', '\U0010b5e4\U0005c15a\U0005b687': b'?*?', '\U000683df\U0006e459\U0005b687': b'X*\x9c', '\U0005b687\U0010b5e4\U0008f52a': b'X*?', '\U0007e0f2\U0005b687\U000be846': b'?\xa7*', '\U0010b5e4\U000be846\U000c991f': b'\x9c*?', '\U000683df\U000c991f\U0007a4d8': b'?X*', '\U0006e459\U000e6112\U000c991f': b'X*?', '\U0006e459\U0007a4d8\U0007e0f2': b'?*\xa7', '\U0003b2b8\U000be846\U0006e459': b'X\x9cX', '\U000d9404\U0005b687\U0007a4d8': b'\x9c?\xa7', '\U0005c15a\U0005c15a\U000c991f': b'?\x9cX', '\U0003b2b8\U0003b2b8\U000d9404': b'X**', '`ÀÀ': b'X?*', '\U000d9404\U000c991f\U000683df': b'\x9c?*', '\U0008f52a\U0007a4d8\U000e6112': b'?X\x9c', '\U0007e0f2\U000c991f\U0005b687': b'\x9c?X', '\U000d9404\U0005c15a\U0005b687': b'X*?', '\U0007e0f2\U0005c15a\U0005c15a': b'\x9c?X', '\U0005b687\U000683df\U0005c15a': b'??X', '00\U0003b2b8': b'\x00\x00\x9c', '\U000c991f\U000d9404\U0005c15a': b'X*?', '\U0005b687\U0005c15a\U0010b5e4': b'X\xa7\xa7', '\U0008f52a\U000e6112\U0003b2b8': b'X\xa7\x9c', '\U000c991f\U0006e459\U000d9404': b'??\xa7', '0\U000d9404`': b'?X\x9c', '\U0007e0f2\U0007e0f2\U0007a4d8': b'\xa7*\x9c', '\U000d9404\U000d9404\U000c991f': b'?\xa7?', '\U0010b5e4\U0010b5e4\U000c991f': b'X*X', '0\U000c991f`': b'XX?', '\U0008f52a\U0007e0f2\U000c991f': b'?\x9c?', '\U000be846\U0005b687\U000e6112': b'\xa7*?', '\U0005c15a\U0008f52a\U0006e459': b'?*?', '\U0010b5e4\U0008f52a\U000d9404': b'?\x9c*', '\U000683df\U0005b687\U000c991f': b'??X', '\U0006e459\U0006e459\U0003b2b8': b'?*?', '\U0007e0f2\U0008f52a\U000c991f': b'\x9c\x9c*', '\U000c991f\U0005b6870': b'?*\x9c', '\U000683df\U0010b5e4\U0007e0f2': b'\x9c??', '\U000c991f\U0008f52a\U0010b5e4': b'???', '\U0006e459\U000e6112\U000be846': b'\x9c*\x9c', '\U0008f52a\U0005b687\U000be846': b'X\xa7*', '\U0007e0f2\U0007e0f2\U0008f52a': b'XX\x9c', '\U0005b687\U0003b2b8\U0008f52a': b'XX\xa7', '\U000683df\U0007a4d8\U0003b2b8': b'X\x9c?', '\U0005c15a\U0005c15a\U0005c15a': b'\x9c?X', '\U000683df\U000c991f\U0005b687': b'\x9c?\xa7', '\U000683df\U0006e459\U0005c15a': b'X*\x9c', '\U0007a4d8\U000e6112\U0007e0f2': b'X\xa7\x9c', '\U000d9404\U000c991f\U0007e0f2': b'X??', '\U0003b2b8\U0005b687\U0007a4d8': b'\xa7?*', '00\U000e6112': b'\x9c\xa7\x9c', '\U000be846\U0008f52a\U0003b2b8': b'\x9c\xa7*', '\U000c991f\U0006e459\U0007e0f2': b'?*?', '\U0007a4d8\U000d9404\U000d9404': b'\x9c\x9c*', 'bar': b'bar', '\U000be846\U0005b687\U0007e0f2': b'?*?', '\U0005c15a\U000683df\U0005b687': b'?X*', '\U000c991f\U0007a4d8\U0003b2b8': b'X\xa7\xa7', '̀00': b'?*\x9c', '\U000683df\U000e6112\U0006e459': b'\xa7**', '\U000c991f\U0007a4d8\U000683df': b'?\xa7X', '\U0006e459\U000e6112\U0007e0f2': b'??X', '\U0007e0f2\U000c991f\U000be846': b'X?\x9c', '\U0008f52a\U000683df\U0006e459': b'?*?', '\U000c991f\U0010b5e4\U000c991f': b'?XX', '\U0005c15a\U0006e459\U0006e459': b'\x9c?\xa7', '\U0006e459\U000be846\U0003b2b8': b'??X', '\U000e6112\U0005b687\U0007a4d8': b'?*\xa7', '\U0010b5e4\U0010b5e4\U0008f52a': b'??X', '\U000683df\U0005c15a\U000d9404': b'\x9c\x9c\xa7', 'baz': b'bar', '\U000d9404\U0005b687\U000683df': b'X?*', '\U0010b5e4\U000d9404\U0005b687': b'XX*', '\U0006e459\U0003b2b8\U000683df': b'\x9c*\xa7', '\U0006e459\U000c991f\U000be846': b'X*\xa7', '\U000e6112\U000c991f\U000d9404': b'?\x9cX', '00À': b'X**', '00\U0007a4d8': b'\x00\x9c\x00', '\U000e6112\U000683df\U0010b5e4': b'XX\xa7', '``0': b'X*X', '\U000e6112\U0005b687\U000c991f': b'\x9c*X', '\U000c991f\U000c991f\U0006e459': b'X?X', '\U0008f52a\U000be846\U0010b5e4': b'\x9c?\x9c', '\U000683df\U0005c15a\U000683df': b'X\x9c*', '\U000c991f\U0003b2b8\U0005c15a': b'???', '\U0005c15a\U000d9404\U000683df': b'\x9c*\x9c', '0\U000e61120': b'\x00\x00\x00', '\U000be846\U000e6112\U0005b687': b'?\xa7*', '\U0005b687\U0005b687\U000683df': b'?X\xa7', '\U0006e459\U0008f52a\U000c991f': b'XXX', '\U0008f52a\U0005b687\U0007e0f2': b'\x9c\x9c\x9c', '\U0007a4d8\U0008f52a\U000be846': b'\xa7*\x9c', '\U0007e0f2\U0006e459\U000c991f': b'\x9c\x9c?', '\U000e6112\U000d9404\U0007e0f2': b'\x9c*?', '\U0006e459\U000e6112\U0005b687': b'X\x9c?', '\U0006e459\U0005b687\U000683df': b'\x9c*\xa7', '\U000be846\U000d9404\U000c991f': b'\x9c\xa7*', '0쀀0': b'*\x00*', '\U000c991f\U0007e0f2\U000683df': b'X\x9c\xa7', '\U0006e459\U000e6112\U0007a4d8': b'\x9c**', '\U0007e0f2\U0007e0f2\U000e6112': b'?\x9c*', '\U0005c15a\U0007a4d8\U0006e459': b'?XX', '\U000e6112\U0008f52a\U000c991f': b'X\xa7\xa7', '\U0007a4d8\U0008f52a\U000e6112': b'\x9c?\x9c', '\U0008f52a\U0007e0f2\U000be846': b'???', '\U0010b5e4\U000e6112\U0007a4d8': b'\x9c\xa7\xa7', '\U000e6112\U0007a4d8\U000be846': b'\x9c\xa7?', '\U0007a4d8\U0005b687\U0007e0f2': b'X\xa7X', '\U0005c15a\U0003b2b8\U0007a4d8': b'?\x9c?', '\U0005c15a\U000d9404\U000e6112': b'?X\xa7', '\U0005c15a\U0005b687\U000683df': b'?X?', '\U000683df\U0003b2b8\U0005c15a': b'?*X', '\U0010b5e4\U000d9404\U000be846': b'\x9cX\xa7', '\U000c991f`0': b'\xa7*\x9c', '0\U000c991f\U000c991f': b'?\xa7?', '\U0006e459\U0007e0f2\U0010b5e4': b'\x9c\x9c\xa7', '\U000d9404\U0003b2b8\U0008f52a': b'\xa7?X', '\U000e6112\U0008f52a\U0005c15a': b'X\xa7?', '\U000683df00': b'X\xa7?', '\U0007a4d8\U0003b2b8\U000e6112': b'X\x9c*', '\U000683df\U0010b5e4\U0010b5e4': b'?XX', '`ƀ0': b'\x00*\x9c', '`00': b'X\xa7\xa7', '\U000e6112\U000e6112\U000d9404': b'??\x9c', '\U0005c15a\U0005c15a\U0006e459': b'\x9c*\x9c', '\U0010b5e4\U000d9404\U0006e459': b'??X', '\U0010b5e4\U000d9404\U000c991f': b'??\x9c', '\U000683df\U0007a4d8\U0005b687': b'X\x9cX', '\U0003b2b8\U000d9404\U0007a4d8': b'\x9c\xa7\xa7', '\U0005c15a\U0010b5e4\U000c991f': b'??X', '\U0003b2b8\U0006e459\U000c991f': b'\x9c\xa7X', '00᠀': b'???', '\U0007a4d8\U0005b687\U000d9404': b'?\xa7\xa7', '\U000c991f\U000c991f\U0007a4d8': b'X\x9c?', '\U0007a4d8\U000be846\U000c991f': b'X\xa7\xa7', '\U0007e0f2\U0005c15a\U000e6112': b'\x9c?\xa7', '\U0005b687\U000e6112\U000e6112': b'XXX', '\U0005c15a\U0003b2b8\U000d9404': b'??\x9c', '000': b'\x00\x00\x00', '0ƀ0': b'\x00\x00\x00', '\U0010b5e4\U000d9404\U0005c15a': b'?\xa7X', 'ƀ00': b'\x00\x00\x00', '\U0006e459\U0005b687\U000d9404': b'X\x9c\xa7', '\U000be846\U0007a4d8\U000d9404': b'\x9c\xa7*', '00\U0005b687': b'\x00\x00\x00', '\U000d9404\U0008f52a\U000e6112': b'\x9c??', '\u300000': b'?XX', '\U0003b2b8\U000683df\U000be846': b'\x9c??', '\U0007e0f2\U000be846\U0007a4d8': b'??\x9c', '\U0003b2b80\U0006e459': b'\x9c*X', '\U0007a4d8\U0007e0f2\U000be846': b'X*?', '\U000c991f\U0008f52a\U0005c15a': b'\x9c?\xa7', '\U0007e0f2\U0005b687\U0007e0f2': b'\x9c\xa7*', '0\U0007a4d8`': b'\xa7*\xa7', '\U000c991f\U000e6112\U0007a4d8': b'\x9c\xa7X', '\U0005b687\U0007e0f2\U000e6112': b'X\xa7\xa7', '0\U000be8460': b'*\x00\x00', '\U000e6112\U0010b5e4\U000d9404': b'??*', '\U000e6112\U0008f52a\U000683df': b'?\xa7X', '0\U0003b2b8\U000e6112': b'XX\xa7', 'À\U000d94040': b'?\x9c\x9c', '\U000c991f\U000683df\U000e6112': b'??\xa7', '\U0008f52a\U0007a4d8\U0003b2b8': b'X**', '00\U000be846': b'\x00\x00\x9c', '\U0006e459\U000d9404\U0007e0f2': b'??*', '0ƀƀ': b'XX\xa7', '\U0010b5e4\U000d9404\U0003b2b8': b'?\x9c\xa7', '\U0008f52a\U0010b5e4\U000be846': b'??X', '\U0008f52a\U000be846\U0005b687': b'X\xa7X', '\U0003b2b8\U000c991f\U0005c15a': b'?*?', '\U0006e459\U0005b687\U0008f52a': b'?\xa7*', '\U0006e459\U0003b2b8\U0007a4d8': b'XX\x9c', '\U0005b687\U0007e0f2\U0005b687': b'X\x9c\xa7', '\U0005c15a\U0010b5e4\U0007a4d8': b'XX\x9c', '\U000d9404\U000c991f\U0005b687': b'XX?', '\U0005c15a\U0007a4d8\U000d9404': b'X\x9c?', '\U0006e459\U0008f52a0': b'\x9c\x9c?', '\U0007e0f2\U0003b2b8\U0005c15a': b'??\x9c', '\U000e6112\U000be846\U000e6112': b'?\xa7?', '\U0006e459\U000c991f\U000c991f': b'\x9c**', '\U0006e459\U000d9404\U0005b687': b'X?*', '\U0007a4d8\U0006e459\U0008f52a': b'?X?', '\U0005b687\U0008f52a\U000c991f': b'X*?', '\U000e6112\U0005b687\U0006e459': b'\x9c*X', '\U0006e459\U000be846\U0010b5e4': b'???', '0\U0005c15a\U0005c15a': b'\x9c**', '\U000e6112\U0006e459\U000c991f': b'?\x9cX', '\U0008f52a\U0010b5e4\U0005b687': b'X\x9cX', '\U000be846\U000e6112\U000d9404': b'?XX', '\U0007e0f2\U000683df\U000683df': b'\x9c\xa7\x9c', '\U0006e459\U0005c15a\U0010b5e4': b'X?\x9c', '\U000e6112\U0007e0f2\U0007a4d8': b'\x9cX?', '0Àƀ': b'?\x9c\xa7', '\U0006e459\U0005b687\U000e6112': b'???', '\U0008f52a\U000683df\U0005b687': b'\x9c\xa7\x9c', '\U0008f52a\U0003b2b8\U000c991f': b'\x9c?*', '\U0006e459\U000c991f\U0007e0f2': b'\x9cX?', '\U000d9404\U0003b2b8\U0003b2b8': b'\xa7*\xa7', '\U0005c15a\U0005b687\U0006e459': b'X*\x9c', '\U000d9404\U000be846\U0005c15a': b'?*\xa7', '\U000d9404\U0007a4d8\U000683df': b'\x9cX?', '\U0005c15a\U000c991f\U000e6112': b'?\x9c\xa7', '\U000e6112\U000e6112\U0003b2b8': b'\x9c?\x9c', '\U0005b687\U0005b687\U0005c15a': b'X?\x9c', '\U0007e0f2\U000c991f\U0007e0f2': b'X\x9cX', '0``': b'??*', '\U000683df\U000d9404\U0007e0f2': b'\xa7*\x9c', '\U000be846\U000d9404\U000e6112': b'?X*', '\U000c991f\U0007a4d8\U0008f52a': b'\x9c\xa7\xa7', '\U000d9404\U000e6112\U0008f52a': b'?*?', '\U0007e0f2\U0007a4d8\U0007a4d8': b'XXX', '\U0008f52a\U000be846\U0005c15a': b'X?*', '\U0008f52a\U0006e459\U0010b5e4': b'?\x9c*', '\U000683df\U0003b2b8\U0003b2b8': b'?X\xa7', '\U0003b2b8\U000e6112\U0005b687': b'?\x9cX', '\U0007a4d8\U000e6112\U000d9404': b'X\x9c*', '0À0': b'\x00\x00\x00', '\U000c991f\U000c991f\U000d9404': b'X\xa7\x9c', '\U0005c15a\U0008f52a\U000be846': b'\x9c*\x9c', 'foo': b'bar', '\U0008f52a\U0007a4d8\U000d9404': b'X??', '\U0007e0f2\U000683df\U000c991f': b'?XX', '\U0007e0f2\U0008f52a\U0007e0f2': b'X\x9cX', '\U0008f52a\U0007a4d8\U0006e459': b'X\x9c\x9c', '\U0005b687\U0006e459\U000c991f': b'?\x9c*', '\U000e6112\U0007e0f2\U0006e459': b'\x9c?\x9c', '\U0007e0f2\U000c991f\U0010b5e4': b'X\x9c\xa7', '\U0003b2b8\U0008f52a\U0005b687': b'??\xa7', '0\U000c991f0': b'\x00\x00\x00', '\U000c991f\U000e6112\U000c991f': b'XXX', '\U0007e0f2\U0005c15a\U0007e0f2': b'XX?', '\U000c991f\U000683df\U000c991f': b'?*?', '\U0005b687\U0010b5e4\U0007a4d8': b'?\x9c*', '\U0007a4d8\U0005c15a\U0007a4d8': b'X?\x9c', '\U0007a4d8\U000e6112\U000be846': b'X?\x9c', '\U000c991f\U0010b5e4\U0007e0f2': b'X\xa7X', '\U0007a4d8\U0010b5e4\U000be846': b'\x9cXX', '\U0006e459\U0007e0f2\U000c991f': b'X*?', '\U0005c15a\U000c991f\U000683df': b'?X*', '0\U000e6112`': b'\x9c\xa7*', '\U000683df\U000be846\U000e6112': b'\x9cX*', '\U0003b2b8\U000683df\U000e6112': b'\x9c*\x9c', '\U0007a4d8\U000683df\U000be846': b'\x9c**', '\U000d9404\U000be846\U000d9404': b'?\x9c\x9c', '\U0007e0f2\U000683df\U000d9404': b'\x9cX\x9c', '\U000d9404\U000e6112\U000d9404': b'\xa7*\x9c', '\U000be846\U000d9404\U0005c15a': b'X*\x9c', '`\U000c991f0': b'\xa7\x00\x00', '0\U0005c15a0': b'??\x9c', '\U0003b2b8\U0007e0f2\U000be846': b'X\x9c\x9c', '\U000e6112\U0007e0f2\U0008f52a': b'X?\x9c', '0̀0': b'\x00\x00\x00', '\U000be846\U0005c15a\U000be846': b'\x9c?*', '\U0003b2b8\U000c991f\U000e6112': b'\x9cXX', '0`\U0007a4d8': b'\xa7*?', '\U000e6112\U000d9404\U0005c15a': b'X??', '\U000e6112\U000d9404\U000d9404': b'\x9c*?', '\U0005b687\U0007e0f2\U0006e459': b'X\xa7*', '\U000683df\U0008f52a\U0007a4d8': b'?\x9c?', '\U000683df\U000d9404\U0007a4d8': b'X*?', '\U000be846\U000683df\U0008f52a': b'?*\xa7', '\U000e6112\U000d9404\U000be846': b'?*?', '\U000683df\U000d9404\U0010b5e4': b'?*?', '\U0008f52a\U0008f52a\U0005c15a': b'??\xa7', '\U0006e459\U0005c15a\U0003b2b8': b'X\x9c\xa7', '\U000683df\U0006e459\U0008f52a': b'XX?', '\U0010b5e4\U0005b687\U000c991f': b'?\xa7X', '\U000d9404\U0007e0f2\U0003b2b8': b'X\x9c*', '0ƀ`': b'\x9c**', '\U0007e0f2\U000e6112\U0010b5e4': b'?\x9c?', '\U000be846\U0007e0f2\U0005b687': b'\x9cX?', '\U000c991f\U0008f52a\U0005b687': b'X\xa7\x9c', '\U0005b687\U0007e0f2\U000be846': b'?*?', '\U000c991f\U000c991f\U000be846': b'XX\xa7', '\U0006e459\U000e6112\U000683df': b'X\x9cX', '\U0006e459\U000c991f\U0005c15a': b'XX*', '\U0003b2b8\U0008f52a\U0006e459': b'?\x9c*', '\U0005c15a\U000c991f\U0010b5e4': b'X\xa7\x9c', '\U0003b2b8\U000c991f\U000c991f': b'\x9c*\xa7', '\U0003b2b8\U0003b2b8\U000be846': b'X*?', 'À0\U000e6112': b'??X', '\U000be846\U0003b2b8\U0005c15a': b'?\x9cX', '\U000683df\U0008f52a0': b'?\xa7X', '00\U000c991f': b'X\x00\x00', '\U0005c15a\U000d9404\U000be846': b'X\xa7\x9c', '\U000683df\U000e6112\U000e6112': b'XX\xa7', '\U0007a4d8\U0005c15a\U0003b2b8': b'\x9c?*', '\U0005c15a00': b'X\x9cX', '\U0005c15a\U000d9404\U000d9404': b'XX*', '\U0008f52a\U0008f52a\U000683df': b'\x9c\xa7X', '\U000be846\U0006e459\U0005b687': b'?X\xa7', '\U000c991f\U0005b687\U0007e0f2': b'?X\xa7', 'ఀ00': b'?X?', '\U000d9404\U000e6112\U0010b5e4': b'?\x9c*', '\U0008f52a\U000683df\U0007e0f2': b'\x9c\x9cX', '\U0003b2b8\U0005c15a\U000d9404': b'\x9c\xa7\x9c', '\U000d9404\U0003b2b8\U0005b687': b'??\x9c', '\U000be846\U0007a4d8\U0005b687': b'?\xa7\xa7', '\U0003b2b8\U0008f52a\U000e6112': b'X?\x9c', '\U0006e459\U0005c15a\U000be846': b'\xa7?*', '\U0003b2b8\U0007a4d8\U0007a4d8': b'XX\xa7', '\U000c991f\U0006e459\U0005c15a': b'?\xa7X', '\U000d9404\U0005c15a\U000e6112': b'X*\x9c', '\U0007a4d8\U000be846\U0007e0f2': b'\x9c\xa7\x9c', '\U000be846\U0007a4d8\U000e6112': b'X*\x9c', '\U0010b5e4\U0008f52a\U0007a4d8': b'?\xa7\x9c', '0`\U0008f52a': b'?\xa7*', '\U0006e459\U0006e459\U0007a4d8': b'??\x9c', '\U0006e459\U000e6112\U000e6112': b'X??', '\U0005c15a\U0008f52a\U0005c15a': b'?\x9c\x9c', '\U000be846\U0007a4d8\U0010b5e4': b'?\x9c?', '\U0007e0f2\U0010b5e4\U000683df': b'X\xa7X', '\U0007e0f2\U000e6112\U0006e459': b'?\x9cX', '\U0005b68700': b'\x9c?X', '\U000e6112\U0006e459\U0005c15a': b'X\x9c\x9c', 'À0`': b'\xa7?X', '\U0008f52a00': b'\x00*\x00', '\U0010b5e4\U0005b687\U0005c15a': b'?\xa7\x9c', '0\U0007a4d8\u0600': b'\xa7*?', '\U0008f52a\U000e6112\U000683df': b'\xa7*?', '\U000c991f\U0005c15a\U0007e0f2': b'?*?', '\U0008f52a\U0010b5e4\U0003b2b8': b'X*?', '`\U000683df0': b'\x9c*\xa7', '\U0010b5e4\U0005c15a\U000c991f': b'\x9c*X', '\U0008f52a\U000d9404\U0008f52a': b'XX\x9c', '0`\U0005b687': b'??\xa7', '0怀0': b'?*?', '0̀\U000be846': b'\x9cX?', '\U0006e459\U0010b5e4\U0007a4d8': b'\x9cX*', '\U0010b5e4\U0006e459\U000d9404': b'X\x9c*', '\U000c991f\U0007a4d8\U000be846': b'\x9c\xa7*', '0`0': b'\x00\x00\x00', '\U000683df\U0007e0f2\U0008f52a': b'?X\xa7', '\U0005b687\U0006e459\U0003b2b8': b'?\x9c?', '\U000e6112\U0003b2b8\U000d9404': b'??\x9c', '\U0006e459\U0005b687\U0010b5e4': b'?X\xa7', '0\U0008f52a0': b'\x00\x00\xa7', '0\U000d9404À': b'X**', '\U0007a4d800': b'\xa7\x00\x00', '0\U000e6112\U0007e0f2': b'?\xa7X', '\U000e6112\U000c991f\U0008f52a': b'X\xa7?', '\U000d9404\U000be846\U000c991f': b'X\xa7\x9c', '\U0010b5e4\U0007a4d8\U000d9404': b'?X\xa7', '\U000c991f\U000683df\U0005c15a': b'X*\x9c', '\U0003b2b8\U000d9404\U000be846': b'X*?', '00\U0010b5e4': b'?\xa7?', '0\U000683df\U0010b5e4': b'?X\x9c', '\U000e6112\U000be846\U0005b687': b'X\x9cX', '\U0007a4d8\U000be846\U0010b5e4': b'X?\x9c', '\U0003b2b8\U000be846\U0005b687': b'?\xa7\x9c', '\U000683df\U000c991f\U0005c15a': b'?\xa7\xa7', '\U0003b2b8\U000c991f\U000683df': b'?\x9c\x9c', '\U0008f52a\U0005b687\U000683df': b'???', '00\U0006e459': b'\xa7*\x9c', '\U000c991f00': b'\x00\x00\x00', '0\U000be846\U0005c15a': b'X\xa7\x9c', '\U000c991f\U000683df\U000d9404': b'\x9c*?', '\U000683df\U0008f52a\U0010b5e4': b'X\x9cX', '\U0005c15a\U0007a4d8\U000c991f': b'\x9c\x9c\xa7', '\U0010b5e4\U0010b5e4\U000683df': b'\x9c\xa7*', '`À0': b'\x00\x00\x00', '\U0003b2b8\U000d9404\U0007e0f2': b'??\xa7', '\U000d9404\U000c991f\U0008f52a': b'\x9c\xa7\x9c', '\U0010b5e4\U0006e459\U000c991f': b'\x9c\xa7*', '\U0006e459\U0007a4d8\U000c991f': b'\x9c?\x9c', '\U000683df\U000d9404\U000be846': b'\x9c\x9cX', '\U0007a4d8\U0003b2b8\U0010b5e4': b'?X*', '\U0010b5e4\U000be846\U0006e459': b'\x9cX\x9c', '\U0005b687\U000be846\U000d9404': b'\x9c\x9c*', '\U000e6112\U000d9404\U0010b5e4': b'X?\xa7', '\U0008f52a\U0007e0f2\U000683df': b'??\x9c', '\U0007e0f2\U0007e0f2\U000be846': b'\x9c*\xa7', '``\U0003b2b8': b'X\xa7X', '\U000683df\U0010b5e4\U0005c15a': b'?\xa7\xa7', '\U000be846\U0006e459\U0007e0f2': b'\xa7?*', '\U0006e459\U0007e0f2\U000e6112': b'\x9c\xa7*', '\U0007e0f2\U0003b2b8\U000be846': b'\x9c**', 'Àƀ0': b'?\x00\x00', '\U0003b2b8\U0003b2b8\U000c991f': b'X?\x9c', '\U0006e459\U0010b5e4\U0007e0f2': b'\x9cX\xa7', '\U0007e0f2\U000e6112\U000e6112': b'?*\x9c', '\U0006e459\U000be846\U0005c15a': b'?\xa7?', '\U000e6112\U000be846\U000be846': b'?\xa7\xa7', '\U0003b2b8\U0007a4d8\U0005c15a': b'?X*', '\U000be846\U0006e459\U000683df': b'\x9c\xa7?', '\U0007a4d8\U000683df\U000e6112': b'X?\xa7', '\U000683df\U000683df\U000d9404': b'X*\x9c', '0\U000c991f\U000683df': b'\x00\x00\x00', '\U0005c15a\U0007e0f2\U000683df': b'\x9c?\x9c', '00ƀ': b'\x00\x00\x00', '\U000d9404\U000d9404\U0007a4d8': b'X*X', '00\U0005c15a': b'?\xa7?', '\U0007a4d8\U000c991f\U0006e459': b'X?\x9c', '\U0003b2b8\U0003b2b8\U0007e0f2': b'X??', '\U000e611200': b'X**', '\U0003b2b8\U0008f52a\U000be846': b'X??', '\U0005c15a\U0005c15a0': b'X\xa7?', '\U0007a4d8\U000c991f\U000683df': b'?X\xa7', '\U0010b5e4\U0008f52a\U0006e459': b'X?X', '\U0010b5e4\U000c991f\U0010b5e4': b'?\x9cX', '0`À': b'?\xa7\x9c', '\U000d9404\U0006e459\U000c991f': b'\x9c*\x9c', '\U000683df\U000d9404\U0005c15a': b'X\xa7?', '\U0005b687\U0005b687\U0010b5e4': b'\x9c\xa7X', '\U000e6112\U0003b2b8\U0006e459': b'\x9c\x9c\xa7', '\U0005c15a\U000be846\U0005b687': b'\x9c\x9c\xa7', '\U000d9404\U000e6112\U0007e0f2': b'\x9c?\xa7', '\U0010b5e4\U0003b2b8\U0008f52a': b'XX\xa7', '\U000683df\U0005b687\U0007a4d8': b'XXX', '\U000e6112\U0005c15a\U0005c15a': b'X\xa7X', '\U0003b2b8\U0007a4d8\U000d9404': b'?\x9c?', '\U0003b2b8\U0010b5e4\U0007e0f2': b'X*?', '\U0007e0f2\U000683df\U0007e0f2': b'X*X', '\U0007e0f2\U000be846\U0008f52a': b'X?\x9c', '\U000d9404\U000683df\U000e6112': b'\xa7*\xa7', '\U0008f52a\U0010b5e4\U000683df': b'\x9c\xa7X', '\U0007e0f2\U000683df\U0005c15a': b'\x9c?*', '\U0010b5e4\U0005b687\U000683df': b'?\x9c\x9c', '\U0010b5e4\U0003b2b8\U0006e459': b'\x9c\x9c?', '\U0007e0f2\U0003b2b8\U000d9404': b'?\x9c?', '\U0005c15a\U0003b2b8\U0005c15a': b'\x9c\x9c\x9c', '\U000d9404\U0010b5e4\U0005c15a': b'\x9c*\xa7', '\U0010b5e4\U0003b2b8\U0010b5e4': b'?\x9c\xa7', '\U0005c15a\U0005c15a\U0003b2b8': b'?X?', '0\U0007e0f2\U0007e0f2': b'?X\x9c', '0À\U000683df': b'X*\xa7', '\U0005c15a\U0005c15a\U0007e0f2': b'X\x9c\x9c', '\U000d9404\U0006e459\U0010b5e4': b'?*\x9c', '00\U0008f52a': b'\x00\x00\x00', '\U0003b2b8\U0008f52a\U0003b2b8': b'\x9c*?', '00̀': b'\x00\x00*', '\U000d9404\U0008f52a\U0010b5e4': b'\x9c\xa7*', '`0\U0005b687': b'?\xa7X', '\U0005b687\U000e6112\U0007a4d8': b'\x9c?X', 'bao': b'bar', '00`': b'\x00\x00\xa7', '\U000be84600': b'X\xa7*', '\U000d9404\U0005c15a\U0007a4d8': b'??\x9c', '\U0008f52a\U0003b2b8\U0003b2b8': b'\xa7?X', '\U0007e0f2\U0003b2b8\U0003b2b8': b'\x9c**', '\U0005c15a0`': b'\x9c??', '\U000be846\U0006e459\U0010b5e4': b'??*', '\U0007e0f2\U0008f52a\U0005c15a': b'\x9cXX', '\U0005b687\U000683df\U0007a4d8': b'?X\x9c', '0\U000d94040': b'\x00?*', '00\U000683df': b'\x00\x00\xa7', '\U0007a4d8\U000683df\U0008f52a': b'X\xa7\x9c', '\U0006e459\U000683df\U0008f52a': b'???', '\U0007a4d8\U0010b5e4\U0007e0f2': b'??\xa7', '00\U0007e0f2': b'?\x9cX', '\U000683df\U0008f52a\U0008f52a': b'\x9c?*', '\U000c991f\U0005c15a\U0008f52a': b'?\xa7?', '\U000c991f\U0008f52a\U0003b2b8': b'?\xa7*', '\U0010b5e4\U0005c15a\U000be846': b'\xa7*X', '\U000d9404\U0003b2b8\U0010b5e4': b'\x9cX\x9c', '\U000d9404\U0005c15a\U0008f52a': b'?X\x9c', '\U0005b687\U000683df\U000be846': b'?\xa7*', '\U000e6112\U0006e459\U000be846': b'X*\x9c', '\U0003b2b8\U0005c15a\U000e6112': b'XX?', '\U0007a4d8\U0005c15a\U000be846': b'?X*', '\U0005c15a\U0007e0f2\U0005b687': b'\x9c\xa7?', '\U000e6112\U0008f52a\U000be846': b'X?X', '\U0003b2b8\U0007e0f2\U0005b687': b'XX\xa7', '\U0003b2b8\U0006e459\U0005b687': b'\xa7*X', '\U000be846\U0007e0f2\U0006e459': b'\x9cX*', '\U000d9404\U000683df\U0007e0f2': b'\x9cX*', '\U0010b5e400': b'\x00?X', '\U0007e0f2\U0008f52a\U000e6112': b'??*', '\U000d9404\U000683df\U0008f52a': b'?\x9c*', '\U000683df\U000be846\U0005b687': b'X\xa7\x9c', '\U000be846\U000c991f\U0007a4d8': b'\x9c*\x9c', '0\U000683df0': b'\x00*\xa7', '\U0006e459\U000e6112\U0005c15a': b'?*?', '\U0007e0f2\U0007e0f2\U0010b5e4': b'\x9c*\x9c', '\U0007e0f2\U000683df\U0007a4d8': b'\xa7*\x9c', '0\U0010b5e40': b'\x9c\x00\x00', '\U000c991f\U000be846\U0008f52a': b'???', 'À00': b'\x00\x00\x00', '\U000683df\U000be846\U0008f52a': b'?\xa7?', '\U0003b2b8\U0007e0f2\U000c991f': b'X\xa7\x9c', '\U000be846\U0005c15a\U0008f52a': b'\x9c*?', '\U0006e459\U000c991f\U000e6112': b'\xa7**', '\U0003b2b8\U0007e0f2\U0007a4d8': b'?\x9c*', '\U000e6112\U000d9404\U0006e459': b'\x9c?\x9c', '\U0005c15a\U000e6112\U000e6112': b'X\x9cX', '0À`': b'?*\x9c', '\U0006e459\U000d9404\U000c991f': b'?*\xa7', '\U0005c15a\U0010b5e4\U0010b5e4': b'?\xa7?', '\U000e6112\U000d9404\U0007a4d8': b'\x9c\xa7\xa7', '\U000be846\U000c991f\U0008f52a': b'\x9c*X', '\U0005b687\U0007e0f2\U0007e0f2': b'???', '\U0006e459\U000d9404\U0010b5e4': b'?\x9c*', '\U0007e0f2\U000c991f\U000e6112': b'?\x9c?', '\U0005b687\U000e6112\U0007e0f2': b'\x9cX?', '0\U0007e0f20': b'\x9c**', '\U000d9404\U0006e459\U000be846': b'X\xa7X', '\U000be846\U000be846\U0005c15a': b'\xa7*?', '\U0008f52a\U0005c15a\U000c991f': b'X\x9c?', '\U000683df\U0005b687\U000be846': b'\x9cX?'}

    tree = Tree(leafcap=32)
    for k, v in d.items():
        tree.add(Point(k, v))

    added_points = len(d)
    tree_points = len(list(tree.filter(b'   ', 24)))

    assert added_points == tree_points
Example #11
0
def test_Tree_filter_all_points(data):
    from pymvptree import Tree, Point

    def hamming(p_a, p_b): 
        return sum(bin(a ^ b).count("1") for a, b in zip(p_a.data, p_b.data))

    t = Tree()

    all_points = {Point(b'', d) for d in data}
    for p in all_points:
        t.add(p)

    current_points = {p for p in t.filter(bytes(4), 4*8)}

    assert current_points == all_points
Example #12
0
def test_Tree_save_and_load_match(data, leafcap):
    data = list(set(data))

    from pymvptree import Tree, Point
    from tempfile import mktemp

    t1 = Tree(leafcap=leafcap)

    saved_points = {Point(d, d) for d in data}
    for p in saved_points:
        try:
            t1.add(p)
        except:
            pass

    tempfile = mktemp()
    try:
        t1.to_file(tempfile)
        t2 = Tree.from_file(tempfile)
    finally:
        os.unlink(tempfile)

    # XXX: Review why len(data) + 2 is necessary here
    added_points = {p.point_id for p in t1.filter(bytes(4),
                                                  4 * 8,
                                                  limit=len(data) + 2)}
    loaded_points = {p.point_id for p in t2.filter(bytes(4),
                                                   4 * 8,
                                                   limit=len(data) + 2)}

    assert added_points == loaded_points
Example #13
0
def test_Tree_add_and_exists_until_full(leafcap, data):
    from pymvptree import Tree, Point

    t = Tree(leafcap=leafcap)

    added_data = set()

    for d in data:
        try:
            point = Point(d, d)
            t.add(point)
        except:
            break
        else:
            assert t.exists(Point(d, d))
            added_data.add(point)

    assert added_data
    assert added_data == set(t.filter(b'0', 8))
Example #14
0
def test_Tree_try_to_add_and_filter(leafcap, max_value):
    from pymvptree import Tree, Point

    t = Tree(leafcap=leafcap)

    added_data = []

    maxlength = len(str(max_value))
    data_formatter = "%%0%d.d" % maxlength

    for i in range(max_value):
        try:
            t.add(Point(i, (data_formatter % i).encode("ascii")))
        except:
            pass
        else:
            added_data.append(i)
        finally:
            # YES, we do this in each iteration. The behaviour in issue
            # #1 is changing in each data addition.
            for d in added_data:
                assert list(t.filter((data_formatter % d).encode("ascii"), 0))
Example #15
0
def test_Tree_add_until_full_then_search():
    from pymvptree import Tree, Point

    t = Tree(leafcap=3)

    for i in range(5):
        t.add(Point(i, b'TEST'))

    pre_full = {p.point_id for p in t.filter(b'TEST', 0)}

    # LEAF is full
    with pytest.raises(RuntimeError):
        t.add(Point(-1, b'TEST'))

    post_full = {p.point_id for p in t.filter(b'TEST', 0)}

    assert pre_full == post_full
Example #16
0
def test_Tree_add_same_data_but_different_point_id(leafcap):
    from pymvptree import Tree, Point

    t = Tree(leafcap=leafcap)

    for i in range(leafcap + 2):
        t.add(Point(i, b'TEST'))

    # LEAF is full
    with pytest.raises(RuntimeError):
        t.add(Point(-1, b'TEST'))

    ids = {p.point_id for p in t.filter(b'TEST', 0)}

    assert ids == set(range(leafcap + 2))
Example #17
0
def test_Tree_Point_point_id_save_and_restore(point_id):
    from pymvptree import Tree, Point
    from tempfile import mktemp

    t1 = Tree()
    t1.add(Point(point_id, b'TEST'))

    tempfile = mktemp()
    try:
        t1.to_file(tempfile)
        t2 = Tree.from_file(tempfile)
    finally:
        os.unlink(tempfile)

    s1 = {p for p in t1.filter(b'TEST', 1)}
    s2 = {p for p in t2.filter(b'TEST', 1)}

    assert s1 == s2
    assert Point(point_id, b'TEST') in s1
Example #18
0
def test_Tree_get_needs_arguments():
    from pymvptree import Tree 

    t = Tree()
    with pytest.raises(TypeError):
        assert t.get()
Example #19
0
def test_Tree_add_non_point():
    from pymvptree import Tree

    t = Tree()
    with pytest.raises(TypeError):
        t.add(b'BADTYPE')
Example #20
0
def test_Tree_load_from_file_unknown():
    from pymvptree import Tree
    from tempfile import mktemp

    with pytest.raises(IOError):
        Tree.from_file(mktemp())