|
| 1 | +from argparse import Namespace |
| 2 | +from types import SimpleNamespace |
| 3 | +from unittest.mock import patch |
| 4 | + |
| 5 | +import plain2code |
| 6 | +import plain_spec |
| 7 | + |
| 8 | + |
| 9 | +def _make_module(module_name, has_acceptance_tests, required_modules=None): |
| 10 | + """Build a minimal stand-in for a PlainModule. |
| 11 | +
|
| 12 | + The functional requirements only need an `acceptance_tests` key when the module |
| 13 | + is expected to contain acceptance tests, because that is all |
| 14 | + `plain_spec.has_acceptance_tests` inspects. |
| 15 | + """ |
| 16 | + functional_requirement = {"markdown": f"- {module_name} functionality."} |
| 17 | + if has_acceptance_tests: |
| 18 | + functional_requirement[plain_spec.ACCEPTANCE_TESTS] = [{"markdown": "- Test it."}] |
| 19 | + |
| 20 | + return SimpleNamespace( |
| 21 | + module_name=module_name, |
| 22 | + plain_source={plain_spec.FUNCTIONAL_REQUIREMENTS: [functional_requirement]}, |
| 23 | + all_required_modules=required_modules or [], |
| 24 | + ) |
| 25 | + |
| 26 | + |
| 27 | +def test_warns_when_acceptance_tests_present_and_no_conformance_script(): |
| 28 | + plain_module = _make_module("top", has_acceptance_tests=True) |
| 29 | + args = Namespace(conformance_tests_script=None) |
| 30 | + |
| 31 | + with patch("plain2code.console") as mock_console: |
| 32 | + plain2code.warn_if_acceptance_tests_without_conformance_script(plain_module, args) |
| 33 | + |
| 34 | + mock_console.warning.assert_called_once() |
| 35 | + warning_message = mock_console.warning.call_args.args[0] |
| 36 | + assert "top" in warning_message |
| 37 | + assert "conformance tests script" in warning_message |
| 38 | + |
| 39 | + |
| 40 | +def test_no_warning_when_conformance_script_configured(): |
| 41 | + plain_module = _make_module("top", has_acceptance_tests=True) |
| 42 | + args = Namespace(conformance_tests_script="run_conformance_tests.sh") |
| 43 | + |
| 44 | + with patch("plain2code.console") as mock_console: |
| 45 | + plain2code.warn_if_acceptance_tests_without_conformance_script(plain_module, args) |
| 46 | + |
| 47 | + mock_console.warning.assert_not_called() |
| 48 | + |
| 49 | + |
| 50 | +def test_no_warning_when_no_acceptance_tests(): |
| 51 | + plain_module = _make_module("top", has_acceptance_tests=False) |
| 52 | + args = Namespace(conformance_tests_script=None) |
| 53 | + |
| 54 | + with patch("plain2code.console") as mock_console: |
| 55 | + plain2code.warn_if_acceptance_tests_without_conformance_script(plain_module, args) |
| 56 | + |
| 57 | + mock_console.warning.assert_not_called() |
| 58 | + |
| 59 | + |
| 60 | +def test_warns_when_acceptance_tests_only_in_required_module(): |
| 61 | + required_module = _make_module("dependency", has_acceptance_tests=True) |
| 62 | + plain_module = _make_module("top", has_acceptance_tests=False, required_modules=[required_module]) |
| 63 | + args = Namespace(conformance_tests_script=None) |
| 64 | + |
| 65 | + with patch("plain2code.console") as mock_console: |
| 66 | + plain2code.warn_if_acceptance_tests_without_conformance_script(plain_module, args) |
| 67 | + |
| 68 | + mock_console.warning.assert_called_once() |
| 69 | + warning_message = mock_console.warning.call_args.args[0] |
| 70 | + assert "dependency" in warning_message |
0 commit comments