project_config.tests.pytest_plugin.plugin module
project-config pytest plugin.
- project_config.tests.pytest_plugin.plugin.assert_data_report(monkeypatch: _pytest.monkeypatch.MonkeyPatch, tmp_path: pathlib.Path) Any [source]
Pytest fixture to assert data reports.
Returns a function that can be used to assert a data report from a reporters module. See
project_config.tests.pytest_plugin.plugin.project_config_data_report_asserter()
.
- project_config.tests.pytest_plugin.plugin.assert_errors_report(monkeypatch: _pytest.monkeypatch.MonkeyPatch, tmp_path: pathlib.Path) Any [source]
Pytest fixture to assert errors reports.
Returns a function that can be used to assert an errors report from a reporters module. See
project_config.tests.pytest_plugin.plugin.project_config_errors_report_asserter()
.
- project_config.tests.pytest_plugin.plugin.assert_project_config_plugin_action(tmp_path: pathlib.Path) Any [source]
Pytest fixture to assert a plugin action.
Returns a function that can be used to assert a plugin action. See
project_config.tests.pytest_plugin.plugin.project_config_plugin_action_asserter()
.
- project_config.tests.pytest_plugin.plugin.project_config_data_report_asserter(monkeypatch: _pytest.monkeypatch.MonkeyPatch, rootdir: pathlib.Path, reporter_module: module, data_key: str, data: Any, expected_result: str, fmt: Optional[str] = None) None [source]
Asserts a data report from a reporter module.
- Parameters
monkeypatch (pytest.MonkeyPatch) – Monkeypatch fixture. This is not needed to define in the fixture as is inserted before the execution.
rootdir (Path) – Path to root directory. This is not needed to define in the fixture as is inserted before the execution.
reporters_module (types.ModuleType) – Module containing the reporters.
data_key (str) – Data key.
data (any) – Data content to report.
expected_result (str) – Expected reported result.
Example
import pytest from project_config.reporters import default @pytest.mark.parametrize( ("data_key", "data", "expected_result"), ( pytest.param( "config", { "cache": "5 minutes", "style": "foo.json5", }, '''cache: 5 minutes style: foo.json5 ''', id="config-style-string", ), pytest.param( "style", { "rules": [ { "files": ["foo.ext", "bar.ext"], }, ], }, '''rules: - files: - foo.ext - bar.ext ''', id="style-basic", ), ), ) def test_default_data_report( data_key, data, expected_result, assert_data_report, ): assert_data_report( default, data_key, data, expected_result, )
- project_config.tests.pytest_plugin.plugin.project_config_errors_report_asserter(monkeypatch: _pytest.monkeypatch.MonkeyPatch, rootdir: pathlib.Path, reporter_module: module, errors: List[project_config.types.ErrorDict], expected_result: str, fmt: Optional[str] = None) None [source]
Asserts an error report from a reporter module.
- Parameters
monkeypatch (pytest.MonkeyPatch) – Monkeypatch fixture. This is not needed to define in the fixture as is inserted before the execution.
rootdir (Path) – Path to root directory. This is not needed to define in the fixture as is inserted before the execution.
reporters_module (types.ModuleType) – Module containing the reporters.
errors (list) – List of errors.
expected_result (str) – Expected reported result.
Example
import pytest from project_config.reporters import default @pytest.mark.parametrize( ("errors", "expected_result"), ( pytest.param( [], "", id="empty", ), pytest.param( [ { "file": "foo.py", "message": "message", "definition": "definition", }, ], "foo.py\n - message definition", id="basic", ), pytest.param( [ { "file": "foo.py", "message": "message 1", "definition": "definition 1", }, { "file": "foo.py", "message": "message 2", "definition": "definition 2", }, { "file": "bar.py", "message": "message 3", "definition": "definition 3", }, ], '''foo.py - message 1 definition 1 - message 2 definition 2 bar.py - message 3 definition 3''', id="complex", ), ), ) def test_default_errors_report( errors, expected_result, assert_errors_report, ): assert_errors_report(default, errors, expected_result)
- project_config.tests.pytest_plugin.plugin.project_config_plugin_action_asserter(rootdir: Union[str, pathlib.Path], plugin_class: type, plugin_method_name: str, files: Dict[str, Optional[Union[str, bool]]], value: Any, rule: project_config.types.Rule, expected_results: List[Tuple[str, Union[bool, project_config.types.ErrorDict]]], additional_files: Optional[Dict[str, Optional[Union[str, bool]]]] = None, assert_case_method_name: bool = True) None [source]
Convenient function to test a plugin action.
- Parameters
rootdir (Path) – Path to root directory. This is not needed to define in the fixture as is inserted before the execution.
plugin_class (type) – Plugin class.
plugin_method_name (str) – Plugin method name.
files (dict) – Dictionary of files to create. Must have the file paths as keys and the content as values. The keys will be passed to the
files
property of the rule. If the value isFalse
, the file will not be created. If the value isNone
, the file will be created as a directory.value (Any) – Value passed to the action.
expected_results (list) – List of expected results.
additional_files (dict) – Dictionary of additional files to create. These will not be defined inside the
files
property of the rule. Follows the same format asfiles
.assert_case_method_name (bool) – If
True
, the method name will be checked to match against camelCase or PascalCase style.
Example
import pytest from project_config import Error, InterruptingError, ResultValue from project_config.plugins.include import IncludePlugin @pytest.mark.parametrize( ("files", "value", "rule", "expected_results"), ( pytest.param( {"foo.ext": "foo"}, ["foo"], None, [], id="ok", ), pytest.param( {"foo.ext": "foo"}, ["bar"], None, [ ( Error, { "definition": ".includeLines[0]", "file": "foo.ext", "message": "Expected line 'bar' not found", }, ), ], id="error", ), ), ) def test_includeLines( files, value, rule, expected_results, assert_project_config_plugin_action, ): assert_project_config_plugin_action( IncludePlugin, 'includeLines', files, value, rule, expected_results, )