aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/fs/test/test_fs.py
diff options
context:
space:
mode:
authorDmitry Kopylov <kopylovd@gmail.com>2022-02-10 16:48:18 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:18 +0300
commitb2f5101486cc0de2e979c8ba9ada2109785bf5fd (patch)
treeaffe28b840816b505db0467f2285b01c89c04247 /library/python/fs/test/test_fs.py
parente9b28b5aad71453a4637b70dde02e801e4147a2a (diff)
downloadydb-b2f5101486cc0de2e979c8ba9ada2109785bf5fd.tar.gz
Restoring authorship annotation for Dmitry Kopylov <kopylovd@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/python/fs/test/test_fs.py')
-rw-r--r--library/python/fs/test/test_fs.py350
1 files changed, 175 insertions, 175 deletions
diff --git a/library/python/fs/test/test_fs.py b/library/python/fs/test/test_fs.py
index 9e2c70c069..6bbd761c04 100644
--- a/library/python/fs/test/test_fs.py
+++ b/library/python/fs/test/test_fs.py
@@ -3,20 +3,20 @@
import errno
import os
import pytest
-import shutil
+import shutil
import six
-import library.python.fs
+import library.python.fs
import library.python.strings
-import library.python.tmp
+import library.python.tmp
import library.python.windows
-import yatest.common
-
+import yatest.common
+
def in_env(case):
def wrapped_case(*args, **kwargs):
- with library.python.tmp.temp_dir() as temp_dir:
+ with library.python.tmp.temp_dir() as temp_dir:
case(lambda path: os.path.join(temp_dir, path))
return wrapped_case
@@ -84,7 +84,7 @@ def gen_error_access_denied():
def test_errorfix_win():
- @library.python.fs.errorfix_win
+ @library.python.fs.errorfix_win
def erroneous_func():
gen_error_access_denied()
@@ -99,7 +99,7 @@ def test_errorfix_win():
def test_custom_fs_error():
with pytest.raises(OSError) as errinfo:
- raise library.python.fs.CustomFsError(errno.EACCES, filename='some/file')
+ raise library.python.fs.CustomFsError(errno.EACCES, filename='some/file')
assert errinfo.value.errno == errno.EACCES
# See transcode_error, which encodes strerror, in library/python/windows/__init__.py
assert isinstance(errinfo.value.strerror, (six.binary_type, six.text_type))
@@ -108,7 +108,7 @@ def test_custom_fs_error():
@in_env
def test_ensure_dir(path):
- library.python.fs.ensure_dir(path('dir/subdir'))
+ library.python.fs.ensure_dir(path('dir/subdir'))
assert os.path.isdir(path('dir'))
assert os.path.isdir(path('dir/subdir'))
@@ -116,7 +116,7 @@ def test_ensure_dir(path):
@in_env
def test_ensure_dir_exists(path):
os.makedirs(path('dir/subdir'))
- library.python.fs.ensure_dir(path('dir/subdir'))
+ library.python.fs.ensure_dir(path('dir/subdir'))
assert os.path.isdir(path('dir'))
assert os.path.isdir(path('dir/subdir'))
@@ -124,7 +124,7 @@ def test_ensure_dir_exists(path):
@in_env
def test_ensure_dir_exists_partly(path):
os.mkdir(path('dir'))
- library.python.fs.ensure_dir(path('dir/subdir'))
+ library.python.fs.ensure_dir(path('dir/subdir'))
assert os.path.isdir(path('dir'))
assert os.path.isdir(path('dir/subdir'))
@@ -133,7 +133,7 @@ def test_ensure_dir_exists_partly(path):
def test_ensure_dir_exists_file(path):
mkfile(path('dir'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.ensure_dir(path('dir/subdir'))
+ library.python.fs.ensure_dir(path('dir/subdir'))
# ENOENT on Windows!
assert errinfo.value.errno in (errno.ENOTDIR, errno.ENOENT)
assert os.path.isfile(path('dir'))
@@ -141,7 +141,7 @@ def test_ensure_dir_exists_file(path):
@in_env
def test_create_dirs(path):
- assert library.python.fs.create_dirs(path('dir/subdir')) == path('dir/subdir')
+ assert library.python.fs.create_dirs(path('dir/subdir')) == path('dir/subdir')
assert os.path.isdir(path('dir'))
assert os.path.isdir(path('dir/subdir'))
@@ -149,7 +149,7 @@ def test_create_dirs(path):
@in_env
def test_move_file(path):
mkfile(path('src'), 'SRC')
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert not os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'SRC'
@@ -158,7 +158,7 @@ def test_move_file(path):
@in_env
def test_move_file_no_src(path):
with pytest.raises(OSError) as errinfo:
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert errinfo.value.errno == errno.ENOENT
@@ -169,13 +169,13 @@ def test_move_file_exists(path):
if library.python.windows.on_win():
# move is platform-dependent, use replace_file for dst replacement on all platforms
with pytest.raises(OSError) as errinfo:
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert errinfo.value.errno == errno.EEXIST
assert os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'DST'
else:
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert not os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'SRC'
@@ -186,7 +186,7 @@ def test_move_file_exists_dir_empty(path):
mkfile(path('src'), 'SRC')
os.mkdir(path('dst'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert errinfo.value.errno in (errno.EEXIST, errno.EISDIR)
assert os.path.isfile(path('src'))
assert os.path.isdir(path('dst'))
@@ -199,7 +199,7 @@ def test_move_file_exists_dir_nonempty(path):
os.mkdir(path('dst'))
mkfile(path('dst/dst_file'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert errinfo.value.errno in (errno.EEXIST, errno.EISDIR)
assert os.path.isfile(path('src'))
assert os.path.isdir(path('dst'))
@@ -211,7 +211,7 @@ def test_move_file_exists_dir_nonempty(path):
def test_move_dir(path):
os.mkdir(path('src'))
mkfile(path('src/src_file'))
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert not os.path.isdir(path('src'))
assert os.path.isdir(path('dst'))
assert os.path.isfile(path('dst/src_file'))
@@ -225,13 +225,13 @@ def test_move_dir_exists_empty(path):
if library.python.windows.on_win():
# move is platform-dependent, use non-atomic replace for directory replacement
with pytest.raises(OSError) as errinfo:
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert errinfo.value.errno == errno.EEXIST
assert os.path.isdir(path('src'))
assert os.path.isdir(path('dst'))
assert not os.path.isfile(path('dst/src_file'))
else:
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert not os.path.isdir(path('src'))
assert os.path.isdir(path('dst'))
assert os.path.isfile(path('dst/src_file'))
@@ -244,7 +244,7 @@ def test_move_dir_exists_nonempty(path):
os.mkdir(path('dst'))
mkfile(path('dst/dst_file'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert errinfo.value.errno in (errno.EEXIST, errno.ENOTEMPTY)
assert os.path.isdir(path('src'))
assert os.path.isfile(path('src/src_file'))
@@ -259,7 +259,7 @@ def test_move_dir_exists_file(path):
mkfile(path('src/src_file'))
mkfile(path('dst'), 'DST')
with pytest.raises(OSError) as errinfo:
- library.python.fs.move(path('src'), path('dst'))
+ library.python.fs.move(path('src'), path('dst'))
assert errinfo.value.errno in (errno.EEXIST, errno.ENOTDIR)
assert os.path.isdir(path('src'))
assert os.path.isfile(path('dst'))
@@ -269,13 +269,13 @@ def test_move_dir_exists_file(path):
@in_env
def test_replace_file(path):
mkfile(path('src'), 'SRC')
- library.python.fs.replace_file(path('src'), path('dst'))
+ library.python.fs.replace_file(path('src'), path('dst'))
assert not os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'SRC'
mkfile(path('src'), 'SRC')
- library.python.fs.replace(path('src'), path('dst2'))
+ library.python.fs.replace(path('src'), path('dst2'))
assert not os.path.isfile(path('src'))
assert os.path.isfile(path('dst2'))
assert file_data(path('dst2')) == 'SRC'
@@ -284,11 +284,11 @@ def test_replace_file(path):
@in_env
def test_replace_file_no_src(path):
with pytest.raises(OSError) as errinfo:
- library.python.fs.replace_file(path('src'), path('dst'))
+ library.python.fs.replace_file(path('src'), path('dst'))
assert errinfo.value.errno == errno.ENOENT
with pytest.raises(OSError) as errinfo2:
- library.python.fs.replace(path('src'), path('dst2'))
+ library.python.fs.replace(path('src'), path('dst2'))
assert errinfo2.value.errno == errno.ENOENT
@@ -296,14 +296,14 @@ def test_replace_file_no_src(path):
def test_replace_file_exists(path):
mkfile(path('src'), 'SRC')
mkfile(path('dst'), 'DST')
- library.python.fs.replace_file(path('src'), path('dst'))
+ library.python.fs.replace_file(path('src'), path('dst'))
assert not os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'SRC'
mkfile(path('src'), 'SRC')
mkfile(path('dst2'), 'DST')
- library.python.fs.replace(path('src'), path('dst2'))
+ library.python.fs.replace(path('src'), path('dst2'))
assert not os.path.isfile(path('src'))
assert os.path.isfile(path('dst2'))
assert file_data(path('dst2')) == 'SRC'
@@ -314,7 +314,7 @@ def test_replace_file_exists_dir_empty(path):
mkfile(path('src'), 'SRC')
os.mkdir(path('dst'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.replace_file(path('src'), path('dst'))
+ library.python.fs.replace_file(path('src'), path('dst'))
assert errinfo.value.errno in (errno.EISDIR, errno.EACCES)
assert os.path.isfile(path('src'))
assert os.path.isdir(path('dst'))
@@ -325,7 +325,7 @@ def test_replace_file_exists_dir_empty(path):
def test_replace_file_exists_dir_empty_overwrite(path):
mkfile(path('src'), 'SRC')
os.mkdir(path('dst'))
- library.python.fs.replace(path('src'), path('dst'))
+ library.python.fs.replace(path('src'), path('dst'))
assert not os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'SRC'
@@ -337,20 +337,20 @@ def test_replace_file_exists_dir_nonempty(path):
os.mkdir(path('dst'))
mkfile(path('dst/dst_file'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.replace_file(path('src'), path('dst'))
+ library.python.fs.replace_file(path('src'), path('dst'))
assert errinfo.value.errno in (errno.EISDIR, errno.EACCES)
assert os.path.isfile(path('src'))
assert os.path.isdir(path('dst'))
assert os.path.isfile(path('dst/dst_file'))
assert not os.path.isfile(path('dst/src'))
-
-
+
+
@in_env
def test_replace_file_exists_dir_nonempty_overwrite(path):
mkfile(path('src'), 'SRC')
os.mkdir(path('dst'))
mkfile(path('dst/dst_file'))
- library.python.fs.replace(path('src'), path('dst'))
+ library.python.fs.replace(path('src'), path('dst'))
assert not os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'SRC'
@@ -360,7 +360,7 @@ def test_replace_file_exists_dir_nonempty_overwrite(path):
def test_replace_dir(path):
os.mkdir(path('src'))
mkfile(path('src/src_file'))
- library.python.fs.replace(path('src'), path('dst'))
+ library.python.fs.replace(path('src'), path('dst'))
assert not os.path.isdir(path('src'))
assert os.path.isdir(path('dst'))
assert os.path.isfile(path('dst/src_file'))
@@ -371,7 +371,7 @@ def test_replace_dir_exists_empty(path):
os.mkdir(path('src'))
mkfile(path('src/src_file'))
os.mkdir(path('dst'))
- library.python.fs.replace(path('src'), path('dst'))
+ library.python.fs.replace(path('src'), path('dst'))
assert not os.path.isdir(path('src'))
assert os.path.isdir(path('dst'))
assert os.path.isfile(path('dst/src_file'))
@@ -383,7 +383,7 @@ def test_replace_dir_exists_nonempty(path):
mkfile(path('src/src_file'))
os.mkdir(path('dst'))
mkfile(path('dst/dst_file'))
- library.python.fs.replace(path('src'), path('dst'))
+ library.python.fs.replace(path('src'), path('dst'))
assert not os.path.isdir(path('src'))
assert os.path.isdir(path('dst'))
assert os.path.isfile(path('dst/src_file'))
@@ -395,7 +395,7 @@ def test_replace_dir_exists_file(path):
os.mkdir(path('src'))
mkfile(path('src/src_file'))
mkfile(path('dst'), 'DST')
- library.python.fs.replace(path('src'), path('dst'))
+ library.python.fs.replace(path('src'), path('dst'))
assert not os.path.isdir(path('src'))
assert os.path.isdir(path('dst'))
assert os.path.isfile(path('dst/src_file'))
@@ -404,14 +404,14 @@ def test_replace_dir_exists_file(path):
@in_env
def test_remove_file(path):
mkfile(path('path'))
- library.python.fs.remove_file(path('path'))
+ library.python.fs.remove_file(path('path'))
assert not os.path.exists(path('path'))
@in_env
def test_remove_file_no(path):
with pytest.raises(OSError) as errinfo:
- library.python.fs.remove_file(path('path'))
+ library.python.fs.remove_file(path('path'))
assert errinfo.value.errno == errno.ENOENT
@@ -419,7 +419,7 @@ def test_remove_file_no(path):
def test_remove_file_exists_dir(path):
os.mkdir(path('path'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.remove_file(path('path'))
+ library.python.fs.remove_file(path('path'))
assert errinfo.value.errno in (errno.EISDIR, errno.EACCES)
assert os.path.isdir(path('path'))
@@ -427,14 +427,14 @@ def test_remove_file_exists_dir(path):
@in_env
def test_remove_dir(path):
os.mkdir(path('path'))
- library.python.fs.remove_dir(path('path'))
+ library.python.fs.remove_dir(path('path'))
assert not os.path.exists(path('path'))
@in_env
def test_remove_dir_no(path):
with pytest.raises(OSError) as errinfo:
- library.python.fs.remove_dir(path('path'))
+ library.python.fs.remove_dir(path('path'))
assert errinfo.value.errno == errno.ENOENT
@@ -442,7 +442,7 @@ def test_remove_dir_no(path):
def test_remove_dir_exists_file(path):
mkfile(path('path'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.remove_dir(path('path'))
+ library.python.fs.remove_dir(path('path'))
assert errinfo.value.errno in (errno.ENOTDIR, errno.EINVAL)
assert os.path.isfile(path('path'))
@@ -450,52 +450,52 @@ def test_remove_dir_exists_file(path):
@in_env
def test_remove_tree(path):
mktree_example(path, 'path')
- library.python.fs.remove_tree(path('path'))
+ library.python.fs.remove_tree(path('path'))
assert not os.path.exists(path('path'))
@in_env
def test_remove_tree_empty(path):
os.mkdir(path('path'))
- library.python.fs.remove_tree(path('path'))
+ library.python.fs.remove_tree(path('path'))
assert not os.path.exists(path('path'))
@in_env
def test_remove_tree_file(path):
mkfile(path('path'))
- library.python.fs.remove_tree(path('path'))
+ library.python.fs.remove_tree(path('path'))
assert not os.path.exists(path('path'))
@in_env
def test_remove_tree_no(path):
with pytest.raises(OSError) as errinfo:
- library.python.fs.remove_tree(path('path'))
+ library.python.fs.remove_tree(path('path'))
assert errinfo.value.errno == errno.ENOENT
@in_env
def test_remove_tree_safe(path):
- library.python.fs.remove_tree_safe(path('path'))
+ library.python.fs.remove_tree_safe(path('path'))
@in_env
def test_ensure_removed(path):
- library.python.fs.ensure_removed(path('path'))
+ library.python.fs.ensure_removed(path('path'))
@in_env
def test_ensure_removed_exists(path):
os.makedirs(path('dir/subdir'))
- library.python.fs.ensure_removed(path('dir'))
+ library.python.fs.ensure_removed(path('dir'))
assert not os.path.exists(path('dir'))
@in_env
def test_ensure_removed_exists_precise(path):
os.makedirs(path('dir/subdir'))
- library.python.fs.ensure_removed(path('dir/subdir'))
+ library.python.fs.ensure_removed(path('dir/subdir'))
assert os.path.exists(path('dir'))
assert not os.path.exists(path('dir/subdir'))
@@ -503,7 +503,7 @@ def test_ensure_removed_exists_precise(path):
@in_env
def test_hardlink_file(path):
mkfile(path('src'), 'SRC')
- library.python.fs.hardlink(path('src'), path('dst'))
+ library.python.fs.hardlink(path('src'), path('dst'))
assert os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'SRC'
@@ -513,7 +513,7 @@ def test_hardlink_file(path):
@in_env
def test_hardlink_file_no_src(path):
with pytest.raises(OSError) as errinfo:
- library.python.fs.hardlink(path('src'), path('dst'))
+ library.python.fs.hardlink(path('src'), path('dst'))
assert errinfo.value.errno == errno.ENOENT
@@ -522,7 +522,7 @@ def test_hardlink_file_exists(path):
mkfile(path('src'), 'SRC')
mkfile(path('dst'), 'DST')
with pytest.raises(OSError) as errinfo:
- library.python.fs.hardlink(path('src'), path('dst'))
+ library.python.fs.hardlink(path('src'), path('dst'))
assert errinfo.value.errno == errno.EEXIST
assert os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
@@ -535,7 +535,7 @@ def test_hardlink_file_exists_dir(path):
mkfile(path('src'), 'SRC')
os.mkdir(path('dst'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.hardlink(path('src'), path('dst'))
+ library.python.fs.hardlink(path('src'), path('dst'))
assert errinfo.value.errno == errno.EEXIST
assert os.path.isfile(path('src'))
assert os.path.isdir(path('dst'))
@@ -547,7 +547,7 @@ def test_hardlink_dir(path):
os.mkdir(path('src'))
mkfile(path('src/src_file'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.hardlink(path('src'), path('dst'))
+ library.python.fs.hardlink(path('src'), path('dst'))
assert errinfo.value.errno in (errno.EPERM, errno.EACCES)
assert os.path.isdir(path('src'))
assert not os.path.isdir(path('dst'))
@@ -557,7 +557,7 @@ def test_hardlink_dir(path):
@in_env
def test_symlink_file(path):
mkfile(path('src'), 'SRC')
- library.python.fs.symlink(path('src'), path('dst'))
+ library.python.fs.symlink(path('src'), path('dst'))
assert os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert os.path.islink(path('dst'))
@@ -567,7 +567,7 @@ def test_symlink_file(path):
@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows')
@in_env
def test_symlink_file_no_src(path):
- library.python.fs.symlink(path('src'), path('dst'))
+ library.python.fs.symlink(path('src'), path('dst'))
assert not os.path.isfile(path('src'))
assert not os.path.isfile(path('dst'))
assert os.path.islink(path('dst'))
@@ -579,7 +579,7 @@ def test_symlink_file_exists(path):
mkfile(path('src'), 'SRC')
mkfile(path('dst'), 'DST')
with pytest.raises(OSError) as errinfo:
- library.python.fs.symlink(path('src'), path('dst'))
+ library.python.fs.symlink(path('src'), path('dst'))
assert errinfo.value.errno == errno.EEXIST
assert os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
@@ -593,7 +593,7 @@ def test_symlink_file_exists_dir(path):
mkfile(path('src'), 'SRC')
os.mkdir(path('dst'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.symlink(path('src'), path('dst'))
+ library.python.fs.symlink(path('src'), path('dst'))
assert errinfo.value.errno == errno.EEXIST
assert os.path.isfile(path('src'))
assert os.path.isdir(path('dst'))
@@ -606,7 +606,7 @@ def test_symlink_file_exists_dir(path):
def test_symlink_dir(path):
os.mkdir(path('src'))
mkfile(path('src/src_file'))
- library.python.fs.symlink(path('src'), path('dst'))
+ library.python.fs.symlink(path('src'), path('dst'))
assert os.path.isdir(path('src'))
assert os.path.isdir(path('dst'))
assert os.path.islink(path('dst'))
@@ -616,7 +616,7 @@ def test_symlink_dir(path):
@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows')
@in_env
def test_symlink_dir_no_src(path):
- library.python.fs.symlink(path('src'), path('dst'))
+ library.python.fs.symlink(path('src'), path('dst'))
assert not os.path.isdir(path('src'))
assert not os.path.isdir(path('dst'))
assert os.path.islink(path('dst'))
@@ -629,7 +629,7 @@ def test_symlink_dir_exists(path):
mkfile(path('src/src_file'))
os.mkdir(path('dst'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.symlink(path('src'), path('dst'))
+ library.python.fs.symlink(path('src'), path('dst'))
assert errinfo.value.errno == errno.EEXIST
assert os.path.isdir(path('src'))
assert os.path.isdir(path('dst'))
@@ -644,7 +644,7 @@ def test_symlink_dir_exists_file(path):
mkfile(path('src/src_file'))
mkfile(path('dst'), 'DST')
with pytest.raises(OSError) as errinfo:
- library.python.fs.symlink(path('src'), path('dst'))
+ library.python.fs.symlink(path('src'), path('dst'))
assert errinfo.value.errno == errno.EEXIST
assert os.path.isdir(path('src'))
assert os.path.isfile(path('dst'))
@@ -654,28 +654,28 @@ def test_symlink_dir_exists_file(path):
@in_env
def test_hardlink_tree(path):
mktree_example(path, 'src')
- library.python.fs.hardlink_tree(path('src'), path('dst'))
+ library.python.fs.hardlink_tree(path('src'), path('dst'))
assert trees_equal(path('src'), path('dst'))
@in_env
def test_hardlink_tree_empty(path):
os.mkdir(path('src'))
- library.python.fs.hardlink_tree(path('src'), path('dst'))
+ library.python.fs.hardlink_tree(path('src'), path('dst'))
assert trees_equal(path('src'), path('dst'))
@in_env
def test_hardlink_tree_file(path):
mkfile(path('src'), 'SRC')
- library.python.fs.hardlink_tree(path('src'), path('dst'))
+ library.python.fs.hardlink_tree(path('src'), path('dst'))
assert trees_equal(path('src'), path('dst'))
@in_env
def test_hardlink_tree_no_src(path):
with pytest.raises(OSError) as errinfo:
- library.python.fs.hardlink_tree(path('src'), path('dst'))
+ library.python.fs.hardlink_tree(path('src'), path('dst'))
assert errinfo.value.errno == errno.ENOENT
@@ -684,11 +684,11 @@ def test_hardlink_tree_exists(path):
mktree_example(path, 'src')
os.mkdir(path('dst_dir'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.hardlink_tree(path('src'), path('dst_dir'))
+ library.python.fs.hardlink_tree(path('src'), path('dst_dir'))
assert errinfo.value.errno == errno.EEXIST
mkfile(path('dst_file'), 'DST')
with pytest.raises(OSError) as errinfo:
- library.python.fs.hardlink_tree(path('src'), path('dst_file'))
+ library.python.fs.hardlink_tree(path('src'), path('dst_file'))
assert errinfo.value.errno == errno.EEXIST
@@ -697,18 +697,18 @@ def test_hardlink_tree_file_exists(path):
mkfile(path('src'), 'SRC')
os.mkdir(path('dst_dir'))
with pytest.raises(OSError) as errinfo:
- library.python.fs.hardlink_tree(path('src'), path('dst_dir'))
+ library.python.fs.hardlink_tree(path('src'), path('dst_dir'))
assert errinfo.value.errno == errno.EEXIST
mkfile(path('dst_file'), 'DST')
with pytest.raises(OSError) as errinfo:
- library.python.fs.hardlink_tree(path('src'), path('dst_file'))
+ library.python.fs.hardlink_tree(path('src'), path('dst_file'))
assert errinfo.value.errno == errno.EEXIST
@in_env
def test_copy_file(path):
mkfile(path('src'), 'SRC')
- library.python.fs.copy_file(path('src'), path('dst'))
+ library.python.fs.copy_file(path('src'), path('dst'))
assert os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'SRC'
@@ -717,14 +717,14 @@ def test_copy_file(path):
@in_env
def test_copy_file_no_src(path):
with pytest.raises(EnvironmentError):
- library.python.fs.copy_file(path('src'), path('dst'))
+ library.python.fs.copy_file(path('src'), path('dst'))
@in_env
def test_copy_file_exists(path):
mkfile(path('src'), 'SRC')
mkfile(path('dst'), 'DST')
- library.python.fs.copy_file(path('src'), path('dst'))
+ library.python.fs.copy_file(path('src'), path('dst'))
assert os.path.isfile(path('src'))
assert os.path.isfile(path('dst'))
assert file_data(path('dst')) == 'SRC'
@@ -735,7 +735,7 @@ def test_copy_file_exists_dir_empty(path):
mkfile(path('src'), 'SRC')
os.mkdir(path('dst'))
with pytest.raises(EnvironmentError):
- library.python.fs.copy_file(path('src'), path('dst'))
+ library.python.fs.copy_file(path('src'), path('dst'))
assert os.path.isfile(path('src'))
assert os.path.isdir(path('dst'))
assert not os.path.isfile(path('dst/src'))
@@ -747,7 +747,7 @@ def test_copy_file_exists_dir_nonempty(path):
os.mkdir(path('dst'))
mkfile(path('dst/dst_file'))
with pytest.raises(EnvironmentError):
- library.python.fs.copy_file(path('src'), path('dst'))
+ library.python.fs.copy_file(path('src'), path('dst'))
assert os.path.isfile(path('src'))
assert os.path.isdir(path('dst'))
assert os.path.isfile(path('dst/dst_file'))
@@ -757,28 +757,28 @@ def test_copy_file_exists_dir_nonempty(path):
@in_env
def test_copy_tree(path):
mktree_example(path, 'src')
- library.python.fs.copy_tree(path('src'), path('dst'))
+ library.python.fs.copy_tree(path('src'), path('dst'))
assert trees_equal(path('src'), path('dst'))
@in_env
def test_copy_tree_empty(path):
os.mkdir(path('src'))
- library.python.fs.copy_tree(path('src'), path('dst'))
+ library.python.fs.copy_tree(path('src'), path('dst'))
assert trees_equal(path('src'), path('dst'))
@in_env
def test_copy_tree_file(path):
mkfile(path('src'), 'SRC')
- library.python.fs.copy_tree(path('src'), path('dst'))
+ library.python.fs.copy_tree(path('src'), path('dst'))
assert trees_equal(path('src'), path('dst'))
@in_env
def test_copy_tree_no_src(path):
with pytest.raises(EnvironmentError):
- library.python.fs.copy_tree(path('src'), path('dst'))
+ library.python.fs.copy_tree(path('src'), path('dst'))
@in_env
@@ -786,10 +786,10 @@ def test_copy_tree_exists(path):
mktree_example(path, 'src')
os.mkdir(path('dst_dir'))
with pytest.raises(EnvironmentError):
- library.python.fs.copy_tree(path('src'), path('dst_dir'))
+ library.python.fs.copy_tree(path('src'), path('dst_dir'))
mkfile(path('dst_file'), 'DST')
with pytest.raises(EnvironmentError):
- library.python.fs.copy_tree(path('src'), path('dst_file'))
+ library.python.fs.copy_tree(path('src'), path('dst_file'))
@in_env
@@ -797,9 +797,9 @@ def test_copy_tree_file_exists(path):
mkfile(path('src'), 'SRC')
os.mkdir(path('dst_dir'))
with pytest.raises(EnvironmentError):
- library.python.fs.copy_tree(path('src'), path('dst_dir'))
+ library.python.fs.copy_tree(path('src'), path('dst_dir'))
mkfile(path('dst_file'), 'DST')
- library.python.fs.copy_tree(path('src'), path('dst_file'))
+ library.python.fs.copy_tree(path('src'), path('dst_file'))
assert trees_equal(path('src'), path('dst_file'))
@@ -807,14 +807,14 @@ def test_copy_tree_file_exists(path):
def test_read_file(path):
mkfile(path('src'), 'SRC')
assert library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding()) == 'SRC'
- assert library.python.fs.read_file(path('src'), binary=False) == 'SRC'
+ assert library.python.fs.read_file(path('src'), binary=False) == 'SRC'
@in_env
def test_read_file_empty(path):
mkfile(path('src'))
assert library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding()) == ''
- assert library.python.fs.read_file(path('src'), binary=False) == ''
+ assert library.python.fs.read_file(path('src'), binary=False) == ''
@in_env
@@ -824,7 +824,7 @@ def test_read_file_multiline(path):
library.python.fs.read_file(path('src')).decode(library.python.strings.fs_encoding())
== 'SRC line 1\nSRC line 2\n'
)
- assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\nSRC line 2\n'
+ assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\nSRC line 2\n'
@in_env
@@ -835,9 +835,9 @@ def test_read_file_multiline_crlf(path):
== 'SRC line 1\r\nSRC line 2\r\n'
)
if library.python.windows.on_win() or six.PY3: # universal newlines are by default in text mode in python3
- assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\nSRC line 2\n'
+ assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\nSRC line 2\n'
else:
- assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\r\nSRC line 2\r\n'
+ assert library.python.fs.read_file(path('src'), binary=False) == 'SRC line 1\r\nSRC line 2\r\n'
@in_env
@@ -845,20 +845,20 @@ def test_read_file_unicode(path):
s = u'АБВ'
mkfile(path('src'), s.encode('utf-8'))
mkfile(path('src_cp1251'), s.encode('cp1251'))
- assert library.python.fs.read_file_unicode(path('src')) == s
- assert library.python.fs.read_file_unicode(path('src_cp1251'), enc='cp1251') == s
- assert library.python.fs.read_file_unicode(path('src'), binary=False) == s
- assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == s
+ assert library.python.fs.read_file_unicode(path('src')) == s
+ assert library.python.fs.read_file_unicode(path('src_cp1251'), enc='cp1251') == s
+ assert library.python.fs.read_file_unicode(path('src'), binary=False) == s
+ assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == s
@in_env
def test_read_file_unicode_empty(path):
mkfile(path('src'))
mkfile(path('src_cp1251'))
- assert library.python.fs.read_file_unicode(path('src')) == ''
- assert library.python.fs.read_file_unicode(path('src_cp1251'), enc='cp1251') == ''
- assert library.python.fs.read_file_unicode(path('src'), binary=False) == ''
- assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == ''
+ assert library.python.fs.read_file_unicode(path('src')) == ''
+ assert library.python.fs.read_file_unicode(path('src_cp1251'), enc='cp1251') == ''
+ assert library.python.fs.read_file_unicode(path('src'), binary=False) == ''
+ assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == ''
@in_env
@@ -866,10 +866,10 @@ def test_read_file_unicode_multiline(path):
s = u'АБВ\nИ еще\n'
mkfile(path('src'), s.encode('utf-8'))
mkfile(path('src_cp1251'), s.encode('cp1251'))
- assert library.python.fs.read_file_unicode(path('src')) == s
- assert library.python.fs.read_file_unicode(path('src_cp1251'), enc='cp1251') == s
- assert library.python.fs.read_file_unicode(path('src'), binary=False) == s
- assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == s
+ assert library.python.fs.read_file_unicode(path('src')) == s
+ assert library.python.fs.read_file_unicode(path('src_cp1251'), enc='cp1251') == s
+ assert library.python.fs.read_file_unicode(path('src'), binary=False) == s
+ assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == s
@in_env
@@ -877,37 +877,37 @@ def test_read_file_unicode_multiline_crlf(path):
s = u'АБВ\r\nИ еще\r\n'
mkfile(path('src'), s.encode('utf-8'))
mkfile(path('src_cp1251'), s.encode('cp1251'))
- assert library.python.fs.read_file_unicode(path('src')) == s
- assert library.python.fs.read_file_unicode(path('src_cp1251'), enc='cp1251') == s
+ assert library.python.fs.read_file_unicode(path('src')) == s
+ assert library.python.fs.read_file_unicode(path('src_cp1251'), enc='cp1251') == s
if library.python.windows.on_win() or six.PY3: # universal newlines are by default in text mode in python3
- assert library.python.fs.read_file_unicode(path('src'), binary=False) == u'АБВ\nИ еще\n'
- assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == u'АБВ\nИ еще\n'
+ assert library.python.fs.read_file_unicode(path('src'), binary=False) == u'АБВ\nИ еще\n'
+ assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == u'АБВ\nИ еще\n'
else:
- assert library.python.fs.read_file_unicode(path('src'), binary=False) == s
- assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == s
+ assert library.python.fs.read_file_unicode(path('src'), binary=False) == s
+ assert library.python.fs.read_file_unicode(path('src_cp1251'), binary=False, enc='cp1251') == s
@in_env
def test_write_file(path):
- library.python.fs.write_file(path('src'), 'SRC')
+ library.python.fs.write_file(path('src'), 'SRC')
assert file_data(path('src')) == 'SRC'
- library.python.fs.write_file(path('src2'), 'SRC', binary=False)
+ library.python.fs.write_file(path('src2'), 'SRC', binary=False)
assert file_data(path('src2')) == 'SRC'
@in_env
def test_write_file_empty(path):
- library.python.fs.write_file(path('src'), '')
+ library.python.fs.write_file(path('src'), '')
assert file_data(path('src')) == ''
- library.python.fs.write_file(path('src2'), '', binary=False)
+ library.python.fs.write_file(path('src2'), '', binary=False)
assert file_data(path('src2')) == ''
@in_env
def test_write_file_multiline(path):
- library.python.fs.write_file(path('src'), 'SRC line 1\nSRC line 2\n')
+ library.python.fs.write_file(path('src'), 'SRC line 1\nSRC line 2\n')
assert file_data(path('src')) == 'SRC line 1\nSRC line 2\n'
- library.python.fs.write_file(path('src2'), 'SRC line 1\nSRC line 2\n', binary=False)
+ library.python.fs.write_file(path('src2'), 'SRC line 1\nSRC line 2\n', binary=False)
if library.python.windows.on_win():
assert file_data(path('src2')) == 'SRC line 1\r\nSRC line 2\r\n'
else:
@@ -916,9 +916,9 @@ def test_write_file_multiline(path):
@in_env
def test_write_file_multiline_crlf(path):
- library.python.fs.write_file(path('src'), 'SRC line 1\r\nSRC line 2\r\n')
+ library.python.fs.write_file(path('src'), 'SRC line 1\r\nSRC line 2\r\n')
assert file_data(path('src')) == 'SRC line 1\r\nSRC line 2\r\n'
- library.python.fs.write_file(path('src2'), 'SRC line 1\r\nSRC line 2\r\n', binary=False)
+ library.python.fs.write_file(path('src2'), 'SRC line 1\r\nSRC line 2\r\n', binary=False)
if library.python.windows.on_win():
assert file_data(path('src2')) == 'SRC line 1\r\r\nSRC line 2\r\r\n'
else:
@@ -928,13 +928,13 @@ def test_write_file_multiline_crlf(path):
@in_env
def test_get_file_size(path):
mkfile(path('one.txt'), '22')
- assert library.python.fs.get_file_size(path('one.txt')) == 2
-
-
+ assert library.python.fs.get_file_size(path('one.txt')) == 2
+
+
@in_env
def test_get_file_size_empty(path):
mkfile(path('one.txt'))
- assert library.python.fs.get_file_size(path('one.txt')) == 0
+ assert library.python.fs.get_file_size(path('one.txt')) == 0
@in_env
@@ -942,9 +942,9 @@ def test_get_tree_size(path):
os.makedirs(path('deeper'))
mkfile(path('one.txt'), '1')
mkfile(path('deeper/two.txt'), '22')
- assert library.python.fs.get_tree_size(path('one.txt')) == 1
- assert library.python.fs.get_tree_size(path('')) == 1
- assert library.python.fs.get_tree_size(path(''), recursive=True) == 3
+ assert library.python.fs.get_tree_size(path('one.txt')) == 1
+ assert library.python.fs.get_tree_size(path('')) == 1
+ assert library.python.fs.get_tree_size(path(''), recursive=True) == 3
@pytest.mark.skipif(library.python.windows.on_win(), reason='Symlinks disabled on Windows')
@@ -956,61 +956,61 @@ def test_get_tree_size_dangling_symlink(path):
os.symlink(path('deeper/two.txt'), path("deeper/link.txt"))
os.remove(path('deeper/two.txt'))
# does not fail
- assert library.python.fs.get_tree_size(path(''), recursive=True) == 1
-
-
+ assert library.python.fs.get_tree_size(path(''), recursive=True) == 1
+
+
@pytest.mark.skipif(not library.python.windows.on_win(), reason='Test hardlinks on windows')
-def test_hardlink_or_copy():
- max_allowed_hard_links = 1023
-
- def run(hardlink_function, dir):
- src = r"test.txt"
- with open(src, "w") as f:
- f.write("test")
- for i in range(max_allowed_hard_links + 1):
- hardlink_function(src, os.path.join(dir, "{}.txt".format(i)))
-
- dir1 = library.python.fs.create_dirs("one")
- with pytest.raises(WindowsError) as e:
- run(library.python.fs.hardlink, dir1)
- assert e.value.winerror == 1142
- assert len(os.listdir(dir1)) == max_allowed_hard_links
-
- dir2 = library.python.fs.create_dirs("two")
- run(library.python.fs.hardlink_or_copy, dir2)
- assert len(os.listdir(dir2)) == max_allowed_hard_links + 1
-
-
-def test_remove_tree_unicode():
- path = u"test_remove_tree_unicode/русский".encode("utf-8")
- os.makedirs(path)
+def test_hardlink_or_copy():
+ max_allowed_hard_links = 1023
+
+ def run(hardlink_function, dir):
+ src = r"test.txt"
+ with open(src, "w") as f:
+ f.write("test")
+ for i in range(max_allowed_hard_links + 1):
+ hardlink_function(src, os.path.join(dir, "{}.txt".format(i)))
+
+ dir1 = library.python.fs.create_dirs("one")
+ with pytest.raises(WindowsError) as e:
+ run(library.python.fs.hardlink, dir1)
+ assert e.value.winerror == 1142
+ assert len(os.listdir(dir1)) == max_allowed_hard_links
+
+ dir2 = library.python.fs.create_dirs("two")
+ run(library.python.fs.hardlink_or_copy, dir2)
+ assert len(os.listdir(dir2)) == max_allowed_hard_links + 1
+
+
+def test_remove_tree_unicode():
+ path = u"test_remove_tree_unicode/русский".encode("utf-8")
+ os.makedirs(path)
library.python.fs.remove_tree(six.text_type("test_remove_tree_unicode"))
- assert not os.path.exists("test_remove_tree_unicode")
-
-
-def test_remove_tree_safe_unicode():
- path = u"test_remove_tree_safe_unicode/русский".encode("utf-8")
- os.makedirs(path)
+ assert not os.path.exists("test_remove_tree_unicode")
+
+
+def test_remove_tree_safe_unicode():
+ path = u"test_remove_tree_safe_unicode/русский".encode("utf-8")
+ os.makedirs(path)
library.python.fs.remove_tree_safe(six.text_type("test_remove_tree_safe_unicode"))
- assert not os.path.exists("test_remove_tree_safe_unicode")
-
-
-def test_copy_tree_custom_copy_function():
- library.python.fs.create_dirs("test_copy_tree_src/deepper/inner")
- library.python.fs.write_file("test_copy_tree_src/deepper/deepper.txt", "deepper.txt")
- library.python.fs.write_file("test_copy_tree_src/deepper/inner/inner.txt", "inner.txt")
- copied = []
-
- def copy_function(src, dst):
- shutil.copy2(src, dst)
- copied.append(dst)
-
+ assert not os.path.exists("test_remove_tree_safe_unicode")
+
+
+def test_copy_tree_custom_copy_function():
+ library.python.fs.create_dirs("test_copy_tree_src/deepper/inner")
+ library.python.fs.write_file("test_copy_tree_src/deepper/deepper.txt", "deepper.txt")
+ library.python.fs.write_file("test_copy_tree_src/deepper/inner/inner.txt", "inner.txt")
+ copied = []
+
+ def copy_function(src, dst):
+ shutil.copy2(src, dst)
+ copied.append(dst)
+
library.python.fs.copy_tree(
"test_copy_tree_src", yatest.common.work_path("test_copy_tree_dst"), copy_function=copy_function
)
- assert len(copied) == 2
- assert yatest.common.work_path("test_copy_tree_dst/deepper/deepper.txt") in copied
- assert yatest.common.work_path("test_copy_tree_dst/deepper/inner/inner.txt") in copied
+ assert len(copied) == 2
+ assert yatest.common.work_path("test_copy_tree_dst/deepper/deepper.txt") in copied
+ assert yatest.common.work_path("test_copy_tree_dst/deepper/inner/inner.txt") in copied
def test_copy2():