diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16b1bbc..ccec4f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,9 +16,11 @@ jobs: INVOKE_LOCAL: "True" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v2" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + with: + poetry-version: "1.8.5" - name: "Linting: black" run: "poetry run invoke black" mypy: @@ -27,9 +29,11 @@ jobs: INVOKE_LOCAL: "True" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v2" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + with: + poetry-version: "1.8.5" - name: "Linting: mypy" run: "poetry run invoke mypy" bandit: @@ -38,9 +42,11 @@ jobs: INVOKE_LOCAL: "True" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v2" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + with: + poetry-version: "1.8.5" - name: "Linting: bandit" run: "poetry run invoke bandit" pydocstyle: @@ -49,9 +55,11 @@ jobs: INVOKE_LOCAL: "True" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v2" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + with: + poetry-version: "1.8.5" - name: "Linting: pydocstyle" run: "poetry run invoke pydocstyle" flake8: @@ -60,9 +68,11 @@ jobs: INVOKE_LOCAL: "True" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v2" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + with: + poetry-version: "1.8.5" - name: "Linting: flake8" run: "poetry run invoke flake8" yamllint: @@ -71,9 +81,11 @@ jobs: INVOKE_LOCAL: "True" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v2" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + with: + poetry-version: "1.8.5" - name: "Linting: yamllint" run: "poetry run invoke yamllint" pylint: @@ -94,9 +106,13 @@ jobs: INVOKE_LOCAL: "True" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v2" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + with: + poetry-version: "1.8.5" + # Default install options is "--only dev", but we need to install all dependencies + poetry-install-options: "" - name: "Linting: Pylint" run: "poetry run invoke pylint" pytest: @@ -112,9 +128,13 @@ jobs: INVOKE_LOCAL: "True" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v2" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + with: + poetry-version: "1.8.5" + # Default install options is "--only dev", but we need to install all dependencies + poetry-install-options: "" - name: "Run Tests" run: "poetry run invoke pytest" publish_gh: @@ -125,9 +145,9 @@ jobs: if: "startsWith(github.ref, 'refs/tags/v')" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Set up Python" - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: python-version: "3.9" - name: "Install Python Packages" @@ -154,9 +174,9 @@ jobs: if: "startsWith(github.ref, 'refs/tags/v')" steps: - name: "Check out repository code" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Set up Python" - uses: "actions/setup-python@v2" + uses: "actions/setup-python@v5" with: python-version: "3.9" - name: "Install Python Packages" diff --git a/jdiff/extract_data.py b/jdiff/extract_data.py index 96188ec..a4a57d0 100644 --- a/jdiff/extract_data.py +++ b/jdiff/extract_data.py @@ -30,7 +30,7 @@ def extract_data_from_json(data: Union[Mapping, List], path: str = "*", exclude: Returns: Evaluated data, may be anything depending on JMESPath used. """ - if exclude and isinstance(data, Dict): + if exclude and isinstance(data, (Dict, List)): if not isinstance(exclude, list): raise ValueError(f"Exclude list must be defined as a list. You have {type(exclude)}") # exclude unwanted elements diff --git a/tasks.py b/tasks.py index c9bc272..18508fe 100644 --- a/tasks.py +++ b/tasks.py @@ -1,7 +1,6 @@ """Tasks for use with Invoke.""" import os import sys -from distutils.util import strtobool from invoke import task try: @@ -16,14 +15,19 @@ def is_truthy(arg): Examples: >>> is_truthy('yes') True - Args: arg (str): Truthy string (True values are y, yes, t, true, on and 1; false values are n, no, f, false, off and 0. Raises ValueError if val is anything else. """ if isinstance(arg, bool): return arg - return bool(strtobool(arg)) + + val = str(arg).lower() + if val in ("y", "yes", "t", "true", "on", "1"): + return True + if val in ("n", "no", "f", "false", "off", "0"): + return False + raise ValueError(f"Invalid truthy value: `{arg}`") PYPROJECT_CONFIG = toml.load("pyproject.toml") diff --git a/tests/test_filter_parsers.py b/tests/test_filter_parsers.py index 46267ab..fe78f38 100644 --- a/tests/test_filter_parsers.py +++ b/tests/test_filter_parsers.py @@ -28,9 +28,38 @@ } }, ) +exclude_filter_test_case_2 = ( + ["interfaceStatistics"], + [ + { + "interfaces": { + "Management1": { + "name": "Management1", + "interfaceStatus": "connected", + "autoNegotiate": "success", + "interfaceStatistics": { + "inBitsRate": 3403.4362520883615, + "inPktsRate": 3.7424095978179257, + "outBitsRate": 16249.69114419833, + "updateInterval": 300, + "outPktsRate": 2.1111866059750692, + }, + } + } + } + ], + [ + { + "interfaces": { + "Management1": {"name": "Management1", "interfaceStatus": "connected", "autoNegotiate": "success"} + } + } + ], +) exclude_filter_tests = [ exclude_filter_test_case_1, + exclude_filter_test_case_2, ]