Beispiel #1
0
def test_no_dest(test_dir: str) -> None:
    """cp a_file -> d_dir should fail if d_dir does not exist"""
    a_file = os.path.join(test_dir, "a_file")
    d_dir = os.path.join(test_dir, "d_dir" + os.path.sep)
    sys.argv = ["pycp", a_file, d_dir]
    with pytest.raises(SystemExit):
        pycp_main()
Beispiel #2
0
def test_cp_exe_file(test_dir: str) -> None:
    """Copied exe file should still be executable"""
    exe_file = os.path.join(test_dir, "file.exe")
    exe_file_2 = os.path.join(test_dir, "file2.exe")
    sys.argv = ["pycp", exe_file, exe_file_2]
    pycp_main()
    assert os.access(exe_file_2, os.X_OK)
Beispiel #3
0
 def test_cp_exe_file(self):
     "copied file should still be executable"
     exe_file   = os.path.join(self.test_dir, "file.exe")
     exe_file_2 = os.path.join(self.test_dir, "file2.exe")
     sys.argv = ["pycp", exe_file, exe_file_2]
     pycp_main()
     self.assertTrue(os.access(exe_file_2, os.X_OK))
Beispiel #4
0
 def test_empty(self):
     "a_dir/empty -> b_dir"
     a_dir = os.path.join(self.test_dir, "a_dir")
     empty = os.path.join(self.test_dir, "a_dir", "empty")
     b_dir = os.path.join(self.test_dir, "b_dir")
     sys.argv = ["pymv", a_dir, b_dir]
     pycp_main()
Beispiel #5
0
 def test_empty(self):
     "a_dir/empty -> b_dir"
     a_dir = os.path.join(self.test_dir, "a_dir")
     empty = os.path.join(self.test_dir, "a_dir", "empty")
     b_dir = os.path.join(self.test_dir, "b_dir")
     sys.argv = ["pymv", a_dir, b_dir]
     pycp_main()
Beispiel #6
0
 def test_cp_exe_file(self):
     "copied file should still be executable"
     exe_file = os.path.join(self.test_dir, "file.exe")
     exe_file_2 = os.path.join(self.test_dir, "file2.exe")
     sys.argv = ["pycp", exe_file, exe_file_2]
     pycp_main()
     self.assertTrue(os.access(exe_file_2, os.X_OK))
Beispiel #7
0
def test_no_dest(test_dir):
    "a_file -> d_dir but d_dir does not exists"
    a_file = os.path.join(test_dir, "a_file")
    d_dir = os.path.join(test_dir, "d_dir" + os.path.sep)
    sys.argv = ["pycp", a_file, d_dir]
    with pytest.raises(SystemExit):
        pycp_main()
Beispiel #8
0
def test_several_sources_2(test_dir: str) -> None:
    """cp a_file b_file -> c_file should fail"""
    a_file = os.path.join(test_dir, "a_file")
    b_file = os.path.join(test_dir, "b_file")
    c_file = os.path.join(test_dir, "c_file")
    sys.argv = ["pycp", a_file, b_file, c_file]
    with pytest.raises(SystemExit):
        pycp_main()
Beispiel #9
0
def test_hidden(test_dir):
    a_dir = os.path.join(test_dir, "a_dir")
    dest = os.path.join(test_dir, "dest")
    os.mkdir(dest)
    sys.argv = ["pymv", a_dir, dest]
    pycp_main()
    hidden_copy = os.path.join(dest, "a_dir", ".hidden")
    assert os.path.exists(hidden_copy)
Beispiel #10
0
def test_hidden(test_dir):
    a_dir = os.path.join(test_dir, "a_dir")
    dest = os.path.join(test_dir, "dest")
    os.mkdir(dest)
    sys.argv = ["pymv", a_dir, dest]
    pycp_main()
    hidden_copy = os.path.join(dest, "a_dir", ".hidden")
    assert os.path.exists(hidden_copy)
Beispiel #11
0
def test_several_sources_1(test_dir):
    "a_file b_file c_file"
    a_file = os.path.join(test_dir, "a_file")
    b_file = os.path.join(test_dir, "b_file")
    c_file = os.path.join(test_dir, "c_file")
    sys.argv = ["pycp", a_file, b_file, c_file]
    with pytest.raises(SystemExit):
        pycp_main()
