Skip to content

Commit

Permalink
Improve unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
WangGithubUser committed Aug 22, 2023
1 parent e39ee51 commit 66edd67
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions client/configuration/tests/search_path_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")

0 comments on commit 66edd67

Please sign in to comment.