Skip to content

Commit

Permalink
Refactor parameters of test_pkg_imported to use the actual values in …
Browse files Browse the repository at this point in the history
…the parameters instead of boolean proxies. Use itertools.product to cover all cases. Explicitly skip the one unsupported case
  • Loading branch information
jaraco committed Sep 8, 2023
1 parent 562dc69 commit 008648d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
import textwrap
import sys
import subprocess
Expand All @@ -15,24 +16,20 @@ def DALS(str):

@pytest.mark.network
@pytest.mark.parametrize(
"has_shebang, has_py_extension, use_dash",
[
(True, True, True),
(True, True, False),
(True, False, False),
(False, True, False),
],
'shebang, extension, dash',
itertools.product(('', '#!/usr/bin/env python'), ('', '.py'), ([], ['--'])),
)
def test_pkg_imported(tmp_path, has_shebang, has_py_extension, use_dash):
def test_pkg_imported(tmp_path, shebang, extension, dash):
"""
Create a script that loads a package and ensure it runs.
"""
scriptname = 'script.py' if has_py_extension else 'script'
shebang or extension or dash or pytest.skip('Unable to infer script')
scriptname = 'script' + extension
jaraco.path.build(
{
scriptname: DALS(
f"""
{"#!/usr/bin/env python" if has_shebang else ""}
{shebang}
import sample
print("Import succeeded")
"""
Expand All @@ -42,10 +39,7 @@ def test_pkg_imported(tmp_path, has_shebang, has_py_extension, use_dash):
)
script = tmp_path / scriptname
pip_args = ['sampleproject']
if use_dash:
script_args = ['--', str(script)]
else:
script_args = [str(script)]
script_args = dash + [str(script)]
cmd = [sys.executable, '-m', 'pip-run'] + pip_args + script_args

out = subprocess.check_output(cmd, text=True, encoding='utf-8')
Expand Down

0 comments on commit 008648d

Please sign in to comment.