Beispiel #12
0
def test_several_sources_2(test_dir):
    "a_file b_file c_dir but c_dir does not exists"
    a_file = os.path.join(test_dir, "a_file")
    b_file = os.path.join(test_dir, "b_file")
    c_dir = os.path.join(test_dir, "c_dir")
    sys.argv = ["pycp", a_file, b_file, c_dir]
    with pytest.raises(SystemExit):
        pycp_main()
Beispiel #13
0
def test_several_sources_3(test_dir: str) -> None:
    """cp a_file b_file -> c_dir should fail if c_dir does not exist"""
    a_file = os.path.join(test_dir, "a_file")
    b_file = os.path.join(test_dir, "b_file")
    c_dir = os.path.join(test_dir, "c_dir")
    sys.argv = ["pycp", a_file, b_file, c_dir]
    with pytest.raises(SystemExit):
        pycp_main()
Beispiel #14
0
def test_several_sources_1(test_dir: str) -> None:
    """cp a_file b_file -> c_dir should work"""
    a_file = os.path.join(test_dir, "a_file")
    b_file = os.path.join(test_dir, "b_file")
    c_dir = os.path.join(test_dir, "c_dir")
    os.mkdir(c_dir)
    sys.argv = ["pycp", a_file, b_file, c_dir]
    pycp_main()
Beispiel #15
0
def test_mv_file_file(test_dir):
    "a_file -> a_file.back"
    a_file = os.path.join(test_dir, "a_file")
    a_file_back = os.path.join(test_dir, "a_file.back")

    sys.argv = ["pymv", a_file, a_file_back]
    pycp_main()
    assert os.path.exists(a_file_back)
    assert not os.path.exists(a_file)
Beispiel #16
0
    def test_mv_file_file(self):
        "a_file -> a_file.back"
        a_file = os.path.join(self.test_dir, "a_file")
        a_file_back = os.path.join(self.test_dir, "a_file.back")

        sys.argv = ["pymv", a_file, a_file_back]
        pycp_main()
        self.assertTrue(os.path.exists(a_file_back))
        self.assertFalse(os.path.exists(a_file))
Beispiel #17
0
def test_mv_file_file(test_dir: str) -> None:
    """mv a_file -> a_file.back should work"""
    a_file = os.path.join(test_dir, "a_file")
    a_file_back = os.path.join(test_dir, "a_file.back")

    sys.argv = ["pymv", a_file, a_file_back]
    pycp_main()
    assert os.path.exists(a_file_back)
    assert not os.path.exists(a_file)
Beispiel #18
0
def test_hidden(test_dir: str) -> None:
    """Check that hidden files are be moved too"""
    a_dir = os.path.join(test_dir, "a_dir")
    dest = os.path.join(test_dir, "dest")
    os.mkdir(dest)
    sys.argv = ["pymv", a_dir, dest]
    pycp_main()
    hidden_copy = os.path.join(dest, "a_dir", ".hidden")
    assert os.path.exists(hidden_copy)
Beispiel #19
0
def test_cp_file_file(test_dir):
    "a_file -> a_file.back"
    # cp a_file a_file.back
    a_file = os.path.join(test_dir, "a_file")
    a_file_back = os.path.join(test_dir, "a_file.back")

    sys.argv = ["pycp", a_file, a_file_back]
    pycp_main()
    assert os.path.exists(a_file_back)
Beispiel #20
0
def test_preserve(test_dir):
    a_file = os.path.join(test_dir, "a_file")
    long_ago = time.time() - 10000
    os.utime(a_file, (long_ago, long_ago))
    a_copy = os.path.join(test_dir, "a_copy")
    sys.argv = ["pycp", "--preserve", a_file, a_copy]
    pycp_main()
    copy_stat = os.stat(a_copy)
    assert copy_stat.st_mtime == long_ago
Beispiel #21
0
    def test_cp_file_file(self):
        "a_file -> a_file.back"
        # cp a_file a_file.back
        a_file = os.path.join(self.test_dir, "a_file")
        a_file_back = os.path.join(self.test_dir, "a_file.back")

        sys.argv = ["pycp", a_file, a_file_back]
        pycp_main()
        self.assertTrue(os.path.exists(a_file_back))
