-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Tox dotted env #39
base: master
Are you sure you want to change the base?
Tox dotted env #39
Changes from all commits
5a65ac4
fd6a29c
9654bde
7a6c81d
877b77c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,9 +43,10 @@ class Version(NamedTuple): | |
major: int = -1 # I'd've preferred to use None, but it complicates sorting | ||
minor: int = -1 | ||
suffix: str = '' | ||
has_dot: bool = False | ||
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. This doesn't belong here. It has nothing to do with what a Version represents. |
||
|
||
@classmethod | ||
def from_string(cls, v: str) -> 'Version': | ||
def from_string(cls, v: str, has_dot: bool = False) -> 'Version': | ||
m = VERSION_RX.match(v) | ||
assert m is not None | ||
prefix, major, minor, suffix = m.groups() | ||
|
@@ -54,6 +55,7 @@ def from_string(cls, v: str) -> 'Version': | |
int(major) if major else -1, | ||
int(minor[1:]) if minor else -1, | ||
suffix, | ||
has_dot, | ||
) | ||
|
||
def __repr__(self) -> str: | ||
|
@@ -62,6 +64,7 @@ def __repr__(self) -> str: | |
f'major={self.major!r}' if self.major != -1 else '', | ||
f'minor={self.minor!r}' if self.minor != -1 else '', | ||
f'suffix={self.suffix!r}' if self.suffix else '', | ||
f'dot={self.has_dot!r}' if self.has_dot else '', | ||
] if part)) | ||
|
||
def __str__(self) -> str: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,11 @@ | |
from check_python_versions.versions import Version | ||
|
||
|
||
def v(versions: List[str]) -> List[Version]: | ||
return [Version.from_string(v) for v in versions] | ||
def v(versions: List[str], has_dot: List[bool] = []) -> List[Version]: | ||
if not has_dot: | ||
has_dot = [False] * len(versions) | ||
return [Version.from_string(v, has_dot=d) | ||
for v, d in zip(versions, has_dot)] | ||
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. Why is this needed? Is |
||
|
||
|
||
def test_get_tox_ini_python_versions(tmp_path): | ||
|
@@ -28,6 +31,16 @@ def test_get_tox_ini_python_versions(tmp_path): | |
assert get_tox_ini_python_versions(tox_ini) == v(['2.7', '3.6', '3.10']) | ||
|
||
|
||
def test_get_tox_ini_dotted_python_versions(tmp_path): | ||
tox_ini = tmp_path / "tox.ini" | ||
tox_ini.write_text(textwrap.dedent("""\ | ||
[tox] | ||
envlist = py2.7,py3.6,py2.7-docs,pylint,py3.10 | ||
""")) | ||
assert get_tox_ini_python_versions(tox_ini) == \ | ||
v(['2.7', '3.6', '3.10'], has_dot=[True, True, True]) | ||
|
||
|
||
def test_get_tox_ini_python_versions_syntax_error(tmp_path): | ||
tox_ini = tmp_path / "tox.ini" | ||
tox_ini.write_text(textwrap.dedent("""\ | ||
|
@@ -107,6 +120,51 @@ def test_update_tox_ini_python_versions(): | |
""") | ||
|
||
|
||
def test_update_tox_ini_dotted_python_versions(): | ||
fp = StringIO(textwrap.dedent("""\ | ||
[tox] | ||
envlist = py2.6, py2.7 | ||
""")) | ||
fp.name = 'tox.ini' | ||
result = update_tox_ini_python_versions(fp, | ||
v(['3.6', '3.7', '3.10'], | ||
has_dot=[True, True, True])) | ||
assert "".join(result) == textwrap.dedent("""\ | ||
[tox] | ||
envlist = py3.6, py3.7, py3.10 | ||
""") | ||
|
||
|
||
def test_update_tox_ini_one_dotted_python_versions(): | ||
fp = StringIO(textwrap.dedent("""\ | ||
[tox] | ||
envlist = py26, py2.7 | ||
""")) | ||
fp.name = 'tox.ini' | ||
result = update_tox_ini_python_versions(fp, | ||
v(['3.6', '3.7', '3.10'], | ||
has_dot=[True, True, True])) | ||
assert "".join(result) == textwrap.dedent("""\ | ||
[tox] | ||
envlist = py3.6, py3.7, py3.10 | ||
""") | ||
|
||
|
||
def test_update_tox_ini_mixed_dotted_python_versions(): | ||
fp = StringIO(textwrap.dedent("""\ | ||
[tox] | ||
envlist = py26, py2.7 | ||
""")) | ||
fp.name = 'tox.ini' | ||
result = update_tox_ini_python_versions(fp, | ||
v(['3.6', '3.7', '3.10'], | ||
has_dot=[True, False, True])) | ||
assert "".join(result) == textwrap.dedent("""\ | ||
[tox] | ||
envlist = py3.6, py37, py3.10 | ||
""") | ||
|
||
|
||
def test_update_tox_ini_python_syntax_error(capsys): | ||
fp = StringIO(textwrap.dedent("""\ | ||
[tox | ||
|
@@ -154,6 +212,13 @@ def test_update_tox_envlist_with_spaces(): | |
assert result == 'py36, py37, pypy3' | ||
|
||
|
||
def test_update_tox_envlist_with_dots_and_spaces(): | ||
result = update_tox_envlist( | ||
'py27, py34, py35', | ||
v(['3.6', '3.7'], has_dot=[True, False])) | ||
assert result == 'py3.6, py37' | ||
|
||
|
||
@pytest.mark.parametrize('s, expected', [ | ||
# note that configparser trims leading whitespace, so \n is never | ||
# followed by a space | ||
|
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.
Instead of global state this should take an argument