Skip to content

Fixes exclude to work with lists #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion jdiff/extract_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tasks for use with Invoke."""
import os
import sys
from distutils.util import strtobool
from invoke import task

try:
Expand All @@ -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")
Expand Down
29 changes: 29 additions & 0 deletions tests/test_filter_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]


Expand Down