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
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)
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