Skip to content

Commit 6b537ab

Browse files
committed
Add unlink_files method tests to TestCmdTests.py.
1 parent 6827a03 commit 6b537ab

File tree

3 files changed

+103
-6
lines changed

3 files changed

+103
-6
lines changed

CHANGES.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
3636
build. The tests were modified to delete the test executable, object file,
3737
and sconsign file prior to the command-line invocation of the VS development
3838
binary.
39-
- A method, unlink_files, was added to the TestCmd class that unlinks a list of
40-
files from a specified directory. An attempt to unlink a file is made only when
41-
the file exists, otherwise, the file is ignored.
39+
- Method unlink_files was added to the TestCmd class that unlinks a list of
40+
files from a specified directory. An attempt to unlink a file is made only
41+
when the file exists; otherwise, the file is ignored.
4242

4343
From Michał Górny:
4444
- Remove unecessary dependencies on pypi packages from setup.cfg

RELEASE.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Here is a summary of the changes since 4.6.0:
1616
NEW FUNCTIONALITY
1717
-----------------
1818

19-
- A method, unlink_files, was added to the TestCmd class that unlinks a list of
20-
files from a specified directory. An attempt to unlink a file is made only when
21-
the file exists, otherwise, the file is ignored.
19+
- Method unlink_files was added to the TestCmd class that unlinks a list of files
20+
from a specified directory. An attempt to unlink a file is made only when the
21+
file exists; otherwise, the file is ignored.
2222

2323

2424
DEPRECATED FUNCTIONALITY

testing/framework/TestCmdTests.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,103 @@ def test_unlink(self):
29932993
os.chmod(wdir_file5, 0o600)
29942994

29952995

2996+
class unlink_files_TestCase(TestCmdTestCase):
2997+
def test_unlink_files(self):
2998+
"""Test unlink_files()"""
2999+
test = TestCmd.TestCmd(workdir = '', subdir = 'foo')
3000+
wdir_file1 = os.path.join(test.workdir, 'file1')
3001+
wdir_file2 = os.path.join(test.workdir, 'file2')
3002+
wdir_foo_file3a = os.path.join(test.workdir, 'foo', 'file3a')
3003+
wdir_foo_file3b = os.path.join(test.workdir, 'foo', 'file3b')
3004+
wdir_foo_file3c = os.path.join(test.workdir, 'foo', 'file3c')
3005+
wdir_foo_file3d = os.path.join(test.workdir, 'foo', 'file3d')
3006+
wdir_foo_file4a = os.path.join(test.workdir, 'foo', 'file4a')
3007+
wdir_foo_file4b = os.path.join(test.workdir, 'foo', 'file4b')
3008+
wdir_foo_file4c = os.path.join(test.workdir, 'foo', 'file4c')
3009+
wdir_foo_file4d = os.path.join(test.workdir, 'foo', 'file4d')
3010+
wdir_file5 = os.path.join(test.workdir, 'file5')
3011+
3012+
with open(wdir_file1, 'w') as f:
3013+
f.write("")
3014+
with open(wdir_file2, 'w') as f:
3015+
f.write("")
3016+
with open(wdir_foo_file3a, 'w') as f:
3017+
f.write("")
3018+
with open(wdir_foo_file3b, 'w') as f:
3019+
f.write("")
3020+
with open(wdir_foo_file3c, 'w') as f:
3021+
f.write("")
3022+
with open(wdir_foo_file3d, 'w') as f:
3023+
f.write("")
3024+
with open(wdir_foo_file4a, 'w') as f:
3025+
f.write("")
3026+
with open(wdir_foo_file4b, 'w') as f:
3027+
f.write("")
3028+
with open(wdir_foo_file4c, 'w') as f:
3029+
f.write("")
3030+
with open(wdir_foo_file4d, 'w') as f:
3031+
f.write("")
3032+
with open(wdir_file5, 'w') as f:
3033+
f.write("")
3034+
3035+
test.unlink_files('', [
3036+
'no_file_a',
3037+
'no_file_b',
3038+
])
3039+
3040+
test.unlink_files('', [
3041+
'file1',
3042+
'file2',
3043+
])
3044+
assert not os.path.exists(wdir_file1)
3045+
assert not os.path.exists(wdir_file2)
3046+
3047+
test.unlink_files('foo', [
3048+
'file3a',
3049+
'file3b',
3050+
])
3051+
assert not os.path.exists(wdir_foo_file3a)
3052+
assert not os.path.exists(wdir_foo_file3b)
3053+
3054+
test.unlink_files(['foo'], [
3055+
'file3c',
3056+
'file3d',
3057+
])
3058+
assert not os.path.exists(wdir_foo_file3c)
3059+
assert not os.path.exists(wdir_foo_file3d)
3060+
3061+
test.unlink_files('', [
3062+
['foo', 'file4a'],
3063+
['foo', 'file4b'],
3064+
])
3065+
assert not os.path.exists(wdir_foo_file4a)
3066+
assert not os.path.exists(wdir_foo_file4b)
3067+
3068+
test.unlink_files([''], [
3069+
['foo', 'file4c'],
3070+
['foo', 'file4d'],
3071+
])
3072+
assert not os.path.exists(wdir_foo_file4c)
3073+
assert not os.path.exists(wdir_foo_file4d)
3074+
3075+
# Make it so we can't unlink file5.
3076+
# For UNIX, remove write permission from the dir and the file.
3077+
# For Windows, open the file.
3078+
os.chmod(test.workdir, 0o500)
3079+
os.chmod(wdir_file5, 0o400)
3080+
with open(wdir_file5, 'r'):
3081+
try:
3082+
try:
3083+
test.unlink_files('', ['file5'])
3084+
except OSError: # expect "Permission denied"
3085+
pass
3086+
except:
3087+
raise
3088+
finally:
3089+
os.chmod(test.workdir, 0o700)
3090+
os.chmod(wdir_file5, 0o600)
3091+
3092+
29963093
class touch_TestCase(TestCmdTestCase):
29973094
def test_touch(self) -> None:
29983095
"""Test touch()"""

0 commit comments

Comments
 (0)