Skip to content

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

Open
ipspace wants to merge 2 commits intodevfrom
ruamel-tests
Open

Fix: Make CI/CD tests work with Ruamel#3353
ipspace wants to merge 2 commits intodevfrom
ruamel-tests

Conversation

@ipspace
Copy link
Copy Markdown
Owner

@ipspace ipspace commented May 6, 2026

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

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
Copy link
Copy Markdown
Owner Author

ipspace commented May 6, 2026

@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
Copy link
Copy Markdown
Collaborator

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

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
Copy link
Copy Markdown
Owner Author

ipspace commented May 7, 2026

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
Copy link
Copy Markdown
Collaborator

a-v-popov commented May 8, 2026

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.

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