From a79b62e6b4bbdf7ff63594e7d0c9446b705a4cdc Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Wed, 11 Oct 2023 14:41:31 +1100 Subject: [PATCH] Test support for Python 3.12 (#224) * Test support for Python 3.12 * Update tests with correct assertion attributes * simplify test matrix --- .github/workflows/ci.yml | 5 +- README.md | 12 ++--- pyproject.toml | 1 + test/integration/test_build.py | 2 +- test/unit/test_cli.py | 97 ++++++++++++++++------------------ 5 files changed, 53 insertions(+), 64 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6817c21..679fbb4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,9 @@ jobs: - '3.9' - '3.10' - '3.11' - continue-on-error: - - false + - '3.12' runs-on: "${{ matrix.os }}" - continue-on-error: "${{ matrix.continue-on-error }}" + continue-on-error: false steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 diff --git a/README.md b/README.md index fe4dfc95..4f36259f 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,9 @@ A command-line application for tracking, reporting on complexity of Python tests and applications. [![Wily](https://img.shields.io/badge/%F0%9F%A6%8A%20wily-passing-brightgreen.svg)](https://wily.readthedocs.io/) -[![codecov](https://codecov.io/gh/tonybaloney/wily/branch/master/graph/badge.svg)](https://codecov.io/gh/tonybaloney/wily) [![Documentation Status](https://readthedocs.org/projects/wily/badge/?version=latest)](https://wily.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/wily.svg)](https://badge.fury.io/py/wily) [![Conda Version](https://img.shields.io/conda/vn/conda-forge/wily.svg)](https://anaconda.org/conda-forge/wily) ![black](https://img.shields.io/badge/code%20style-black-000000.svg) +[![codecov](https://codecov.io/gh/tonybaloney/wily/branch/master/graph/badge.svg)](https://codecov.io/gh/tonybaloney/wily) [![Documentation Status](https://readthedocs.org/projects/wily/badge/?version=latest)](https://wily.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/wily.svg)](https://badge.fury.io/py/wily) [![Conda Version](https://img.shields.io/conda/vn/conda-forge/wily.svg)](https://anaconda.org/conda-forge/wily) ![black](https://img.shields.io/badge/code%20style-black-000000.svg) ![PyPI - Downloads](https://img.shields.io/pypi/dm/wily) - -``` +```default wily [a]: quick to think of things, having a very good understanding of situations and possibilities, and often willing to use tricks to achieve an aim. @@ -42,7 +41,7 @@ Wily can be used via a command line interface, `wily`. ## Demo -Here is a demo of wily analysing a Python project, giving a summary of changes to complexity in the last 10 commits and then showing changes against a specific git revision: +Here is a demo of wily analysing a Python project, giving a summary of changes to complexity in the last 10 commits and then showing changes against a specific git revision: ![demo](./docs/source/_static/termtosvg_leo0ur6s.svg) @@ -86,7 +85,7 @@ repos: The first step to using `wily` is to build a wily cache with the statistics of your project. -``` +```default Usage: __main__.py build [OPTIONS] [TARGETS]... Build the wily cache @@ -108,7 +107,6 @@ Limit the number of revisions (defaults to 50). ![wily-build](https://github.com/tonybaloney/wily/raw/master/docs/source/_static/wily_build.png) - #### `wily report` Show a specific metric for a given file, requires that `.wily/` exists @@ -139,7 +137,6 @@ Show information about the build directory. Requires that `.wily/` exists. ![wily-graph](https://github.com/tonybaloney/wily/raw/master/docs/source/_static/wily_index.png) - ### `wily list-metrics` List the metrics available in the Wily operators. Each one of the metrics can be used in `wily graph` and `wily report` @@ -203,7 +200,6 @@ Wily will detect and scan all Python code in .ipynb files automatically. You can disable this behaviour if you require by setting `ipynb_support = false` in the configuration. You can also disable the behaviour of reporting on individual cells by setting `ipynb_cells = false`. - # Credits ## Contributors diff --git a/pyproject.toml b/pyproject.toml index f5337028..5ae1da26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3 :: Only", ] dependencies = [ diff --git a/test/integration/test_build.py b/test/integration/test_build.py index 84e544e1..91c092fc 100644 --- a/test/integration/test_build.py +++ b/test/integration/test_build.py @@ -89,7 +89,7 @@ def test_build_crash(tmpdir): ) as bar_finish: runner = CliRunner() result = runner.invoke(main.cli, ["--path", tmpdir, "build", "test.py"]) - assert bar_finish.called_once + assert bar_finish.called assert result.exit_code == 1, result.stdout diff --git a/test/unit/test_cli.py b/test/unit/test_cli.py index 40c1f8a0..edc77931 100644 --- a/test/unit/test_cli.py +++ b/test/unit/test_cli.py @@ -8,13 +8,6 @@ from wily.helper.custom_enums import ReportFormat -def test_init(): - with patch.object(main, "cli", return_value=None) as cli: - with patch.object(main, "__name__", "__main__"): - __import__("wily.__main__") - assert cli.called_once - - def test_help(): """ Test that CLI when called with help options @@ -33,7 +26,7 @@ def test_setup(): runner = CliRunner() result = runner.invoke(main.cli, ["setup"]) assert result.exit_code == 0 - assert handle_no_cache.called_once + assert handle_no_cache.called def test_handle_no_cache_no(): @@ -43,7 +36,7 @@ def test_handle_no_cache_no(): with patch("wily.__main__.input", return_value="n") as mock_input: with pytest.raises(SystemExit): main.handle_no_cache(None) - assert mock_input.called_once + assert mock_input.called def test_handle_no_cache(): @@ -55,8 +48,10 @@ def test_handle_no_cache(): runner = CliRunner() runner.invoke(main.cli, ["setup"]) assert mock_input.called - assert build_command.called_once - assert build_command.called_with("1") + assert build_command.called + build_command.assert_called_with( + max_revisions=11, targets=["."], operators=None + ) def test_build(): @@ -67,7 +62,7 @@ def test_build(): runner = CliRunner() result = runner.invoke(main.cli, ["build", "wily"]) assert result.exit_code == 0 - assert build.called_once + assert build.called def test_build_with_opts(): @@ -80,7 +75,7 @@ def test_build_with_opts(): main.cli, ["build", "wily", "-n 1", "-o raw,maintainability"] ) assert result.exit_code == 0 - assert build.called_once + assert build.called assert build.call_args[1]["config"].max_revisions == 1 assert build.call_args[1]["config"].operators == ["raw", "maintainability"] @@ -94,8 +89,8 @@ def test_index(): runner = CliRunner() result = runner.invoke(main.cli, ["index"]) assert result.exit_code == 0 - assert index.called_once - assert check_cache.called_once + assert index.called + assert check_cache.called def test_index_with_opts(): @@ -107,8 +102,8 @@ def test_index_with_opts(): runner = CliRunner() result = runner.invoke(main.cli, ["index", "--message"]) assert result.exit_code == 0 - assert index.called_once - assert check_cache.called_once + assert index.called + assert check_cache.called assert index.call_args[1]["include_message"] @@ -121,8 +116,8 @@ def test_index_with_no_message(): runner = CliRunner() result = runner.invoke(main.cli, ["index", "--no-message"]) assert result.exit_code == 0 - assert index.called_once - assert check_cache.called_once + assert index.called + assert check_cache.called assert not index.call_args[1]["include_message"] @@ -139,12 +134,12 @@ def test_report(): runner = CliRunner() result = runner.invoke(main.cli, ["report", "foo.py"]) assert result.exit_code == 0, result.stdout - assert report.called_once - assert check_cache.called_once + assert report.called + assert check_cache.called assert report.call_args[1]["path"] == "foo.py" assert report.call_args[1]["format"] == ReportFormat.CONSOLE assert "maintainability.mi" in report.call_args[1]["metrics"] - assert gdf.called_once + assert gdf.called def test_report_with_opts(): @@ -158,8 +153,8 @@ def test_report_with_opts(): main.cli, ["report", "foo.py", "example_metric", "-n 101", "--message"] ) assert result.exit_code == 0, result.stdout - assert report.called_once - assert check_cache.called_once + assert report.called + assert check_cache.called assert report.call_args[1]["path"] == "foo.py" assert report.call_args[1]["metrics"] == ("example_metric",) assert report.call_args[1]["include_message"] @@ -187,8 +182,8 @@ def test_report_html_format(): ) assert result.exit_code == 0, result.stdout - assert report.called_once - assert check_cache.called_once + assert report.called + assert check_cache.called assert report.call_args[1]["path"] == "foo.py" assert report.call_args[1]["metrics"] == ("example_metric",) assert report.call_args[1]["include_message"] @@ -215,8 +210,8 @@ def test_report_console_format(): ], ) assert result.exit_code == 0, result.stdout - assert report.called_once - assert check_cache.called_once + assert report.called + assert check_cache.called assert report.call_args[1]["path"] == "foo.py" assert report.call_args[1]["metrics"] == ("example_metric",) assert report.call_args[1]["include_message"] @@ -243,8 +238,6 @@ def test_report_not_existing_format(): ], ) assert result.exit_code == 2, result.stdout - assert report.called_once - assert check_cache.called_once def test_report_html_format_with_output(): @@ -268,8 +261,8 @@ def test_report_html_format_with_output(): ) assert result.exit_code == 0, result.stdout - assert report.called_once - assert check_cache.called_once + assert report.called + assert check_cache.called assert report.call_args[1]["path"] == "foo.py" assert report.call_args[1]["metrics"] == ("example_metric",) assert report.call_args[1]["include_message"] @@ -291,8 +284,8 @@ def test_graph(): main.cli, ["graph", "foo.py", "-m", "example_metric"] ) assert result.exit_code == 0 - assert graph.called_once - assert check_cache.called_once + assert graph.called + assert check_cache.called assert graph.call_args[1]["path"] == ("foo.py",) assert graph.call_args[1]["metrics"] == "example_metric" @@ -309,8 +302,8 @@ def test_graph_multiple_paths(): ["graph", "foo.py", "bar.py", "baz.py", "-m", "example_metric"], ) assert result.exit_code == 0 - assert graph.called_once - assert check_cache.called_once + assert graph.called + assert check_cache.called assert graph.call_args[1]["path"] == ("foo.py", "bar.py", "baz.py") assert graph.call_args[1]["metrics"] == "example_metric" @@ -326,8 +319,8 @@ def test_graph_multiple_metrics(): main.cli, ["graph", "foo.py", "-m", "example_metric,another_metric"] ) assert result.exit_code == 0 - assert graph.called_once - assert check_cache.called_once + assert graph.called + assert check_cache.called assert graph.call_args[1]["path"] == ("foo.py",) assert graph.call_args[1]["metrics"] == "example_metric,another_metric" @@ -343,8 +336,8 @@ def test_graph_with_output(): main.cli, ["graph", "foo.py", "-m", "example_metric", "-o", "foo.html"] ) assert result.exit_code == 0 - assert graph.called_once - assert check_cache.called_once + assert graph.called + assert check_cache.called assert graph.call_args[1]["path"] == ("foo.py",) assert graph.call_args[1]["metrics"] == "example_metric" assert graph.call_args[1]["output"] == "foo.html" @@ -363,10 +356,10 @@ def test_diff(): runner = CliRunner() result = runner.invoke(main.cli, ["diff", "foo.py", "x/b.py"]) assert result.exit_code == 0 - assert diff.called_once - assert check_cache.called_once + assert diff.called + assert check_cache.called assert diff.call_args[1]["files"] == ("foo.py", "x/b.py") - assert gdf.called_once + assert gdf.called assert "maintainability.mi" in diff.call_args[1]["metrics"] @@ -392,8 +385,8 @@ def test_diff_with_metrics(): ], ) assert result.exit_code == 0 - assert diff.called_once - assert check_cache.called_once + assert diff.called + assert check_cache.called assert diff.call_args[1]["files"] == ("foo.py", "x/b.py") assert not gdf.called assert "maintainability.mi" in diff.call_args[1]["metrics"] @@ -409,8 +402,8 @@ def test_clean(): runner = CliRunner() result = runner.invoke(main.cli, ["clean", "--yes"]) assert result.exit_code == 0 - assert clean.called_once - assert check_cache.called_once + assert clean.called + assert check_cache.called def test_clean_with_prompt(): @@ -423,9 +416,9 @@ def test_clean_with_prompt(): runner = CliRunner() result = runner.invoke(main.cli, ["clean"]) assert result.exit_code == 0 - assert clean.called_once - assert check_cache.called_once - assert mock_input.called_once + assert clean.called + assert check_cache.called + assert mock_input.called def test_clean_with_prompt_no_value(): @@ -439,5 +432,5 @@ def test_clean_with_prompt_no_value(): result = runner.invoke(main.cli, ["clean"]) assert result.exit_code == 0 assert not clean.called - assert check_cache.called_once - assert mock_input.called_once + assert check_cache.called + assert mock_input.called