diff --git a/tests/test_formatter/snapshots/snap_test_formatter_output.py b/tests/test_formatter/snapshots/snap_test_formatter_output.py index 3c6de0617..e858a6516 100644 --- a/tests/test_formatter/snapshots/snap_test_formatter_output.py +++ b/tests/test_formatter/snapshots/snap_test_formatter_output.py @@ -7,24 +7,65 @@ snapshots = Snapshot() -snapshots['test_formatter[cli_options0-regular] formatter_regular'] = ''' +snapshots['test_formatter_correct[cli_options0-regular] formatter_correct_regular'] = '' + +snapshots['test_formatter[cli_options2-with_source] formatter_with_source'] = ''' \x1b[4m\x1b[1m./tests/fixtures/formatter1.py\x1b[0m\x1b[0m + 1:1 WPS111 Found too short name: s + \x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m: + ^ + 1:7 WPS110 Found wrong variable name: handle + \x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m: + ^ + 2:21 WPS432 Found magic number: 200 + \x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2\x1b[39;49;00m_00 + ^ + 2:21 WPS303 Found underscored number: 2_00 + \x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2\x1b[39;49;00m_00 + ^ \x1b[4m\x1b[1m./tests/fixtures/formatter2.py\x1b[0m\x1b[0m + 1:1 WPS110 Found wrong variable name: data + \x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m: + ^ + 1:10 WPS110 Found wrong variable name: param + \x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m: + ^ + 2:12 WPS437 Found protected attribute usage: _protected + \x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10\x1b[39;49;00m_00 + ^ + 2:31 WPS303 Found underscored number: 10_00 + \x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10\x1b[39;49;00m_00 + ^ Full list of violations and explanations: -https://wemake-python-stylegui.de/en/0.10.0/pages/violations/ +https://wemake-python-stylegui.de/en/xx.xx/pages/violations/ ''' -snapshots['test_formatter[cli_options4-statistic_with_source] formatter_statistic_with_source'] = ''' +snapshots['test_formatter_correct[cli_options4-statistic_with_source] formatter_correct_statistic_with_source'] = ''' + +\x1b[4m\x1b[1mAll errors: 0\x1b[0m\x1b[0m +''' + +snapshots['test_formatter_correct[cli_options3-with_source_statistic] formatter_correct_with_source_statistic'] = ''' + +\x1b[4m\x1b[1mAll errors: 0\x1b[0m\x1b[0m +''' + +snapshots['test_formatter_correct[cli_options1-regular_statistic] formatter_correct_regular_statistic'] = ''' + +\x1b[4m\x1b[1mAll errors: 0\x1b[0m\x1b[0m +''' + +snapshots['test_formatter[cli_options3-with_source_statistic] formatter_with_source_statistic'] = ''' \x1b[4m\x1b[1m./tests/fixtures/formatter1.py\x1b[0m\x1b[0m 1:1 WPS111 Found too short name: s @@ -87,10 +128,10 @@ \x1b[4m\x1b[1mAll errors: 8\x1b[0m\x1b[0m Full list of violations and explanations: -https://wemake-python-stylegui.de/en/0.10.0/pages/violations/ +https://wemake-python-stylegui.de/en/xx.xx/pages/violations/ ''' -snapshots['test_formatter[cli_options3-with_source_statistic] formatter_with_source_statistic'] = ''' +snapshots['test_formatter[cli_options4-statistic_with_source] formatter_statistic_with_source'] = ''' \x1b[4m\x1b[1m./tests/fixtures/formatter1.py\x1b[0m\x1b[0m 1:1 WPS111 Found too short name: s @@ -153,48 +194,24 @@ \x1b[4m\x1b[1mAll errors: 8\x1b[0m\x1b[0m Full list of violations and explanations: -https://wemake-python-stylegui.de/en/0.10.0/pages/violations/ +https://wemake-python-stylegui.de/en/xx.xx/pages/violations/ ''' -snapshots['test_formatter[cli_options2-with_source] formatter_with_source'] = ''' +snapshots['test_formatter[cli_options0-regular] formatter_regular'] = ''' \x1b[4m\x1b[1m./tests/fixtures/formatter1.py\x1b[0m\x1b[0m - 1:1 WPS111 Found too short name: s - \x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m: - ^ - 1:7 WPS110 Found wrong variable name: handle - \x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m: - ^ - 2:21 WPS432 Found magic number: 200 - \x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2\x1b[39;49;00m_00 - ^ - 2:21 WPS303 Found underscored number: 2_00 - \x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2\x1b[39;49;00m_00 - ^ \x1b[4m\x1b[1m./tests/fixtures/formatter2.py\x1b[0m\x1b[0m - 1:1 WPS110 Found wrong variable name: data - \x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m: - ^ - 1:10 WPS110 Found wrong variable name: param - \x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m: - ^ - 2:12 WPS437 Found protected attribute usage: _protected - \x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10\x1b[39;49;00m_00 - ^ - 2:31 WPS303 Found underscored number: 10_00 - \x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10\x1b[39;49;00m_00 - ^ Full list of violations and explanations: -https://wemake-python-stylegui.de/en/0.10.0/pages/violations/ +https://wemake-python-stylegui.de/en/xx.xx/pages/violations/ ''' snapshots['test_formatter[cli_options1-regular_statistic] formatter_regular_statistic'] = ''' @@ -236,24 +253,7 @@ \x1b[4m\x1b[1mAll errors: 8\x1b[0m\x1b[0m Full list of violations and explanations: -https://wemake-python-stylegui.de/en/0.10.0/pages/violations/ +https://wemake-python-stylegui.de/en/xx.xx/pages/violations/ ''' -snapshots['test_formatter_correct[cli_options1-regular_statistic] formatter_correct_regular_statistic'] = ''' - -\x1b[4m\x1b[1mAll errors: 0\x1b[0m\x1b[0m -''' - -snapshots['test_formatter_correct[cli_options0-regular] formatter_correct_regular'] = '' - snapshots['test_formatter_correct[cli_options2-with_source] formatter_correct_with_source'] = '' - -snapshots['test_formatter_correct[cli_options3-with_source_statistic] formatter_correct_with_source_statistic'] = ''' - -\x1b[4m\x1b[1mAll errors: 0\x1b[0m\x1b[0m -''' - -snapshots['test_formatter_correct[cli_options4-statistic_with_source] formatter_correct_statistic_with_source'] = ''' - -\x1b[4m\x1b[1mAll errors: 0\x1b[0m\x1b[0m -''' diff --git a/tests/test_formatter/test_formatter_output.py b/tests/test_formatter/test_formatter_output.py index 70a1f1ad9..1e4dcedd9 100644 --- a/tests/test_formatter/test_formatter_output.py +++ b/tests/test_formatter/test_formatter_output.py @@ -22,6 +22,20 @@ import pytest +from wemake_python_styleguide.formatter import WemakeFormatter +from wemake_python_styleguide.version import pkg_version + + +def _safe_output(output: str) -> str: + """ + Removes version specific things from console output. + + So our formatter will be tested on all versions correctly. + """ + current_version_url = WemakeFormatter._doc_url # noqa: WPS437 + general_version_url = current_version_url.replace(pkg_version, 'xx.xx') + return output.replace(current_version_url, general_version_url) + @pytest.mark.parametrize('cli_options, output', [ ([], 'regular'), @@ -60,7 +74,10 @@ def test_formatter(snapshot, cli_options, output): ) stdout, _ = process.communicate() - snapshot.assert_match(stdout, 'formatter_{0}'.format(output)) + snapshot.assert_match( + _safe_output(stdout), + 'formatter_{0}'.format(output), + ) @pytest.mark.parametrize('cli_options, output', [ @@ -70,7 +87,7 @@ def test_formatter(snapshot, cli_options, output): (['--show-source', '--statistic'], 'with_source_statistic'), (['--statistic', '--show-source'], 'statistic_with_source'), ]) -def test_formatter_correct(snapshot, cli_options, output): +def test_formatter_correct(snapshot, monkeypatch, cli_options, output): """All correct code should not raise any violations and no output.""" filename = './tests/fixtures/correct.py' @@ -91,4 +108,7 @@ def test_formatter_correct(snapshot, cli_options, output): ) stdout, _ = process.communicate() - snapshot.assert_match(stdout, 'formatter_correct_{0}'.format(output)) + snapshot.assert_match( + _safe_output(stdout), + 'formatter_correct_{0}'.format(output), + )