Skip to content

Add unit tests for osism/tasks/conductor/sonic/{bgp,constants}#2209

Open
berendt wants to merge 1 commit intomainfrom
gh2198
Open

Add unit tests for osism/tasks/conductor/sonic/{bgp,constants}#2209
berendt wants to merge 1 commit intomainfrom
gh2198

Conversation

@berendt
Copy link
Copy Markdown
Member

@berendt berendt commented Apr 25, 2026

Covers both modules with 100% statement coverage:

  • bgp.py: calculate_local_asn_from_ipv4 (docstring example, CIDR stripping, custom prefix, zero-padding, boundary octets, invalid formats), calculate_minimum_as_for_group (multiple/empty groups, invalid IPs skipped with logger.debug, None/empty primary_ip4 silently skipped, custom prefix, str() conversion of non-str IPs), and find_interconnected_spine_groups delegation to connections.find_interconnected_devices.
  • constants.py: invariants of module-level tables (default values, sorted-and-deduped DEFAULT_SONIC_ROLES, sample port-speed mappings across families, HIGH_SPEED_PORTS consistency with PORT_TYPE_TO_SPEED_MAP, HWSKU prefix and uniqueness).

Closes #2198

AI-assisted: Claude Code

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Several of the constants tests (e.g., in test_constants.py) repeat the same assertion pattern over different values and could be made more concise and maintainable using pytest.mark.parametrize.
  • The multiple calculate_local_asn_from_ipv4 invalid-input tests in test_bgp.py share a lot of boilerplate and could also benefit from parametrization over the invalid input and expected error pattern.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Several of the constants tests (e.g., in `test_constants.py`) repeat the same assertion pattern over different values and could be made more concise and maintainable using `pytest.mark.parametrize`.
- The multiple `calculate_local_asn_from_ipv4` invalid-input tests in `test_bgp.py` share a lot of boilerplate and could also benefit from parametrization over the invalid input and expected error pattern.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@berendt berendt force-pushed the gh2198 branch 2 times, most recently from b3739b4 to 48c9f0c Compare April 25, 2026 10:42
@berendt berendt requested a review from ideaship April 25, 2026 10:43
- bgp.py: calculate_local_asn_from_ipv4 (docstring example, CIDR
  stripping, custom prefix, zero-padding, boundary octets, invalid
  formats), calculate_minimum_as_for_group (multiple/empty groups,
  invalid IPs skipped with logger.debug, None/empty primary_ip4
  silently skipped, custom prefix, str() conversion of non-str IPs),
  and find_interconnected_spine_groups delegation to
  connections.find_interconnected_devices.
- constants.py: invariants of module-level tables (default values,
  sorted-and-deduped DEFAULT_SONIC_ROLES, sample port-speed mappings
  across families, HIGH_SPEED_PORTS consistency with
  PORT_TYPE_TO_SPEED_MAP, HWSKU prefix and uniqueness).

Importing these tests triggers osism/tasks/conductor/__init__, which
transitively loads osism/tasks/conductor/utils.py with its module-level
``from ansible import ...`` statements. ansible-core lives in the
optional ``[ansible]`` extra and is not installed in the unit-test
environment, so tests/conftest.py registers lightweight sys.modules
stubs for ``ansible``, ``ansible.constants``, ``ansible.errors`` and
``ansible.parsing.vault`` before collection. The stubs only satisfy
the import statements and are skipped when the real package is
installed.

Closes #2198

AI-assisted: Claude Code
Signed-off-by: Christian Berendt <berendt@osism.tech>
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.

Unit tests for osism/tasks/conductor/sonic/{constants,bgp}.py

1 participant