From 46da49052a956bc431afccf172303b28c4d48986 Mon Sep 17 00:00:00 2001 From: xuzg Date: Fri, 1 Dec 2017 20:54:57 +0800 Subject: [PATCH 01/12] Add tests for remove --- tests/test_file.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/test_file.py b/tests/test_file.py index 3f33417..fc64537 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -1,5 +1,5 @@ import os -from pydu.file import makedirs +from pydu.file import makedirs,remove import pytest @@ -30,3 +30,29 @@ class Testmakedirs(): path = str(tmpdir.join('test/test')) makedirs(path) assert os.path.exists(path) + +class Testremove(): + def test_remove_dir(self, tmpdir): + path = str(tmpdir.join('test')) + makedirs(path) + remove(path) + assert not os.path.exists(path) + + def test_remove_file(self, tmpdir): + file = str(tmpdir.join('test.txt')) + open(file, 'w') + remove(file) + assert not os.path.exists(file) + + def test_remove_mutil_dirs(self, tmpdir): + path = str(tmpdir.join('test/test')) + makedirs(path) + path = str(tmpdir.join('test')) + remove(path) + assert not os.path.exists(path) + + def test_remove_with_ignore_error(self): + pass + + def test_remove_without_ignore_error(self): + pass From 1c7f5ed830844ef3e45fc2cdca53c6ed7dfa5d9e Mon Sep 17 00:00:00 2001 From: xuzg Date: Fri, 1 Dec 2017 22:43:46 +0800 Subject: [PATCH 02/12] Add exit_ok=True in open file when parent dir is exists --- pydu/file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydu/file.py b/pydu/file.py index 4c8bf9e..f2eb2b0 100644 --- a/pydu/file.py +++ b/pydu/file.py @@ -72,7 +72,7 @@ def open_file(path, mode='wb+', buffer_size=-1, ignore_errors=False): f = None try: if path and not os.path.isdir(path): - makedirs(os.path.dirname(path)) + makedirs(os.path.dirname(path), exist_ok=True) f = open(path, mode, buffer_size) except Exception: if not ignore_errors: From 75a7be7ea22b5b5bc3af69e706515574bbb5896c Mon Sep 17 00:00:00 2001 From: xuzg Date: Fri, 1 Dec 2017 22:44:32 +0800 Subject: [PATCH 03/12] Add test forremoves open_file and so on --- tests/test_file.py | 105 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 6 deletions(-) diff --git a/tests/test_file.py b/tests/test_file.py index 6694c31..8d2196a 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -1,5 +1,6 @@ import os from pydu.file import makedirs,remove +from pydu.file import removes,open_file import pytest @@ -34,6 +35,7 @@ class Testmakedirs(): makedirs(path) assert os.path.exists(path) + class Testremove(): def test_remove_dir(self, tmpdir): path = str(tmpdir.join('test')) @@ -42,10 +44,10 @@ class Testremove(): assert not os.path.exists(path) def test_remove_file(self, tmpdir): - file = str(tmpdir.join('test.txt')) - open(file, 'w') - remove(file) - assert not os.path.exists(file) + filename = str(tmpdir.join('test.txt')) + open(filename, 'w') + remove(filename) + assert not os.path.exists(filename) def test_remove_mutil_dirs(self, tmpdir): path = str(tmpdir.join('test/test')) @@ -54,8 +56,99 @@ class Testremove(): remove(path) assert not os.path.exists(path) - def test_remove_with_ignore_error(self): + def test_remove_with_ignore_error(self, tmpdir): + path = str(tmpdir.join('test')) + remove(path, ignore_errors=True) + + def test_remove_without_ignore_error(self, tmpdir): + path = str(tmpdir.join('test')) + with pytest.raises(Exception) as e: + remove(path, ignore_errors=False) + + def test_remove_without_ignore_error_with_onerror(self): pass - def test_remove_without_ignore_error(self): + +class Testremoves(): + def test_removes_paths(self, tmpdir): + path1 = str(tmpdir.join('test1')) + path2 = str(tmpdir.join('test2')) + path3 = str(tmpdir.join('test3')) + for path in [path1, path2, path3]: + makedirs(path) + removes([path1, path2, path3]) + assert not os.path.exists(path1) + assert not os.path.exists(path2) + assert not os.path.exists(path3) + + def test_removes_files(self,tmpdir): + f1 = str(tmpdir.join('test1.txt')) + f2 = str(tmpdir.join('test2.txt')) + f3 = str(tmpdir.join('test3.txt')) + for f in [f1, f2, f3]: + open(f, 'w') + removes([f1, f2, f3]) + for f in [f1, f2, f3]: + assert not os.path.exists(f) + + def test_removes_files_and_path(self,tmpdir): + f1 = str(tmpdir.join('test1.txt')) + f2 = str(tmpdir.join('test2.txt')) + p1 = str(tmpdir.join('test1')) + p2 = str(tmpdir.join('test2')) + for f in [f1,f2]: + open(f, 'w') + for p in [p1,p2]: + makedirs(p) + removes([f1, f2, p1, p2]) + for f in [f1, f2, p1, p2]: + assert not os.path.exists(f) + + +class Testopenfile(): + def test_open_file_without_parent_dir(self,tmpdir): + f = str(tmpdir.join('test/test1.txt')) + open_file(f) + assert os.path.exists(f) + + def test_open_file_in_exist_path(self, tmpdir): + f = str(tmpdir.join('test2.txt')) + open_file(f) + assert os.path.exists(f) + + def test_open_exist_file(self,tmpdir): + f = str(tmpdir.join('test3.txt')) + open_file(f) + with open(f, 'r') as f: + with pytest.raises(Exception) as f: + os.remove(f) + + def test_open_file_with_ignore_error(self, tmpdir): + f = str(tmpdir.join('test1.txt')) + open_file(f, mode='r', ignore_errors=True) + + def test_open_file_without_ignore_error(self,tmpdir): + f = str(tmpdir.join('test1.txt')) + with pytest.raises(Exception) as e: + open_file(f, mode='r') + + +class Testlink(): + def test_link_a_file(self, tmpdir): pass + + def test_link_a_dir(self, tmpdir): + pass + + def test_link_with_overwrite(self,tmpdir): + pass + + def test_link_without_link(self,tmpdir): + pass + + def test_link_with_ignore_error(self,tmpdir): + pass + + def test_link_without_error(self,tmpdir): + pass + From f45d227cda82e55525492b8adace30a8a1ab4f5f Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 16:13:47 +0800 Subject: [PATCH 04/12] py2 shutil.copy have no paraamter follow_symlink --- pydu/file.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pydu/file.py b/pydu/file.py index f2eb2b0..1fd840a 100644 --- a/pydu/file.py +++ b/pydu/file.py @@ -98,7 +98,10 @@ def copy(src, dst, ignore_errors=False, follow_symlinks=True): if os.path.isdir(src): shutil.copytree(src, dst, symlinks=not follow_symlinks) else: - shutil.copy(src, dst, follow_symlinks=follow_symlinks) + if not follow_symlinks and os.path.islink(src): + os.symlink(os.readlink(src), dst) + else: + shutil.copy(src, dst) except Exception: if not ignore_errors: raise OSError('Copy {} to {} error'.format(src, dst)) From cb28914589da488abb61a308316178fb6d36fb33 Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 16:14:14 +0800 Subject: [PATCH 05/12] Add test for link copy --- tests/test_file.py | 153 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 141 insertions(+), 12 deletions(-) diff --git a/tests/test_file.py b/tests/test_file.py index 8d2196a..23ccde5 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -1,7 +1,8 @@ import os -from pydu.file import makedirs,remove -from pydu.file import removes,open_file +from pydu.file import makedirs,remove,link +from pydu.file import removes,open_file,copy import pytest +import sys class Testmakedirs(): @@ -133,22 +134,150 @@ class Testopenfile(): open_file(f, mode='r') +@pytest.mark.skipif(sys.platform == 'win32', + reason="does not run on windows") class Testlink(): def test_link_a_file(self, tmpdir): - pass + file = str(tmpdir.join('test.txt')) + link_file = str(tmpdir.join('test.link')) + open(file) + link(file, link_file) + assert os.path.exists(link_file) def test_link_a_dir(self, tmpdir): - pass + dirname = str(tmpdir.join('test')) + link_dirname = str(tmpdir.join('test.link')) + makedirs(dirname) + link(dirname, link_dirname) + assert os.path.exists(link_dirname) - def test_link_with_overwrite(self,tmpdir): - pass + def test_link_with_overwrite(self, tmpdir): + dirname = str(tmpdir.join('test')) + link_dirname = str(tmpdir.join('test.link')) + makedirs(dirname) + link(dirname, link_dirname) + link(dirname, link_dirname, overwrite=True) + assert os.path.exists(link_dirname) - def test_link_without_link(self,tmpdir): - pass + def test_link_without_overwrite(self, tmpdir): + dirname = str(tmpdir.join('test')) + link_dirname = str(tmpdir.join('test.link')) + makedirs(dirname) + link(dirname, link_dirname) + with pytest.raises(Exception) as e: + link(dirname, link_dirname) - def test_link_with_ignore_error(self,tmpdir): - pass + def test_link_with_ignore_error(self, tmpdir): + dirname = str(tmpdir.join('test')) + link_dirname = str(tmpdir.join('test.link')) + makedirs(dirname) + link(dirname, link_dirname) + link(dirname, link_dirname, ignore_errors=True) - def test_link_without_error(self,tmpdir): - pass + def test_link_without_ignore_error(self, tmpdir): + dirname = str(tmpdir.join('test')) + link_dirname = str(tmpdir.join('test.link')) + makedirs(dirname) + link(dirname, link_dirname) + with pytest.raises(Exception) as e: + link(dirname, link_dirname) + +class Testcopy(): + def test_copy_file(self,tmpdir): + f = str(tmpdir.join('test.txt')) + f_copy = str(tmpdir.join('test_copy.txt')) + open(f, 'w') + copy(f, f_copy) + assert os.path.exists(f_copy) + + def test_copy_non_empty_dir(self, tmpdir): + f = str(tmpdir.join('test/test.txt')) + d = str(tmpdir.join('test')) + d_copy = str(tmpdir.join('test_copy')) + os.makedirs(d) + open(f, 'w') + copy(d, d_copy) + assert os.path.exists(d_copy) + + def test_copy_empty_dir(self,tmpdir): + d = str(tmpdir.join('test')) + d_copy = str(tmpdir.join('test_copy')) + makedirs(d) + copy(d,d_copy) + assert os.path.exists(d_copy) + + @pytest.mark.skipif(sys.platform == 'win32', + reason="does not run on windows") + def test_copy_dir_follow_symlink(self, tmpdir): + f = str(tmpdir.join('test/test.txt')) + d = str(tmpdir.join('test')) + link_f = str(tmpdir.join('test/test_link.txt')) + d_copy = str(tmpdir.join('test_copy')) + new_link_f = str(tmpdir.join('test_copy/test_link.txt')) + open(f) + os.symlink(f, link_f) + copy(d, d_copy, follow_symlinks=True) + assert os.path.exists(d_copy) + assert os.path.islink(new_link_f) + + @pytest.mark.skipif(sys.platform == 'win32', + reason="does not run on windows") + def test_copy_dir_not_follow_symlink(self, tmpdir): + f = str(tmpdir.join('test/test.txt')) + d = str(tmpdir.join('test')) + link_f = str(tmpdir.join('test/test_link.txt')) + d_copy = str(tmpdir.join('test_copy')) + new_link_f = str(tmpdir.join('test_copy/test_link.txt')) + open(f) + os.symlink(f, link_f) + copy(d, d_copy) + assert os.path.exists(d_copy) + assert not os.path.islink(new_link_f) + + @pytest.mark.skipif(sys.platform == 'win32', + reason="does not run on windows") + def test_copy_file_follow_symlink(self, tmpdir): + file = str(tmpdir.join('test.txt')) + link_file = str(tmpdir.join('test.link')) + copy_link_file = str(tmpdir.join('test_copy.link')) + open(file) + link(file, link_file) + copy(link_file, copy_link_file,follow_symlinks=True) + assert os.path.exists(copy_link_file) + assert not os.path.islink(copy_link_file) + + @pytest.mark.skipif(sys.platform == 'win32', + reason="does not run on windows") + def test_copy_file_not_follow_symlink(self, tmpdir): + file = str(tmpdir.join('test.txt')) + link_file = str(tmpdir.join('test.link')) + copy_link_file = str(tmpdir.join('test_copy.link')) + open(file) + link(file, link_file) + copy(link_file, copy_link_file, follow_symlinks=False) + assert os.path.exists(copy_link_file) + assert os.path.islink(copy_link_file) + + def test_copy_path_to_exits_path(self, tmpdir): + dir1 = str(tmpdir.join('test1')) + dir2 = str(tmpdir.join('test2')) + makedirs(dir1) + makedirs(dir2) + with pytest.raises(Exception) as e: + copy(dir1, dir2) + + def test_copy_without_ignore_error(self, tmpdir): + dir1 = str(tmpdir.join('test1')) + dir2 = str(tmpdir.join('test2')) + makedirs(dir1) + makedirs(dir2) + with pytest.raises(Exception) as e: + copy(dir1, dir2, ignore_errors=False) + + def test_copy_with_ignore_error(self, tmpdir): + dir1 = str(tmpdir.join('test1')) + dir2 = str(tmpdir.join('test2')) + makedirs(dir1) + makedirs(dir2) + copy(dir1, dir2, ignore_errors=True) From a58d48209a039da99611f74f118b1161c4427fd7 Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 16:20:00 +0800 Subject: [PATCH 06/12] Open file with write mode --- tests/test_file.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_file.py b/tests/test_file.py index 23ccde5..5cadf72 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -140,7 +140,7 @@ class Testlink(): def test_link_a_file(self, tmpdir): file = str(tmpdir.join('test.txt')) link_file = str(tmpdir.join('test.link')) - open(file) + open(file, 'w') link(file, link_file) assert os.path.exists(link_file) @@ -215,7 +215,7 @@ class Testcopy(): link_f = str(tmpdir.join('test/test_link.txt')) d_copy = str(tmpdir.join('test_copy')) new_link_f = str(tmpdir.join('test_copy/test_link.txt')) - open(f) + open(f, 'w') os.symlink(f, link_f) copy(d, d_copy, follow_symlinks=True) assert os.path.exists(d_copy) @@ -229,7 +229,7 @@ class Testcopy(): link_f = str(tmpdir.join('test/test_link.txt')) d_copy = str(tmpdir.join('test_copy')) new_link_f = str(tmpdir.join('test_copy/test_link.txt')) - open(f) + open(f, 'w') os.symlink(f, link_f) copy(d, d_copy) assert os.path.exists(d_copy) @@ -241,7 +241,7 @@ class Testcopy(): file = str(tmpdir.join('test.txt')) link_file = str(tmpdir.join('test.link')) copy_link_file = str(tmpdir.join('test_copy.link')) - open(file) + open(file, 'w') link(file, link_file) copy(link_file, copy_link_file,follow_symlinks=True) assert os.path.exists(copy_link_file) @@ -253,7 +253,7 @@ class Testcopy(): file = str(tmpdir.join('test.txt')) link_file = str(tmpdir.join('test.link')) copy_link_file = str(tmpdir.join('test_copy.link')) - open(file) + open(file, 'w') link(file, link_file) copy(link_file, copy_link_file, follow_symlinks=False) assert os.path.exists(copy_link_file) From fd0965e02faa3f261a29e1a0c8ce6d417da5cd7c Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 16:26:34 +0800 Subject: [PATCH 07/12] makedir before open an not exist file --- tests/test_file.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_file.py b/tests/test_file.py index 5cadf72..2c10124 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -215,6 +215,7 @@ class Testcopy(): link_f = str(tmpdir.join('test/test_link.txt')) d_copy = str(tmpdir.join('test_copy')) new_link_f = str(tmpdir.join('test_copy/test_link.txt')) + makedirs(d) open(f, 'w') os.symlink(f, link_f) copy(d, d_copy, follow_symlinks=True) @@ -229,6 +230,7 @@ class Testcopy(): link_f = str(tmpdir.join('test/test_link.txt')) d_copy = str(tmpdir.join('test_copy')) new_link_f = str(tmpdir.join('test_copy/test_link.txt')) + makedirs(d) open(f, 'w') os.symlink(f, link_f) copy(d, d_copy) @@ -243,7 +245,7 @@ class Testcopy(): copy_link_file = str(tmpdir.join('test_copy.link')) open(file, 'w') link(file, link_file) - copy(link_file, copy_link_file,follow_symlinks=True) + copy(link_file, copy_link_file, follow_symlinks=True) assert os.path.exists(copy_link_file) assert not os.path.islink(copy_link_file) From 6c1c686c15836f24bf50ed5638c62f47e9ffc7f0 Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 16:33:16 +0800 Subject: [PATCH 08/12] Delete test in link for can not link a dir to another --- tests/test_file.py | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/tests/test_file.py b/tests/test_file.py index 2c10124..c935548 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -144,41 +144,16 @@ class Testlink(): link(file, link_file) assert os.path.exists(link_file) - def test_link_a_dir(self, tmpdir): - dirname = str(tmpdir.join('test')) - link_dirname = str(tmpdir.join('test.link')) - makedirs(dirname) - link(dirname, link_dirname) - assert os.path.exists(link_dirname) - - def test_link_with_overwrite(self, tmpdir): - dirname = str(tmpdir.join('test')) - link_dirname = str(tmpdir.join('test.link')) - makedirs(dirname) - link(dirname, link_dirname) - link(dirname, link_dirname, overwrite=True) - assert os.path.exists(link_dirname) - - def test_link_without_overwrite(self, tmpdir): - dirname = str(tmpdir.join('test')) - link_dirname = str(tmpdir.join('test.link')) - makedirs(dirname) - link(dirname, link_dirname) - with pytest.raises(Exception) as e: - link(dirname, link_dirname) - def test_link_with_ignore_error(self, tmpdir): dirname = str(tmpdir.join('test')) link_dirname = str(tmpdir.join('test.link')) makedirs(dirname) - link(dirname, link_dirname) link(dirname, link_dirname, ignore_errors=True) def test_link_without_ignore_error(self, tmpdir): dirname = str(tmpdir.join('test')) link_dirname = str(tmpdir.join('test.link')) makedirs(dirname) - link(dirname, link_dirname) with pytest.raises(Exception) as e: link(dirname, link_dirname) From b0f8c07d0e533bfaf7dbb313bbd7e0aee6833205 Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 16:36:49 +0800 Subject: [PATCH 09/12] Modify link to symlink --- tests/test_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_file.py b/tests/test_file.py index c935548..d324bfb 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -231,7 +231,7 @@ class Testcopy(): link_file = str(tmpdir.join('test.link')) copy_link_file = str(tmpdir.join('test_copy.link')) open(file, 'w') - link(file, link_file) + os.symlink(file, link_file) copy(link_file, copy_link_file, follow_symlinks=False) assert os.path.exists(copy_link_file) assert os.path.islink(copy_link_file) From 1fe52eb8fe5afc552fd60d83dba5913ecb0df79e Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 16:45:14 +0800 Subject: [PATCH 10/12] Keep symlink in a direcotory when follow_symlink is false --- tests/test_file.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_file.py b/tests/test_file.py index d324bfb..1ad2333 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -195,7 +195,7 @@ class Testcopy(): os.symlink(f, link_f) copy(d, d_copy, follow_symlinks=True) assert os.path.exists(d_copy) - assert os.path.islink(new_link_f) + assert not os.path.islink(new_link_f) @pytest.mark.skipif(sys.platform == 'win32', reason="does not run on windows") @@ -208,9 +208,9 @@ class Testcopy(): makedirs(d) open(f, 'w') os.symlink(f, link_f) - copy(d, d_copy) + copy(d, d_copy, follow_symlinks=False) assert os.path.exists(d_copy) - assert not os.path.islink(new_link_f) + assert os.path.islink(new_link_f) @pytest.mark.skipif(sys.platform == 'win32', reason="does not run on windows") From ea35a05ce8ee581ab5ec663ed44f05973466a7be Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 17:01:10 +0800 Subject: [PATCH 11/12] Add symlink function --- pydu/file.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pydu/file.py b/pydu/file.py index 1fd840a..403445d 100644 --- a/pydu/file.py +++ b/pydu/file.py @@ -93,10 +93,23 @@ def link(src, dst, overwrite=False, ignore_errors=False): raise OSError('Link {} to {} error'.format(dst, src)) +def symlink(src, dst, overwrite=False, ignore_errors=False): + try: + if os.path.exists(dst): + if overwrite: + remove(dst) + else: + return + os.symlink(src, dst) + except Exception: + if not ignore_errors: + raise OSError('Link {} to {} error'.format(dst, src)) + + def copy(src, dst, ignore_errors=False, follow_symlinks=True): try: if os.path.isdir(src): - shutil.copytree(src, dst, symlinks=not follow_symlinks) + shutil.copytree(src, dst, symlinks=follow_symlinks) else: if not follow_symlinks and os.path.islink(src): os.symlink(os.readlink(src), dst) From 495cc1b7e9f6dfe040e86db36d617bd61d1ebfee Mon Sep 17 00:00:00 2001 From: xuzg Date: Sat, 2 Dec 2017 17:01:44 +0800 Subject: [PATCH 12/12] Add test for symlink --- tests/test_file.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/test_file.py b/tests/test_file.py index 1ad2333..643fbd9 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -1,6 +1,7 @@ import os -from pydu.file import makedirs,remove,link -from pydu.file import removes,open_file,copy +from pydu.file import makedirs, remove +from pydu.file import removes, open_file, copy +from pydu.file import link, symlink import pytest import sys @@ -158,6 +159,31 @@ class Testlink(): link(dirname, link_dirname) +@pytest.mark.skipif(sys.platform == 'win32', + reason="does not run on windows") +class Testsymlink(): + def test_link_a_file(self, tmpdir): + file = str(tmpdir.join('test.txt')) + link_file = str(tmpdir.join('test.link')) + open(file, 'w') + symlink(file, link_file) + assert os.path.exists(link_file) + assert os.path.islink(link_file) + + def test_link_with_ignore_error(self, tmpdir): + dirname = str(tmpdir.join('test')) + link_dirname = str(tmpdir.join('test.link')) + makedirs(dirname) + link(dirname, link_dirname, ignore_errors=True) + + def test_link_without_ignore_error(self, tmpdir): + dirname = str(tmpdir.join('test')) + link_dirname = str(tmpdir.join('test.link')) + makedirs(dirname) + with pytest.raises(Exception) as e: + link(dirname, link_dirname) + + class Testcopy(): def test_copy_file(self,tmpdir): f = str(tmpdir.join('test.txt')) @@ -195,7 +221,7 @@ class Testcopy(): os.symlink(f, link_f) copy(d, d_copy, follow_symlinks=True) assert os.path.exists(d_copy) - assert not os.path.islink(new_link_f) + assert os.path.islink(new_link_f) @pytest.mark.skipif(sys.platform == 'win32', reason="does not run on windows") @@ -210,7 +236,7 @@ class Testcopy(): os.symlink(f, link_f) copy(d, d_copy, follow_symlinks=False) assert os.path.exists(d_copy) - assert os.path.islink(new_link_f) + assert not os.path.islink(new_link_f) @pytest.mark.skipif(sys.platform == 'win32', reason="does not run on windows")