From 97e8390a1649bbc60d94230fa8d24131a7f9e88b Mon Sep 17 00:00:00 2001 From: Dan Halperin Date: Mon, 16 Nov 2026 18:13:15 +0000 Subject: [PATCH] CI: test all supported Python releases Add Python 3.15 to the unit and integration matrices and run doc tests on 3.15. The matrices cover released, non-EOL Python versions 3.11 through 3.15 and finish every entry even when one fails. Remove DeepDiff and its cachebox dependency, which cannot build on Python 3.15. Use a local route-field matcher with the existing subset, unordered collection, duplicate, and type-checking behavior. Co-authored-by: dhalperi <526415+dhalperi@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> --- .github/workflows/reusable-precommit.yml | 6 ++- pybatfish/client/asserts.py | 27 ++++++++----- pyproject.toml | 2 +- tests/client/test_assert.py | 48 ++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 11 deletions(-) diff --git a/.github/workflows/reusable-precommit.yml b/.github/workflows/reusable-precommit.yml index 7ac52c5d..486cb0a0 100644 --- a/.github/workflows/reusable-precommit.yml +++ b/.github/workflows/reusable-precommit.yml @@ -100,12 +100,14 @@ jobs: version=$(echo ${{ matrix.python_version }} | sed s/\\.//) bash <(curl -s https://codecov.io/bash) -t ${{ secrets.PYBATFISH_CODECOV_TOKEN }} -F unit${version} strategy: + fail-fast: false matrix: python_version: - "3.11" - "3.12" - "3.13" - "3.14" + - "3.15" integration_tests: runs-on: ubuntu-latest needs: @@ -149,12 +151,14 @@ jobs: version=$(echo ${{ matrix.python_version }} | sed s/\\.//) bash <(curl -s https://codecov.io/bash) -t ${{ secrets.PYBATFISH_CODECOV_TOKEN }} -F integration${version} strategy: + fail-fast: false matrix: python_version: - "3.11" - "3.12" - "3.13" - "3.14" + - "3.15" doc_tests: runs-on: ubuntu-latest needs: @@ -167,7 +171,7 @@ jobs: java-version: "25" - uses: actions/setup-python@v7 with: - python-version: "3.14" + python-version: "3.15" - name: Download bf JAR uses: actions/download-artifact@v8 with: diff --git a/pybatfish/client/asserts.py b/pybatfish/client/asserts.py index c3f9374b..c36d72b4 100644 --- a/pybatfish/client/asserts.py +++ b/pybatfish/client/asserts.py @@ -26,7 +26,6 @@ from collections.abc import Iterable from typing import TYPE_CHECKING, Any -from deepdiff import DeepDiff from pandas import DataFrame from pybatfish.datamodel import PathConstraints @@ -125,16 +124,26 @@ def _get_duplicate_router_ids( return df[df.duplicated(["Router_ID"], keep=False)].sort_values(["Router_ID"]) +def _is_value_match(actual: Any, expected: Any) -> bool: + if actual is expected: + return True + if type(actual) is not type(expected): + return False + if isinstance(actual, dict): + return actual.keys() == expected.keys() and all( + _is_value_match(value, expected[key]) for key, value in actual.items() + ) + if isinstance(actual, (list, tuple, set, frozenset)): + # Collection order and duplicate counts do not affect matching. + return all(any(_is_value_match(a, e) for e in expected) for a in actual) and all( + any(_is_value_match(a, e) for a in actual) for e in expected + ) + return bool(actual == expected) + + def _is_dict_match(actual: dict[str, Any], expected: dict[str, Any]) -> bool: """Matches two dictionaries. `expected` can be a subset of `actual`.""" - diff = DeepDiff( - _subdict(actual, expected.keys()), - expected, - ignore_order=True, - verbose_level=1, - view="text", - ) - return not diff + return _is_value_match(_subdict(actual, expected.keys()), expected) def _raise_common(err_text, soft=False): diff --git a/pyproject.toml b/pyproject.toml index 761950ac..69cd0823 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,11 +37,11 @@ classifiers = [ "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", ] keywords = ["network", "configuration", "verification"] dependencies = [ "attrs>=18.1.0", - "deepdiff", "pandas", "python-dateutil", "PyYAML", diff --git a/tests/client/test_assert.py b/tests/client/test_assert.py index b9af62f0..9b65b267 100644 --- a/tests/client/test_assert.py +++ b/tests/client/test_assert.py @@ -40,6 +40,8 @@ from pybatfish.client.session import Session from pybatfish.datamodel import HeaderConstraints, PathConstraints from pybatfish.datamodel.answer import TableAnswer +from pybatfish.datamodel.primitives import ListWrapper +from pybatfish.datamodel.route import NextHopIp from pybatfish.exception import ( BatfishAssertException, BatfishAssertWarning, @@ -626,6 +628,52 @@ def test_is_dict_match(): # wrong value assert not _is_dict_match({"k1": "v1", "k2": "v2"}, {"k1": "v3"}) + assert _is_dict_match({}, {"k1": None}) + + +@pytest.mark.parametrize( + "actual,expected,matched", + [ + ([1, 2], [2, 1], True), + ([1, 1], [1], True), + ([1], [1, 1], True), + ([1, 2], [1, 3], False), + ([], [], True), + ([], [1], False), + ([1], [], False), + ((1, 2), (2, 1), True), + ([1, 2], (1, 2), False), + ({1, 2}, {2, 1}, True), + (frozenset({1, 2}), frozenset({2, 1}), True), + ({1}, {1.0}, False), + ({"a": [1, 2], "b": 3}, {"b": 3, "a": [2, 1]}, True), + ([{"a": [1, 2]}, {"b": 3}], [{"b": 3}, {"a": [2, 1]}], True), + ({"a": 1, "b": 2}, {"a": 1}, False), + (1, 1.0, False), + (True, 1, False), + (float("nan"), float("nan"), False), + (ListWrapper([1, 2]), ListWrapper([2, 1]), True), + (ListWrapper([1, 2]), [2, 1], False), + (NextHopIp("1.1.1.1"), NextHopIp("1.1.1.1"), True), + (NextHopIp("1.1.1.1"), NextHopIp("2.2.2.2"), False), + ], +) +def test_is_dict_match_values(actual, expected, matched): + assert _is_dict_match({"field": actual}, {"field": expected}) is matched + + +def test_has_route_unordered_communities(): + routes = DataFrame( + { + "Node": ["n1"], + "VRF": ["default"], + "Network": ["192.0.2.0/24"], + "Communities": [["1:1", "1:2"]], + } + ) + assert_has_route(routes, {"Communities": ["1:2", "1:1"]}, "n1") + assert_has_no_route(routes, {"Communities": ["1:3"]}, "n1") + def test_has_route_unsupported_type_routes(): with pytest.raises(TypeError) as excinfo: