Tests: harden ruamel detection and gate fixture generators#3362
Open
a-v-popov wants to merge 1 commit intoipspace:ruamel-testsfrom
Open
Tests: harden ruamel detection and gate fixture generators#3362a-v-popov wants to merge 1 commit intoipspace:ruamel-testsfrom
a-v-popov wants to merge 1 commit intoipspace:ruamel-testsfrom
Conversation
* tests/utils.py: probe `ruamel.yaml`, not the bare `ruamel` namespace package, which can survive uninstalls and produce false positives. Pin `yaml.dump(..., default_flow_style=False, width=120)` to match `Box.to_yaml`'s historical defaults so future fixtures with top-level scalar lists do not silently diverge from the committed format. Drop redundant `global HAS_RUAMEL` and promote the explanatory block into a real `clean_ruamel` docstring. * tests/test_transformation.py: remove the redundant `log._ERROR_LOG = []` reset (`init_log_system` already does this inside `run_test`) and the trailing whitespace in `test_coverage_verbose_cases`. * tests/conftest.py: surface a `UserWarning` via `pytest_configure` / `issue_config_time_warning` when `ruamel.yaml` is present, so users see the slowdown advisory in pytest's standard warnings summary without breaking collection or pass/fail. * tests/create-transformation-test-case.py: print a stderr advisory before fixture generation when `ruamel.yaml` is installed (cleanup path keeps it correct, just slow). * tests/create-error-tests.sh: hard-fail at the top when `ruamel.yaml` is importable, since error-log fixtures cannot be generated correctly under ruamel and the docs already warn against it; refusing to run prevents broken `.log` files from being committed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A few items I'd suggest addressing before merging PR #3345, plus two small follow-ups:
1. The detection probe matches the namespace shim, not the library
tests/utils.pydoesimport ruamel, butruamelis a PEP 420 namespace package — it can survive uninstalls ofruamel.yaml(theruamel/directory often lingers, or another package owns part of the namespace). On my system right now:HAS_RUAMELbecomesTruewhileBox/PyYAML disagree, andclean_ruamelruns for nothing. python-box itself probes withfrom ruamel.yaml import version_info, YAML(box/converters.py:22). Suggested:2.
yaml.dumpshould pindefault_flow_style=FalseBox.to_yaml(...)in python-box 7.x defaults todefault_flow_style=False, width=120and callsyaml.dump(obj, default_flow_style=default_flow_style, width=width, ...)(box/converters.py:195,box/box.py:1018). The PR replaces it with:PyYAML's own default for
default_flow_styleisNone("auto: flow for inner scalar-only collections"), notFalse. Today's fixtures are all under-mappings, so the two modes coincide and the suite passes. The next fixture with a top-level scalar list, or a deeply nested scalar-only structure, will silently diverge from the format every committedexpected/*.ymlwas generated in. One-line fix:3.
log._ERROR_LOG = []is redundantThe previous line was
log.err_count = 0, which was a typo from the start —log.err_countdoesn't exist; the public counter isget_error_count()atnetsim/utils/log.py:389. The newlog._ERROR_LOG = []does target a real attribute, butrun_testimmediately callslog.init_log_system(header=False), which itself does_ERROR_LOG = [](log.py:539). The reset is redundant, and reaching into a leading-underscore symbol from outside the module is a smell. Either drop the line, or calllog.init_log_system(header=False)if a defensive reset is desired.Two small follow-ups worth folding in
tests/conftest.py(new): the standard-pytest-safe way to surface "ruamel.yaml is installed, things will be slower" ispytest_configure+config.issue_config_time_warning(UserWarning(...)). It appears in pytest's warnings summary, never fails a run, and doesn't touch collection /-kfiltering / parallelism. ImportHAS_RUAMELfromtests/utils.pyso there's a single source of truth.tests/create-error-tests.shdoesn't enforce it — a user can still run it and commit broken.logfiles. A 4-linepython3 -c "import ruamel.yaml" && exit 2guard at the top closes that hole.tests/create-transformation-test-case.pydoes work under ruamel (theclean_ruamelwalk handles it), so a stderr advisory there is enough.Reference implementation of all of the above on
a-v-popov/netlab@pr-3353-followup(compare view) — verified end-to-end:ruamel.yaml: xform + error tests pass; no warning.ruamel.yaml0.19.1: xform + error tests pass (+~40% wall time, matching the "slower" claim);UserWarningappears in pytest's warnings summary; nothing fails or skips.create-error-tests.shwithruamel.yamlinstalled: exits 2 with an actionable message before doing anything destructive.ruff check .clean.