-
Notifications
You must be signed in to change notification settings - Fork 9
WIP common tests #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hroncok
wants to merge
1
commit into
fedora-python:master
Choose a base branch
from
hroncok:tests_common
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
WIP common tests #62
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import textwrap | ||
|
||
import pytest | ||
|
||
from utils import ( | ||
DOT_TOX, | ||
NATIVE_EXEC_PREFIX_MSG, | ||
NATIVE_EXECUTABLE, | ||
NATIVE_SITE_PACKAGES, | ||
NATIVE_TOXENV, | ||
TOX_VERSION, | ||
TOX4, | ||
envs_from_tox_ini, | ||
modify_config, | ||
expand_tox, | ||
prep_tox_output, | ||
tox, | ||
tox_footer, | ||
) | ||
|
||
|
||
def test_native_toxenv_current_env(): | ||
result = tox("-e", NATIVE_TOXENV, "--current-env") | ||
assert result.stdout.splitlines()[0] == NATIVE_EXEC_PREFIX_MSG | ||
assert not (DOT_TOX / NATIVE_TOXENV / "lib").is_dir() | ||
|
||
|
||
@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) | ||
def test_print_deps(toxenv, print_deps_stdout_arg): | ||
result = tox("-e", toxenv, print_deps_stdout_arg) | ||
expected = expand_tox(textwrap.dedent( | ||
f""" | ||
[[TOX4:tox]] | ||
six | ||
py | ||
{tox_footer(toxenv)} | ||
""" | ||
).lstrip()) | ||
assert prep_tox_output(result.stdout) == expected | ||
|
||
|
||
@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) | ||
@pytest.mark.parametrize("pre_post", ["pre", "post", "both"]) | ||
def test_print_deps_with_commands_pre_post(projdir, toxenv, pre_post, print_deps_stdout_arg): | ||
with modify_config(projdir / 'tox.ini') as config: | ||
if pre_post == "both": | ||
config["testenv"]["commands_pre"] = "echo unexpected" | ||
config["testenv"]["commands_post"] = "echo unexpected" | ||
else: | ||
config["testenv"][f"commands_{pre_post}"] = "echo unexpected" | ||
result = tox("-e", toxenv, print_deps_stdout_arg) | ||
expected = expand_tox(textwrap.dedent( | ||
f""" | ||
[[TOX4:tox]] | ||
six | ||
py | ||
{tox_footer(toxenv)} | ||
""" | ||
).lstrip()) | ||
assert sorted(prep_tox_output(result.stdout).splitlines()) == sorted( | ||
expected.splitlines() | ||
) | ||
assert result.stderr == "" | ||
|
||
|
||
@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) | ||
def test_print_deps_with_tox_minversion(projdir, toxenv, print_deps_stdout_arg): | ||
with modify_config(projdir / "tox.ini") as config: | ||
config["tox"]["minversion"] = "3.13" | ||
result = tox("-e", toxenv, print_deps_stdout_arg) | ||
expected = textwrap.dedent( | ||
f""" | ||
tox>=3.13 | ||
six | ||
py | ||
{tox_footer(toxenv)} | ||
""" | ||
).lstrip() | ||
assert prep_tox_output(result.stdout) == expected | ||
|
||
|
||
@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) | ||
def test_print_deps_with_tox_requires(projdir, toxenv, print_deps_stdout_arg): | ||
with modify_config(projdir / "tox.ini") as config: | ||
config["tox"]["requires"] = "\n setuptools > 30\n pluggy" | ||
result = tox("-e", toxenv, print_deps_stdout_arg) | ||
expected = expand_tox(textwrap.dedent( | ||
f""" | ||
setuptools>30 | ||
pluggy | ||
[[TOX4:tox]] | ||
six | ||
py | ||
{tox_footer(toxenv)} | ||
""" | ||
).lstrip()) | ||
assert prep_tox_output(result.stdout) == expected | ||
|
||
|
||
@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) | ||
def test_print_deps_with_tox_minversion_and_requires( | ||
projdir, toxenv, print_deps_stdout_arg | ||
): | ||
with modify_config(projdir / "tox.ini") as config: | ||
config["tox"]["minversion"] = "3.13" | ||
config["tox"]["requires"] = "\n setuptools > 30\n pluggy" | ||
result = tox("-e", toxenv, print_deps_stdout_arg) | ||
expected = expand_tox(textwrap.dedent( | ||
f""" | ||
[[TOX3:tox>=3.13]] | ||
setuptools>30 | ||
pluggy | ||
[[TOX4:tox>=3.13]] | ||
six | ||
py | ||
{tox_footer(toxenv)} | ||
""" | ||
).lstrip()) | ||
assert prep_tox_output(result.stdout) == expected |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,10 +117,36 @@ def tox_footer(envs=None, spaces=8): | |
|
||
|
||
def prep_tox_output(output): | ||
"""Remove time info from tox output""" | ||
result = re.sub(r" \((\d+\.\d+|\d+) seconds\)", "", output) | ||
result = re.sub(r" ✔ in (\d+\.\d+|\d+) seconds", "", result) | ||
return result | ||
"""Remove time info from tox 4 output. | ||
Strip spaces around operators in tox 3 output.""" | ||
if TOX4: | ||
output = re.sub(r" \((\d+\.\d+|\d+) seconds\)", "", output) | ||
output = re.sub(r" ✔ in (\d+\.\d+|\d+) seconds", "", output) | ||
else: | ||
output = re.sub(" ((<|>)=?) ", r"\1", output) | ||
return output | ||
|
||
|
||
def expand_tox(text): | ||
"""Replace [[TOX4:...]] and [[TOX3:...]] expressions, | ||
empty liens are stripped if created.""" | ||
source_lines = text.splitlines() | ||
out_lines = [] | ||
for line in source_lines: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only this loop is kinda cryptic. I'd add comments saying that the first if not line is there to preserve empty lines in the original output and the second if line is there to avoid adding more empty lines if one of the inline expressions creates one. |
||
if not line: | ||
out_lines.append(line) | ||
continue | ||
if TOX4: | ||
line = re.sub(r"\[\[TOX3:[^\]]*\]\]", "", line) | ||
line = re.sub(r"\[\[TOX4:([^\]]*)\]\]", r"\1", line) | ||
else: | ||
line = re.sub(r"\[\[TOX4:[^\]]*\]\]", "", line) | ||
line = re.sub(r"\[\[TOX3:([^\]]*)\]\]", r"\1", line) | ||
if line: | ||
out_lines.append(line) | ||
if text[-1] == "\n": | ||
out_lines.append("") | ||
return "\n".join(out_lines) | ||
|
||
|
||
needs_all_pythons = pytest.mark.skipif( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.