diff options
author | Joseph Brill <48932340+jcbrill@users.noreply.github.com> | 2024-01-07 14:42:04 (GMT) |
---|---|---|
committer | Joseph Brill <48932340+jcbrill@users.noreply.github.com> | 2024-01-07 14:42:04 (GMT) |
commit | d06ad9e5bd309ba75163e3c06df539f7378d2363 (patch) | |
tree | 59b1437d9fcf8d45af5aeeedff5814c58b4101bc /testing | |
parent | ed18bdf70a2f8ff20f4debcc202684d7d4e737a4 (diff) | |
download | SCons-d06ad9e5bd309ba75163e3c06df539f7378d2363.zip SCons-d06ad9e5bd309ba75163e3c06df539f7378d2363.tar.gz SCons-d06ad9e5bd309ba75163e3c06df539f7378d2363.tar.bz2 |
Merge branch 'master' into HEAD
Manually resolve conflicts:
* CHANGES.txt
* RELEASE.txt
* SCons/Tool/MSCommon/vc.py
Diffstat (limited to 'testing')
-rw-r--r-- | testing/framework/TestCmd.py | 27 | ||||
-rw-r--r-- | testing/framework/TestCmdTests.py | 110 | ||||
-rw-r--r-- | testing/framework/TestSCons.py | 2 | ||||
-rw-r--r-- | testing/framework/TestUnit/taprunner.py | 2 |
4 files changed, 131 insertions, 10 deletions
diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index 48238a0..98094c8 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -802,7 +802,7 @@ else: # From Josiah Carlson, # ASPN : Python Cookbook : Module to allow Asynchronous subprocess use on Windows and Posix platforms -# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554 +# https://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554 if sys.platform == 'win32': # and subprocess.mswindows: try: @@ -1872,6 +1872,31 @@ class TestCmd: file = self.canonicalize(file) os.unlink(file) + def unlink_files(self, dirpath, files): + """Unlinks a list of file names from the specified directory. + + The directory path may be a list, in which case the elements are + concatenated with the os.path.join() method. + + A file name may be a list, in which case the elements are + concatenated with the os.path.join() method. + + The directory path and file name are concatenated with the + os.path.join() method. The resulting file path is assumed to be + under the temporary working directory unless it is an absolute path + name. An attempt to unlink the resulting file is made only when the + file exists otherwise the file path is ignored. + """ + if is_List(dirpath): + dirpath = os.path.join(*dirpath) + for file in files: + if is_List(file): + file = os.path.join(*file) + filepath = os.path.join(dirpath, file) + filepath = self.canonicalize(filepath) + if os.path.exists(filepath): + self.unlink(filepath) + def verbose_set(self, verbose) -> None: """Sets the verbose level.""" self.verbose = verbose diff --git a/testing/framework/TestCmdTests.py b/testing/framework/TestCmdTests.py index dc752ba..1331f9d 100644 --- a/testing/framework/TestCmdTests.py +++ b/testing/framework/TestCmdTests.py @@ -1601,10 +1601,10 @@ class rmdir_TestCase(TestCmdTestCase): try: test.rmdir(['no', 'such', 'dir']) - except EnvironmentError: + except FileNotFoundError: pass else: - raise Exception("did not catch expected SConsEnvironmentError") + raise Exception("did not catch expected FileNotFoundError") test.subdir(['sub'], ['sub', 'dir'], @@ -1616,19 +1616,19 @@ class rmdir_TestCase(TestCmdTestCase): try: test.rmdir(['sub']) - except EnvironmentError: + except OSError: pass else: - raise Exception("did not catch expected SConsEnvironmentError") + raise Exception("did not catch expected OSError") assert os.path.isdir(s_d_o), f"{s_d_o} is gone?" try: test.rmdir(['sub']) - except EnvironmentError: + except OSError: pass else: - raise Exception("did not catch expected SConsEnvironmentError") + raise Exception("did not catch expected OSError") assert os.path.isdir(s_d_o), f"{s_d_o} is gone?" @@ -1647,7 +1647,6 @@ class rmdir_TestCase(TestCmdTestCase): assert not os.path.exists(s), f"{s} exists?" - class run_TestCase(TestCmdTestCase): def test_run(self) -> None: """Test run()""" @@ -2994,6 +2993,103 @@ class unlink_TestCase(TestCmdTestCase): os.chmod(wdir_file5, 0o600) +class unlink_files_TestCase(TestCmdTestCase): + def test_unlink_files(self): + """Test unlink_files()""" + test = TestCmd.TestCmd(workdir = '', subdir = 'foo') + wdir_file1 = os.path.join(test.workdir, 'file1') + wdir_file2 = os.path.join(test.workdir, 'file2') + wdir_foo_file3a = os.path.join(test.workdir, 'foo', 'file3a') + wdir_foo_file3b = os.path.join(test.workdir, 'foo', 'file3b') + wdir_foo_file3c = os.path.join(test.workdir, 'foo', 'file3c') + wdir_foo_file3d = os.path.join(test.workdir, 'foo', 'file3d') + wdir_foo_file4a = os.path.join(test.workdir, 'foo', 'file4a') + wdir_foo_file4b = os.path.join(test.workdir, 'foo', 'file4b') + wdir_foo_file4c = os.path.join(test.workdir, 'foo', 'file4c') + wdir_foo_file4d = os.path.join(test.workdir, 'foo', 'file4d') + wdir_file5 = os.path.join(test.workdir, 'file5') + + with open(wdir_file1, 'w') as f: + f.write("") + with open(wdir_file2, 'w') as f: + f.write("") + with open(wdir_foo_file3a, 'w') as f: + f.write("") + with open(wdir_foo_file3b, 'w') as f: + f.write("") + with open(wdir_foo_file3c, 'w') as f: + f.write("") + with open(wdir_foo_file3d, 'w') as f: + f.write("") + with open(wdir_foo_file4a, 'w') as f: + f.write("") + with open(wdir_foo_file4b, 'w') as f: + f.write("") + with open(wdir_foo_file4c, 'w') as f: + f.write("") + with open(wdir_foo_file4d, 'w') as f: + f.write("") + with open(wdir_file5, 'w') as f: + f.write("") + + test.unlink_files('', [ + 'no_file_a', + 'no_file_b', + ]) + + test.unlink_files('', [ + 'file1', + 'file2', + ]) + assert not os.path.exists(wdir_file1) + assert not os.path.exists(wdir_file2) + + test.unlink_files('foo', [ + 'file3a', + 'file3b', + ]) + assert not os.path.exists(wdir_foo_file3a) + assert not os.path.exists(wdir_foo_file3b) + + test.unlink_files(['foo'], [ + 'file3c', + 'file3d', + ]) + assert not os.path.exists(wdir_foo_file3c) + assert not os.path.exists(wdir_foo_file3d) + + test.unlink_files('', [ + ['foo', 'file4a'], + ['foo', 'file4b'], + ]) + assert not os.path.exists(wdir_foo_file4a) + assert not os.path.exists(wdir_foo_file4b) + + test.unlink_files([''], [ + ['foo', 'file4c'], + ['foo', 'file4d'], + ]) + assert not os.path.exists(wdir_foo_file4c) + assert not os.path.exists(wdir_foo_file4d) + + # Make it so we can't unlink file5. + # For UNIX, remove write permission from the dir and the file. + # For Windows, open the file. + os.chmod(test.workdir, 0o500) + os.chmod(wdir_file5, 0o400) + with open(wdir_file5, 'r'): + try: + try: + test.unlink_files('', ['file5']) + except OSError: # expect "Permission denied" + pass + except: + raise + finally: + os.chmod(test.workdir, 0o700) + os.chmod(wdir_file5, 0o600) + + class touch_TestCase(TestCmdTestCase): def test_touch(self) -> None: """Test touch()""" diff --git a/testing/framework/TestSCons.py b/testing/framework/TestSCons.py index 39a4245..b6e3490 100644 --- a/testing/framework/TestSCons.py +++ b/testing/framework/TestSCons.py @@ -55,7 +55,7 @@ from TestCmd import PIPE # here provides some independent verification that what we packaged # conforms to what we expect. -default_version = '4.5.3ayyyymmdd' +default_version = '4.7.0ayyyymmdd' # TODO: these need to be hand-edited when there are changes python_version_unsupported = (3, 6, 0) diff --git a/testing/framework/TestUnit/taprunner.py b/testing/framework/TestUnit/taprunner.py index 6f8cb00..b52c762 100644 --- a/testing/framework/TestUnit/taprunner.py +++ b/testing/framework/TestUnit/taprunner.py @@ -1,6 +1,6 @@ """ Format unittest results in Test Anything Protocol (TAP). -http://testanything.org/tap-version-13-specification.html +https://testanything.org/tap-version-13-specification.html Public domain work by: anatoly techtonik <techtonik@gmail.com> |