Skip to content

Fix: Make CI/CD tests work with Ruamel - #3353

Merged
ipspace merged 4 commits into
devfrom
ruamel-tests
May 9, 2026
Merged

Fix: Make CI/CD tests work with Ruamel#3353
ipspace merged 4 commits into
devfrom
ruamel-tests

Conversation

@ipspace

@ipspace ipspace commented May 6, 2026

Copy link
Copy Markdown
Owner

This is more of a workaround than a complete solution. The tests pass even when Ruamel is installed and you can generate new transformation test results. Error test results cannot be generated with Ruamel due to Ruamel-specific scalar types

@ipspace

ipspace commented May 6, 2026

Copy link
Copy Markdown
Owner Author

@a-v-popov -- this makes CI/CD tests work with ruamel, but it's an ugly workaround until we're forced to migrate to ruamel. It also makes tests run a bit slower, as the topology must be cleaned of ruamel scalar types before proceeding.

@ipspace ipspace linked an issue May 6, 2026 that may be closed by this pull request

@a-v-popov a-v-popov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few items, mostly AI/test driven, I'd suggest addressing before merging, plus two small follow-ups, I think might be helpful:

1. The detection probe matches the namespace shim, not the library

tests/utils.py does import ruamel, but ruamel is a PEP 420 namespace package — it can survive uninstalls of ruamel.yaml (the ruamel/ directory often lingers, or another package owns part of the namespace). On my system right now:

>>> import ruamel
>>> import ruamel.yaml
ModuleNotFoundError: No module named 'ruamel.yaml'

HAS_RUAMEL becomes True while Box/PyYAML disagree, and clean_ruamel runs for nothing. python-box itself probes with from ruamel.yaml import version_info, YAML (box/converters.py:22). Suggested:

try:
  import ruamel.yaml  # noqa: F401
  HAS_RUAMEL = True
except ImportError:
  HAS_RUAMEL = False

2. yaml.dump should pin default_flow_style=False

Box.to_yaml(...) in python-box 7.x defaults to default_flow_style=False, width=120 and calls yaml.dump(obj, default_flow_style=default_flow_style, width=width, ...) (box/converters.py:195, box/box.py:1018). The PR replaces it with:

return yaml.dump(topology.to_dict(), width=120)

PyYAML's own default for default_flow_style is None ("auto: flow for inner scalar-only collections"), not False. 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 committed expected/*.yml was generated in. One-line fix:

return yaml.dump(topology.to_dict(), default_flow_style=False, width=120)

3. log._ERROR_LOG = [] is redundant

The previous line was log.err_count = 0, which was a typo from the start — log.err_count doesn't exist; the public counter is get_error_count() at netsim/utils/log.py:389. The new log._ERROR_LOG = [] does target a real attribute, but run_test immediately calls log.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 call log.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" is pytest_configure + config.issue_config_time_warning(UserWarning(...)). It appears in pytest's warnings summary, never fails a run, and doesn't touch collection / -k filtering / parallelism. Import HAS_RUAMEL from tests/utils.py so there's a single source of truth.
  • Gate the fixture generators. The PR docs already say error-log fixtures can't be generated under ruamel, but tests/create-error-tests.sh doesn't enforce it — a user can still run it and commit broken .log files. A 4-line python3 -c "import ruamel.yaml" && exit 2 guard at the top closes that hole. tests/create-transformation-test-case.py does work under ruamel (the clean_ruamel walk 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:

  • Without ruamel.yaml: xform + error tests pass; no warning.
  • With ruamel.yaml 0.19.1: xform + error tests pass (+~40% wall time, matching the "slower" claim); UserWarning appears in pytest's warnings summary; nothing fails or skips.
  • create-error-tests.sh with ruamel.yaml installed: exits 2 with an actionable message before doing anything destructive.
  • ruff check . clean.

Happy to open the follow-up as a separate PR against dev after this lands, or fold the changes in here if you prefer.

@ipspace

ipspace commented May 7, 2026

Copy link
Copy Markdown
Owner Author

A few items, mostly AI/test driven, I'd suggest addressing before merging, plus two small follow-ups, I think might be helpful:

Awesome job. Thanks a million. What AI model/harness were you using?

Happy to open the follow-up as a separate PR against dev after this lands, or fold the changes in here if you prefer.

It would be great if you could either add changes to this PR or submit a PR against this branch, so that we end with a single commit in the dev branch.

@a-v-popov

a-v-popov commented May 8, 2026

Copy link
Copy Markdown
Collaborator

What AI model/harness were you using?

That would be Claude Code running in tmux on remote VM in a cloud and using official Opus 4.7 model at xhigh effort, if I understood the question correctly.

It would be great if you could either add changes to this PR or submit a PR against this branch, so that we end with a single commit in the dev branch.

Submitted #3362
Please let me know if anything is off.

ipspace and others added 4 commits May 9, 2026 08:36
This is more of a workaround than a complete solution. The tests pass
even when Ruamel is installed and you can generate new transformation
test results. Error test results cannot be generated with Ruamel due
to Ruamel-specific scalar types
* 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.
@ipspace
ipspace merged commit 382a25b into dev May 9, 2026
11 checks passed
@ipspace
ipspace deleted the ruamel-tests branch May 9, 2026 06:52
@ipspace

ipspace commented May 9, 2026

Copy link
Copy Markdown
Owner Author

That would be Claude Code running in tmux on remote VM in a cloud and using official Opus 4.7 model at xhigh effort

Thank you. Exactly what I was looking for!

Submitted #3362 Please let me know if anything is off.

The only missing detail were the type annotations in the new test file. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] tests are failing in devcontainer

2 participants