Beispiel #22
0
 def test_cp_file_dir(self):
     "a_file -> b_dir"
     a_file = os.path.join(self.test_dir, "a_file")
     b_dir  = os.path.join(self.test_dir, "b_dir")
     os.mkdir(b_dir)
     sys.argv = ["pycp", a_file, b_dir]
     pycp_main()
     dest = os.path.join(b_dir, "a_file")
     self.assertTrue(os.path.exists(dest))
Beispiel #23
0
def test_cp_file_dir(test_dir):
    "a_file -> b_dir"
    a_file = os.path.join(test_dir, "a_file")
    b_dir = os.path.join(test_dir, "b_dir")
    os.mkdir(b_dir)
    sys.argv = ["pycp", a_file, b_dir]
    pycp_main()
    dest = os.path.join(b_dir, "a_file")
    assert os.path.exists(dest)
Beispiel #24
0
 def test_cp_file_dir(self):
     "a_file -> b_dir"
     a_file = os.path.join(self.test_dir, "a_file")
     b_dir = os.path.join(self.test_dir, "b_dir")
     os.mkdir(b_dir)
     sys.argv = ["pycp", a_file, b_dir]
     pycp_main()
     dest = os.path.join(b_dir, "a_file")
     self.assertTrue(os.path.exists(dest))
Beispiel #25
0
def test_mv_file_file(test_dir):
    "a_file -> a_file.back"
    a_file = os.path.join(test_dir, "a_file")
    a_file_back = os.path.join(test_dir, "a_file.back")

    sys.argv = ["pymv", a_file, a_file_back]
    pycp_main()
    assert os.path.exists(a_file_back)
    assert not os.path.exists(a_file)
Beispiel #26
0
def test_copy_readonly(test_dir: str) -> None:
    """cp a_file -> ro_dir should fail if ro_dir is read only"""
    a_file = os.path.join(test_dir, "a_file")
    ro_dir = tempfile.mkdtemp("pycp-test-ro")
    os.chmod(ro_dir, stat.S_IRUSR | stat.S_IXUSR)
    sys.argv = ["pycp", a_file, ro_dir]
    with pytest.raises(SystemExit):
        pycp_main()
    shutil.rmtree(ro_dir)
Beispiel #27
0
def test_cp_file_file(test_dir: str) -> None:
    """cp a_file -> a_file.back should work"""
    # cp a_file a_file.back
    a_file = os.path.join(test_dir, "a_file")
    a_file_back = os.path.join(test_dir, "a_file.back")

    sys.argv = ["pycp", a_file, a_file_back]
    pycp_main()
    assert os.path.exists(a_file_back)
Beispiel #28
0
    def test_mv_file_file(self):
        "a_file -> a_file.back"
        a_file      = os.path.join(self.test_dir, "a_file")
        a_file_back = os.path.join(self.test_dir, "a_file.back")

        sys.argv = ["pymv", a_file, a_file_back]
        pycp_main()
        self.assertTrue (os.path.exists(a_file_back))
        self.assertFalse(os.path.exists(a_file))
Beispiel #29
0
    def test_cp_file_file(self):
        "a_file -> a_file.back"
        # cp a_file a_file.back
        a_file      = os.path.join(self.test_dir, "a_file")
        a_file_back = os.path.join(self.test_dir, "a_file.back")

        sys.argv = ["pycp", a_file, a_file_back]
        pycp_main()
        self.assertTrue(os.path.exists(a_file_back))
Beispiel #30
0
def test_cp_file_dir(test_dir: str) -> None:
    """cp a_file -> b_dir should work"""
    a_file = os.path.join(test_dir, "a_file")
    b_dir = os.path.join(test_dir, "b_dir")
    os.mkdir(b_dir)
    sys.argv = ["pycp", a_file, b_dir]
    pycp_main()
    dest = os.path.join(b_dir, "a_file")
    assert os.path.exists(dest)
Beispiel #31
0
 def test_overwrite_2(self):
     "a_file -> b_file and b_file already exists (safe)"
     a_file = os.path.join(self.test_dir, "a_file")
     b_file = os.path.join(self.test_dir, "b_file")
     sys.argv = ["pycp", "--safe",  a_file, b_file]
     pycp_main()
     b_file_desc = open(b_file, "r")
     b_contents  = b_file_desc.read()
     b_file_desc.close()
     self.assertEquals(b_contents, "b\n")
