diff --git a/pyproject.toml b/pyproject.toml index d4c15a7..e4b08bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,3 +5,7 @@ requires = [ "wheel >= 0.29.0", ] build-backend = 'setuptools.build_meta' + +[tool.black] +# py39 is not supported yet +target-version = ["py27", "py35", "py36", "py37", "py38"] diff --git a/setup.cfg b/setup.cfg index 211c325..7221c18 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,6 +54,7 @@ tox = [options.extras_require] testing = + black; python_version>='3.6' flake8 >= 3, <4 pytest >= 4.0.0, <6 pytest-cov >= 2, <3 @@ -72,6 +73,7 @@ minversion = 3.7 isolated_build = true skip_missing_interpreters = true envlist = + black flake8 py{27,35,36,37,38,39}-tox{312,315,latest} @@ -81,7 +83,7 @@ python = 3.5: py35 3.6: py36 3.7: py37 - 3.8: py38, flake8 + 3.8: py38, black, flake8 3.9: py39 [testenv] @@ -92,8 +94,13 @@ deps = extras = testing commands = pytest --cov=tox_gh_actions --cov-append --cov-branch {posargs:tests} +[testenv:black] +commands = black --check src/ tests/ setup.py +extras = testing +description = run black under {basepython} + [testenv:flake8] -commands = flake8 src/ tests/ +commands = flake8 src/ tests/ setup.py extras = testing description = run flake8 under {basepython} diff --git a/src/tox_gh_actions/plugin.py b/src/tox_gh_actions/plugin.py index d9f26e3..bc8d599 100644 --- a/src/tox_gh_actions/plugin.py +++ b/src/tox_gh_actions/plugin.py @@ -107,7 +107,7 @@ def get_python_version(): if "PyPy" in sys.version: return "pypy" + str(sys.version_info[0]) # Assuming running on CPython - return '.'.join([str(i) for i in sys.version_info[:2]]) + return ".".join([str(i) for i in sys.version_info[:2]]) def is_running_on_actions(): @@ -135,6 +135,7 @@ def is_env_specified(config): # which is licensed under MIT LICENSE # https://github.com/tox-dev/tox-travis/blob/0.12/LICENSE + def parse_dict(value): # type: (str) -> Dict[str, str] """Parse a dict value from the tox config. @@ -151,5 +152,5 @@ def parse_dict(value): } """ lines = [line.strip() for line in value.strip().splitlines()] - pairs = [line.split(':', 1) for line in lines if line] + pairs = [line.split(":", 1) for line in lines if line] return dict((k.strip(), v.strip()) for k, v in pairs) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index a06c63e..c619435 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -4,214 +4,226 @@ from tox_gh_actions import plugin -@pytest.mark.parametrize("config,expected", [ - ( - { - "gh-actions": { - "python": """2.7: py27 +@pytest.mark.parametrize( + "config,expected", + [ + ( + { + "gh-actions": { + "python": """2.7: py27 3.5: py35 3.6: py36 3.7: py37, flake8""" - } - }, - { - "python": { - "2.7": ["py27"], - "3.5": ["py35"], - "3.6": ["py36"], - "3.7": ["py37", "flake8"], + } }, - "env": {}, - }, - ), - ( - { - "gh-actions": { - "python": """2.7: py27 -3.8: py38""" + { + "python": { + "2.7": ["py27"], + "3.5": ["py35"], + "3.6": ["py36"], + "3.7": ["py37", "flake8"], + }, + "env": {}, }, - "gh-actions:env": { - "PLATFORM": """ubuntu-latest: linux + ), + ( + { + "gh-actions": { + "python": """2.7: py27 +3.8: py38""" + }, + "gh-actions:env": { + "PLATFORM": """ubuntu-latest: linux macos-latest: macos windows-latest: windows""" - } - }, - { - "python": { - "2.7": ["py27"], - "3.8": ["py38"], + }, }, - "env": { - "PLATFORM": { - "ubuntu-latest": ["linux"], - "macos-latest": ["macos"], - "windows-latest": ["windows"], + { + "python": { + "2.7": ["py27"], + "3.8": ["py38"], + }, + "env": { + "PLATFORM": { + "ubuntu-latest": ["linux"], + "macos-latest": ["macos"], + "windows-latest": ["windows"], + }, }, }, - }, - ), - ( - {"gh-actions": {}}, - { - "python": {}, - "env": {}, - }, - ), - ( - {}, - { - "python": {}, - "env": {}, - }, - ), -]) + ), + ( + {"gh-actions": {}}, + { + "python": {}, + "env": {}, + }, + ), + ( + {}, + { + "python": {}, + "env": {}, + }, + ), + ], +) def test_parse_config(config, expected): assert plugin.parse_config(config) == expected -@pytest.mark.parametrize("config,version,environ,expected", [ - ( - { - "python": { - "2.7": ["py27", "flake8"], - "3.8": ["py38", "flake8"], +@pytest.mark.parametrize( + "config,version,environ,expected", + [ + ( + { + "python": { + "2.7": ["py27", "flake8"], + "3.8": ["py38", "flake8"], + }, + "unknown": {}, + }, + "2.7", + {}, + ["py27", "flake8"], + ), + ( + { + "python": { + "2.7": ["py27", "flake8"], + "3.8": ["py38", "flake8"], + }, + "env": { + "SAMPLE": { + "VALUE1": ["fact1", "fact2"], + "VALUE2": ["fact3", "fact4"], + }, + }, }, - "unknown": {}, - }, - "2.7", - {}, - ["py27", "flake8"], - ), - ( - { - "python": { - "2.7": ["py27", "flake8"], - "3.8": ["py38", "flake8"], + "2.7", + { + "SAMPLE": "VALUE1", + "HOGE": "VALUE3", }, - "env": { - "SAMPLE": { - "VALUE1": ["fact1", "fact2"], - "VALUE2": ["fact3", "fact4"], + ["py27-fact1", "py27-fact2", "flake8-fact1", "flake8-fact2"], + ), + ( + { + "python": { + "2.7": ["py27", "flake8"], + "3.8": ["py38", "flake8"], + }, + "env": { + "SAMPLE": { + "VALUE1": ["fact1", "fact2"], + "VALUE2": ["fact3", "fact4"], + }, + "HOGE": { + "VALUE3": ["fact5", "fact6"], + "VALUE4": ["fact7", "fact8"], + }, }, }, - }, - "2.7", - { - "SAMPLE": "VALUE1", - "HOGE": "VALUE3", - }, - ["py27-fact1", "py27-fact2", "flake8-fact1", "flake8-fact2"], - ), - ( - { - "python": { - "2.7": ["py27", "flake8"], - "3.8": ["py38", "flake8"], + "2.7", + { + "SAMPLE": "VALUE1", + "HOGE": "VALUE3", }, - "env": { - "SAMPLE": { - "VALUE1": ["fact1", "fact2"], - "VALUE2": ["fact3", "fact4"], + [ + "py27-fact1-fact5", + "py27-fact1-fact6", + "py27-fact2-fact5", + "py27-fact2-fact6", + "flake8-fact1-fact5", + "flake8-fact1-fact6", + "flake8-fact2-fact5", + "flake8-fact2-fact6", + ], + ), + ( + { + "python": { + "2.7": ["py27", "flake8"], + "3.8": ["py38", "flake8"], }, - "HOGE": { - "VALUE3": ["fact5", "fact6"], - "VALUE4": ["fact7", "fact8"], + "env": { + "SAMPLE": { + "VALUE1": ["django18", "flake8"], + "VALUE2": ["django18"], + }, }, }, - }, - "2.7", - { - "SAMPLE": "VALUE1", - "HOGE": "VALUE3", - }, - [ - "py27-fact1-fact5", "py27-fact1-fact6", - "py27-fact2-fact5", "py27-fact2-fact6", - "flake8-fact1-fact5", "flake8-fact1-fact6", - "flake8-fact2-fact5", "flake8-fact2-fact6", - ], - ), - ( - { - "python": { - "2.7": ["py27", "flake8"], - "3.8": ["py38", "flake8"], + "2.7", + { + "SAMPLE": "VALUE1", + "HOGE": "VALUE3", }, - "env": { - "SAMPLE": { - "VALUE1": ["django18", "flake8"], - "VALUE2": ["django18"], + [ + "py27-django18", + "py27-flake8", + "flake8-django18", + "flake8-flake8", + ], + ), + ( + { + "python": { + "2.7": ["py27", "flake8"], + "3.8": ["py38", "flake8"], + }, + "env": { + "SAMPLE": { + "VALUE1": ["fact1", "fact2"], + "VALUE2": ["fact3", "fact4"], + }, }, + "unknown": {}, }, - }, - "2.7", - { - "SAMPLE": "VALUE1", - "HOGE": "VALUE3", - }, - [ - "py27-django18", "py27-flake8", - "flake8-django18", "flake8-flake8", - ], - ), - ( - { - "python": { - "2.7": ["py27", "flake8"], - "3.8": ["py38", "flake8"], + "2.7", + { + "SAMPLE": "VALUE3", }, - "env": { - "SAMPLE": { - "VALUE1": ["fact1", "fact2"], - "VALUE2": ["fact3", "fact4"], + ["py27", "flake8"], + ), + ( + { + "python": { + "2.7": ["py27", "flake8"], + "3.8": ["py38", "flake8"], + }, + "env": { + "SAMPLE": { + "VALUE1": [], + }, }, + "unknown": {}, }, - "unknown": {}, - }, - "2.7", - { - "SAMPLE": "VALUE3", - }, - ["py27", "flake8"], - ), - ( - { - "python": { - "2.7": ["py27", "flake8"], - "3.8": ["py38", "flake8"], + "3.8", + { + "SAMPLE": "VALUE2", }, - "env": { - "SAMPLE": { - "VALUE1": [], + ["py38", "flake8"], + ), + ( + { + "python": { + "3.8": ["py38", "flake8"], }, }, - "unknown": {}, - }, - "3.8", - { - "SAMPLE": "VALUE2", - }, - ["py38", "flake8"], - ), - ( - { - "python": { - "3.8": ["py38", "flake8"], + "2.7", + {}, + [], + ), + ( + { + "python": {}, }, - }, - "2.7", - {}, - [], - ), - ( - { - "python": {}, - }, - "3.8", - {}, - [], - ), -]) + "3.8", + {}, + [], + ), + ], +) def test_get_factors(mocker, config, version, environ, expected): mocker.patch("tox_gh_actions.plugin.os.environ", environ) result = normalize_factors_list(plugin.get_factors(config, version)) @@ -226,82 +238,96 @@ def normalize_factors_list(factors): return result -@pytest.mark.parametrize("envlist,factors,expected", [ - ( - ['py27', 'py37', 'flake8'], - ['py37', 'flake8'], - ['py37', 'flake8'], - ), - ( - ['py27', 'py37', 'flake8'], - [], - [], - ), - ( - [], - ['py37', 'flake8'], - [], - ), - ( - ['py27-dj111', 'py37-dj111', 'py37-dj20', 'flake8'], - ['py37', 'flake8'], - ['py37-dj111', 'py37-dj20', 'flake8'], - ), - ( - ['py27-django18', 'py37-django18', 'flake8'], - [ - 'py27-django18', 'py27-flake8', - 'flake8-django18', 'flake8-flake8', - ], - ['py27-django18', 'flake8'], - ) -]) +@pytest.mark.parametrize( + "envlist,factors,expected", + [ + ( + ["py27", "py37", "flake8"], + ["py37", "flake8"], + ["py37", "flake8"], + ), + ( + ["py27", "py37", "flake8"], + [], + [], + ), + ( + [], + ["py37", "flake8"], + [], + ), + ( + ["py27-dj111", "py37-dj111", "py37-dj20", "flake8"], + ["py37", "flake8"], + ["py37-dj111", "py37-dj20", "flake8"], + ), + ( + ["py27-django18", "py37-django18", "flake8"], + [ + "py27-django18", + "py27-flake8", + "flake8-django18", + "flake8-flake8", + ], + ["py27-django18", "flake8"], + ), + ], +) def test_get_envlist_from_factors(envlist, factors, expected): assert plugin.get_envlist_from_factors(envlist, factors) == expected -@pytest.mark.parametrize("version,info,expected", [ - ( - "3.8.1 (default, Jan 22 2020, 06:38:00) \n[GCC 9.2.0]", - (3, 8, 1, "final", 0), - "3.8", - ), - ( - "3.6.9 (1608da62bfc7, Dec 23 2019, 10:50:04)\n" - "[PyPy 7.3.0 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]", - (3, 6, 9, "final", 0), - "pypy3", - ), - ( - "2.7.13 (724f1a7d62e8, Dec 23 2019, 15:36:24)\n" - "[PyPy 7.3.0 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]", - (2, 7, 13, "final", 42), - "pypy2", - ) -]) +@pytest.mark.parametrize( + "version,info,expected", + [ + ( + "3.8.1 (default, Jan 22 2020, 06:38:00) \n[GCC 9.2.0]", + (3, 8, 1, "final", 0), + "3.8", + ), + ( + "3.6.9 (1608da62bfc7, Dec 23 2019, 10:50:04)\n" + "[PyPy 7.3.0 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]", + (3, 6, 9, "final", 0), + "pypy3", + ), + ( + "2.7.13 (724f1a7d62e8, Dec 23 2019, 15:36:24)\n" + "[PyPy 7.3.0 with GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]", + (2, 7, 13, "final", 42), + "pypy2", + ), + ], +) def test_get_version(mocker, version, info, expected): mocker.patch("tox_gh_actions.plugin.sys.version", version) mocker.patch("tox_gh_actions.plugin.sys.version_info", info) assert plugin.get_python_version() == expected -@pytest.mark.parametrize("environ,expected", [ - ({"GITHUB_ACTIONS": "true"}, True), - ({"GITHUB_ACTIONS": "false"}, False), - ({}, False), -]) +@pytest.mark.parametrize( + "environ,expected", + [ + ({"GITHUB_ACTIONS": "true"}, True), + ({"GITHUB_ACTIONS": "false"}, False), + ({}, False), + ], +) def test_is_running_on_actions(mocker, environ, expected): mocker.patch("tox_gh_actions.plugin.os.environ", environ) assert plugin.is_running_on_actions() == expected -@pytest.mark.parametrize("option_env,environ,expected", [ - (None, {"TOXENV": "flake8"}, True), - (["py27,py38"], {}, True), - (["py27", "py38"], {}, True), - (["py27"], {"TOXENV": "flake8"}, True), - (None, {}, False), -]) +@pytest.mark.parametrize( + "option_env,environ,expected", + [ + (None, {"TOXENV": "flake8"}, True), + (["py27,py38"], {}, True), + (["py27", "py38"], {}, True), + (["py27"], {"TOXENV": "flake8"}, True), + (None, {}, False), + ], +) def test_is_env_specified(mocker, option_env, environ, expected): mocker.patch("tox_gh_actions.plugin.os.environ", environ) option = mocker.MagicMock()