def test_cp_file_exists(tmp_path): """ should fail because src and dst are the same. print error and systemexist. """ src_dir, dst_dir, src_file = setup_dirs(tmp_path) with pytest.raises(SystemExit) as context: s = Shot(src=str(src_dir), dst=str(src_dir)) s._confirm = lambda: True # avoid capturing stdin during test s() assert (1, ) == context.value.args
def test_debug_mv_file_exists(tmp_path): """ should fail because src and dst are the same. latest file will be foo, will fail to copy since it already exists. """ src_dir, dst_dir, src_file = setup_dirs(tmp_path) with pytest.raises(Exception) as context: s = Shot(src=str(src_dir), dst=str(src_dir), mv=True, debug=True) s._confirm = lambda: True # avoid capturing stdin during test s() assert f"Destination path '{src_file}' already exists" in context.value.args
def test_cp_to_file(tmp_path): """ dst dir exists but dst/bar.txt does not. shot should create it by copying src/foo1.txt to dst/bar.txt """ src_dir, dst_dir, src_file = setup_dirs(tmp_path) expected_output_path = dst_dir / "bar.txt" assert os.path.exists(src_file) == True assert os.path.exists(expected_output_path) == False s = Shot(src=str(src_dir), dst=str(expected_output_path)) s._confirm = lambda: True # avoid capturing stdin during test s() assert os.path.exists(src_file) == True assert os.path.exists(expected_output_path) == True