Beispiel #32
0
 def test_cp_dir_dir_1(self):
     "a_dir -> b_dir (b_dir does not exist)"
     a_dir = os.path.join(self.test_dir, "a_dir")
     b_dir = os.path.join(self.test_dir, "b_dir")
     sys.argv = ["pycp", a_dir, b_dir]
     pycp_main()
     c_file = os.path.join(b_dir, "c_file")
     d_file = os.path.join(b_dir, "c_file")
     self.assertTrue(os.path.exists(c_file))
     self.assertTrue(os.path.exists(d_file))
Beispiel #33
0
def test_cp_dir_dir_1(test_dir):
    "a_dir -> b_dir (b_dir does not exist)"
    a_dir = os.path.join(test_dir, "a_dir")
    b_dir = os.path.join(test_dir, "b_dir")
    sys.argv = ["pycp", a_dir, b_dir]
    pycp_main()
    c_file = os.path.join(b_dir, "c_file")
    d_file = os.path.join(b_dir, "c_file")
    assert os.path.exists(c_file)
    assert os.path.exists(d_file)
Beispiel #34
0
def test_preserve(test_dir: str) -> None:
    """ Check that mtimes are preserved"""
    a_file = os.path.join(test_dir, "a_file")
    long_ago = time.time() - 10000
    os.utime(a_file, (long_ago, long_ago))
    a_copy = os.path.join(test_dir, "a_copy")
    sys.argv = ["pycp", "--preserve", a_file, a_copy]
    pycp_main()
    copy_stat = os.stat(a_copy)
    assert copy_stat.st_mtime == pytest.approx(long_ago, abs=1)
Beispiel #35
0
def test_overwrite_2(test_dir: str) -> None:
    """cp a_file -> b_file should not overwrite b_file when using --safe"""
    a_file = os.path.join(test_dir, "a_file")
    b_file = os.path.join(test_dir, "b_file")
    sys.argv = ["pycp", "--safe", a_file, b_file]
    pycp_main()
    b_file_desc = open(b_file, "r")
    b_contents = b_file_desc.read()
    b_file_desc.close()
    assert b_contents == "b\n"
Beispiel #36
0
 def test_overwrite_1(self):
     "a_file -> b_file and b_file already exists (unsafe)"
     a_file = os.path.join(self.test_dir, "a_file")
     b_file = os.path.join(self.test_dir, "b_file")
     sys.argv = ["pycp", a_file, b_file]
     pycp_main()
     b_file_desc = open(b_file, "r")
     b_contents = b_file_desc.read()
     b_file_desc.close()
     self.assertEquals(b_contents, "a\n")
Beispiel #37
0
def test_cp_dir_dir_1(test_dir: str) -> None:
    """cp a_dir -> b_dir should work when b_dir does not exist"""
    a_dir = os.path.join(test_dir, "a_dir")
    b_dir = os.path.join(test_dir, "b_dir")
    sys.argv = ["pycp", a_dir, b_dir]
    pycp_main()
    c_file = os.path.join(b_dir, "c_file")
    d_file = os.path.join(b_dir, "c_file")
    assert os.path.exists(c_file)
    assert os.path.exists(d_file)
Beispiel #38
0
def test_cp_dir_dir2_global(test_dir):
    a_dir = os.path.join(test_dir, "a_dir")
    b_dir = os.path.join(test_dir, "b_dir")
    os.mkdir(b_dir)
    sys.argv = ["pycp", "-g", a_dir, b_dir]
    pycp_main()
    c_file = os.path.join(b_dir, "a_dir", "c_file")
    d_file = os.path.join(b_dir, "a_dir", "c_file")
    assert os.path.exists(c_file)
    assert os.path.exists(d_file)
Beispiel #39
0
 def test_cp_dir_dir2_global(self):
     a_dir = os.path.join(self.test_dir, "a_dir")
     b_dir = os.path.join(self.test_dir, "b_dir")
     os.mkdir(b_dir)
     sys.argv = ["pycp", "-g", a_dir, b_dir]
     pycp_main()
     c_file = os.path.join(b_dir, "a_dir", "c_file")
     d_file = os.path.join(b_dir, "a_dir", "c_file")
     self.assertTrue(os.path.exists(c_file))
     self.assertTrue(os.path.exists(d_file))
