def test_sync_dir(): try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure([], []) os.mkdir("simpletest/1/a/x/") _exec("simpletest/1/a", "simpletest/2/a") assert os.path.exists("simpletest/2/a/x/") shutil.rmtree("simpletest")
def test_empty_src(): try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure([], ["2.txt", "3.txt", "c/2c.txt"]) outs, errs = _exec("simpletest/1/a", "simpletest/2/a") assert "-f 2.txt\n-d c\n-f 3.txt\n" in outs assert errs == "" shutil.rmtree("simpletest")
def test_simple_diff_common_files(): try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure(["1.txt", "2.txt"], ["2.txt", "3.txt"]) outs, errs = _exec("simpletest/1/a", "simpletest/2/a") assert "+f 1.txt" in outs assert "-f 3.txt" in outs assert errs == "" shutil.rmtree("simpletest")
def test_identical(): try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure(["1.txt", "2.txt", "c/1c.txt"], ["1.txt", "2.txt", "c/1c.txt"]) outs, errs = _exec("simpletest/1/a", "simpletest/2/a") assert "Contents are identical" in outs assert errs == "" shutil.rmtree("simpletest")
def test_empty_dest(): try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure(["2.txt", "3.txt", "c/2c.txt"], []) outs, errs = _exec("simpletest/1/a", "simpletest/2/a") assert "+f 2.txt" in outs assert "+d c" in outs assert "+f c/2c.txt" in outs assert "+f 3.txt" in outs assert errs == "" shutil.rmtree("simpletest")
def test_sync_same_name(): try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure(["1.txt", "2.txt"], ["1.txt", "2.txt"]) f = open("simpletest/1/a/1.txt", "w+") f.write("A") f.close() f = open("simpletest/1/a/2.txt", "w+") f.write("A") f.close() _exec("simpletest/1/a", "simpletest/2/a") assert os.path.exists("simpletest/2/a/1.txt") assert os.path.exists("simpletest/2/a/2.txt") shutil.rmtree("simpletest")
def test_sync_files(): try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure(["1.txt", "2.txt", "c/1c.txt", "c/d/4.txt"], ["2.txt", "3.txt", "c/2c.txt"]) _exec("simpletest/1/a", "simpletest/2/a") assert os.path.exists("simpletest/2/a/c/d/4.txt") assert os.path.exists("simpletest/2/a/1.txt") assert os.path.exists("simpletest/2/a/2.txt") assert not os.path.exists("simpletest/2/a/3.txt") assert os.path.exists("simpletest/2/a/c/1c.txt") assert not os.path.exists("simpletest/2/a/c/2c.txt") shutil.rmtree("simpletest")
def test_find_diffs_async(): from main import analyse_diffs try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure( ["1.txt", "c/2.txt", "d/3.txt", "k/e/4.txt"], ["1.txt", "2.txt", "3.txt", "g/h/5.txt"], ) add_buffer, delete_buffer = analyse_diffs("simpletest/1/a", "simpletest/2/a", False) assert len(add_buffer) == 7 assert len(delete_buffer) == 3 shutil.rmtree("simpletest")
def test_hidden_files(): try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure( ["1.txt", "2.txt", "c/1c.txt", "d/.1d.txt"], ["2.txt", "3.txt", "c/2c.txt", "e/1e.txt"], ) outs, errs = _exec("simpletest/1/a", "simpletest/2/a") assert "+f 1.txt" in outs assert "+f c/1c.txt" in outs assert "-f c/2c.txt" in outs assert "+d d" in outs assert "+f d/.1d.txt" in outs assert "-d e" in outs assert "-f 3.txt" in outs assert errs == "" shutil.rmtree("simpletest")
def test_sync_diff(): from main import analyse_diffs try: shutil.rmtree("simpletest") except FileNotFoundError: pass create_structure( ["1.txt", "c/2.txt", "d/3.txt", "k/e/4.txt"], ["1.txt", "2.txt", "3.txt", "g/h/5.txt"], ) analyse_diffs("simpletest/1/a", "simpletest/2/a", False) _exec("simpletest/1/a", "simpletest/2/a") assert os.path.exists("simpletest/2/a/c/2.txt") assert os.path.exists("simpletest/2/a/d/3.txt") assert os.path.exists("simpletest/2/a/k/e/4.txt") assert not os.path.exists("simpletest/2/a/2.txt") assert not os.path.exists("simpletest/2/a/3.txt") assert not os.path.exists("simpletest/2/a/g") shutil.rmtree("simpletest")