From 66edd67a9db508b88cf34678df3d40b4b7923ba6 Mon Sep 17 00:00:00 2001 From: Wang <120731947+WangGithubUser@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:48:04 +0800 Subject: [PATCH] Improve unittest --- .../configuration/tests/search_path_test.py | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/client/configuration/tests/search_path_test.py b/client/configuration/tests/search_path_test.py index bf3790e7e8b..3104721c7d9 100644 --- a/client/configuration/tests/search_path_test.py +++ b/client/configuration/tests/search_path_test.py @@ -3,6 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. +import shutil import tempfile from pathlib import Path @@ -85,17 +86,20 @@ def test_command_line_argument(self) -> None: "foo$bar", ) - Path.mkdir(Path("foo"), exist_ok=True) - Path.mkdir(Path("foo/bar-1.0.0.dist-info"), exist_ok=True) - Path.touch(Path("foo/bar.py"), exist_ok=True) + Path.mkdir(Path("foo")) + Path.mkdir(Path("foo/bar-1.0.0.dist-info")) + Path.touch(Path("foo/bar.py")) with open("foo/bar-1.0.0.dist-info/RECORD", "w", encoding="UTF-8") as f: f.write("bar.py") - self.assertEqual( - SitePackageElement("foo", "bar", True).command_line_argument(), - "foo$bar.py", - ) + try: + self.assertEqual( + SitePackageElement("foo", "bar", True).command_line_argument(), + "foo$bar.py", + ) + finally: + shutil.rmtree("foo") def test_expand_global_root(self) -> None: self.assertEqual( @@ -251,11 +255,16 @@ def test_process_required_raw_elements_site_package_nonexistence(self) -> None: ) def test_toplevel_module_not_pyfile(self) -> None: - Path.mkdir(Path("foo"), exist_ok=True) - Path.mkdir(Path("foo/bar-1.0.0.dist-info"), exist_ok=True) - Path.touch(Path("foo/bar.so"), exist_ok=True) + Path.mkdir(Path("foo")) + Path.mkdir(Path("foo/bar-1.0.0.dist-info")) + Path.touch(Path("foo/bar.so")) with open("foo/bar-1.0.0.dist-info/RECORD", "w", encoding="UTF-8") as f: f.write("bar.so") - self.assertEqual(SitePackageElement("foo", "bar", True).path(), "foo/bar.so") + try: + self.assertEqual( + SitePackageElement("foo", "bar", True).path(), "foo/bar.so" + ) + finally: + shutil.rmtree("foo")