Skip to content

Commit

Permalink
fix test too fast
Browse files Browse the repository at this point in the history
  • Loading branch information
lidong committed Jun 4, 2024
1 parent 280e4a7 commit 726e2ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 14 additions & 7 deletions test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,29 +720,36 @@ def test_pip_install_target():
_clean_paths()
# test without "insert sys.path"
start_time = time.time()
pip_install_target(Path("./mock_dir"), ["six"], force=False, sys_path=None)
assert time.time() - start_time > 2
assert pip_install_target(
"./mock_dir", ["six", "--no-cache-dir"], force=False, sys_path=None
)
assert time.time() - start_time > 0.5
sys.modules.pop("six", None)
import six

assert "mock_dir" not in six.__file__
# hit md5 cache, force=False, sys_path ignored
start_time = time.time()
pip_install_target(Path("./mock_dir"), ["six"], force=False, sys_path=0)
assert time.time() - start_time < 2
assert not pip_install_target(
"./mock_dir", ["six", "--no-cache-dir"], force=False, sys_path=0
)
assert time.time() - start_time < 0.5
sys.modules.pop("six", None)
import six

assert "mock_dir" not in six.__file__
# test force=True, sys_path=0 worked
start_time = time.time()
pip_install_target(Path("./mock_dir"), ["six"], force=True, sys_path=0)
assert time.time() - start_time > 2
assert pip_install_target(
"./mock_dir", ["six", "--no-cache-dir"], force=True, sys_path=0
)
assert time.time() - start_time > 0.5
sys.modules.pop("six", None)
import six

assert "mock_dir" in six.__file__


def main():
"""
test all cases
Expand All @@ -752,7 +759,7 @@ def main():
count = 0
items = list(globals().items())
total = len(items)
name_list = {}
name_list = ''
for name, func in items:
if name_list and name not in name_list:
continue
Expand Down
4 changes: 2 additions & 2 deletions zipapps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,14 @@ def pip_install_target(
target = Path(target)
md5_path = target / ZipApp.get_md5(pip_args)
if not force and md5_path.exists():
return
return False
ZipApp._pip_install(target_dir=target, pip_args=pip_args)
if rm_patterns:
ZipApp._rm_with_patterns(target, patterns=rm_patterns.split(","))

md5_path.touch()
if isinstance(sys_path, int):
sys.path.insert(sys_path, target.absolute().as_posix())

return True

create_app = ZipApp.create_app

0 comments on commit 726e2ec

Please sign in to comment.