Beispiel #40
0
def test_overwrite_2(test_dir):
    "a_file -> b_file and b_file already exists (safe)"
    a_file = os.path.join(test_dir, "a_file")
    b_file = os.path.join(test_dir, "b_file")
    sys.argv = ["pycp", "--safe", a_file, b_file]
    pycp_main()
    b_file_desc = open(b_file, "r")
    b_contents = b_file_desc.read()
    b_file_desc.close()
    assert b_contents == "b\n"
Beispiel #41
0
def test_mv_dir_dir_1(test_dir):
    "a_dir -> b_dir (b_dir does not exist)"
    a_dir = os.path.join(test_dir, "a_dir")
    b_dir = os.path.join(test_dir, "b_dir")
    sys.argv = ["pymv", a_dir, b_dir]
    pycp_main()
    c_file = os.path.join(b_dir, "c_file")
    d_file = os.path.join(b_dir, "c_file")
    assert os.path.exists(c_file)
    assert os.path.exists(d_file)
    assert not os.path.exists(a_dir)
Beispiel #42
0
 def test_mv_dir_dir2_global(self):
     "a_dir -> b_dir (b_dir does not exist), with --global"
     a_dir = os.path.join(self.test_dir, "a_dir")
     b_dir = os.path.join(self.test_dir, "b_dir")
     sys.argv = ["pymv", a_dir, b_dir]
     pycp_main()
     c_file = os.path.join(b_dir, "c_file")
     d_file = os.path.join(b_dir, "c_file")
     self.assertTrue (os.path.exists(c_file))
     self.assertTrue (os.path.exists(d_file))
     self.assertFalse(os.path.exists(a_dir))
Beispiel #43
0
 def test_overwrite_1(self):
     "a_file -> b_file and b_file already exists (unsafe)"
     a_file = os.path.join(self.test_dir, "a_file")
     b_file = os.path.join(self.test_dir, "b_file")
     sys.argv = ["pymv", a_file, b_file]
     pycp_main()
     b_file_desc = open(b_file, "r")
     b_contents = b_file_desc.read()
     b_file_desc.close()
     self.assertEqual(b_contents, "a\n")
     self.assertFalse(os.path.exists(a_file))
Beispiel #44
0
 def test_mv_dir_dir_2(self):
     "a_dir -> b_dir (b_dir exists)"
     a_dir = os.path.join(self.test_dir, "a_dir")
     b_dir = os.path.join(self.test_dir, "b_dir")
     os.mkdir(b_dir)
     sys.argv = ["pymv", a_dir, b_dir]
     pycp_main()
     c_file = os.path.join(b_dir, "a_dir", "c_file")
     d_file = os.path.join(b_dir, "a_dir", "c_file")
     self.assertTrue (os.path.exists(c_file))
     self.assertTrue (os.path.exists(d_file))
     self.assertFalse(os.path.exists(a_dir))
Beispiel #45
0
 def test_cp_keep_rel_symlink(self):
     a_link = os.path.join(self.test_dir, "a_link")
     a_target = os.path.join(self.test_dir, "a_target")
     with open(a_target, "w") as fp:
         fp.write("a_target\n")
     os.symlink("a_target", a_link)
     b_dir = os.path.join(self.test_dir, "b_dir")
     os.mkdir(b_dir)
     b_link = os.path.join(b_dir, "b_link")
     sys.argv = ["pycp", a_link, b_link]
     pycp_main()
     self.assertTrue(os.path.islink(b_link))
     b_target = os.readlink(b_link)
     self.assertEquals(b_target, "a_target")
Beispiel #46
0
 def test_cp_symlink(self):
     # note: since shutil.copytree does not handle
     # symlinks the way we would like to, create
     # link now
     a_link = os.path.join(self.test_dir, "a_link")
     a_target = os.path.join(self.test_dir, "a_target")
     with open(a_target, "w") as fp:
         fp.write("a_target\n")
     os.symlink("a_target", a_link)
     b_link = os.path.join(self.test_dir, "b_link")
     sys.argv = ["pycp", a_link, b_link]
     pycp_main()
     self.assertTrue(os.path.islink(b_link))
     b_target = os.readlink(b_link)
     self.assertEquals(b_target, "a_target")
Beispiel #47
0
def main():
    sys.argv = ["pycp", "src.dat", "dest.dat"]
    pycp_main()