Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
Binary file modified .coverage
Binary file not shown.
44 changes: 36 additions & 8 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
name: Json2xml

on: [push, pull_request]
on:
push:
branches: [main, master]
paths-ignore:
- 'docs/**'
- '*.md'
- '*.rst'
pull_request:
paths-ignore:
- 'docs/**'
- '*.md'
- '*.rst'

permissions:
contents: read
Expand All @@ -25,12 +36,19 @@ jobs:
macos-latest,
]
include:
# Add exact version 3.14.0-alpha.0 for ubuntu-latest only
# Add exact version 3.14.0-beta.1 for ubuntu-latest only
- python-version: 3.14.0-beta.1
tox-python-version: py314-full
os: ubuntu-latest
# Add special linting and type-checking jobs
- python-version: '3.12'
tox-python-version: lint
os: ubuntu-latest
- python-version: '3.12'
tox-python-version: typecheck
os: ubuntu-latest
exclude:
# Exclude other OSes with Python 3.14.0-alpha.0
# Exclude other OSes with Python 3.14.0-beta.1
- python-version: 3.14.0-beta.1
tox-python-version: py314-full
os: windows-latest
Expand All @@ -48,25 +66,35 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: 'pip'
cache-dependency-path: |
requirements*.txt
requirements-dev.in

- name: install uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v6
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Consider pinning the action to a full semver or commit SHA

Loose tags (e.g., v6) can pull in unexpected patch updates that break builds. Pin to a full semver (e.g., v6.2.1) or a commit SHA for reproducible workflows.

Suggested change
uses: astral-sh/setup-uv@v6
uses: astral-sh/setup-uv@v6.2.1

with:
enable-cache: true
cache-dependency-glob: requirements-dev.txt
cache-dependency-glob: requirements*.txt

- name: Install dependencies
run: uv pip install --system tox tox-uv
run: |
uv pip install --system tox tox-uv
uv pip install --system pytest pytest-xdist pytest-cov

- name: Run tox targets for ${{ matrix.python-version }}
run: tox -e ${{matrix.tox-python-version}}
run: tox -e ${{matrix.tox-python-version}} --parallel auto
env:
PYTHONPATH: ${{ github.workspace }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
if: success() && matrix.tox-python-version != 'lint' && matrix.tox-python-version != 'typecheck'
with:
directory: ./coverage/reports/
env_vars: OS,PYTHON
fail_ci_if_error: true
files: ./coverage.xml,./coverage2.xml,!./cache
files: ./coverage.xml
flags: unittests
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-umbrella
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ test = [

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
xvs = true
addopts = "--cov=json2xml --cov-report=xml:coverage/reports/coverage.xml --cov-report=term"
[tool.ruff]
exclude = [
".env",
Expand Down
85 changes: 85 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""Pytest configuration for json2xml tests."""
from __future__ import annotations

import json
import os

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'os' is not used.

Copilot Autofix

AI 5 months ago

To fix the problem, we will remove the unused import os statement from line 5. This will eliminate the unnecessary dependency and improve the readability of the code. No other changes are required since the os module is not used anywhere in the provided code.

Suggested changeset 1
tests/conftest.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -4,3 +4,2 @@
 import json
-import os
 from pathlib import Path
EOF
@@ -4,3 +4,2 @@
import json
import os
from pathlib import Path
Copilot is powered by AI and may make mistakes. Always verify output.
from pathlib import Path
from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING

import pytest

if TYPE_CHECKING:
from _pytest.capture import CaptureFixture

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'CaptureFixture' is not used.

Copilot Autofix

AI 5 months ago

To fix the problem, we should remove the unused import statement from _pytest.capture import CaptureFixture on line 12. This will eliminate the unnecessary dependency and improve code clarity without affecting the functionality of the code.

Suggested changeset 1
tests/conftest.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -11,3 +11,3 @@
 if TYPE_CHECKING:
-    from _pytest.capture import CaptureFixture
+    
     from _pytest.fixtures import FixtureRequest
EOF
@@ -11,3 +11,3 @@
if TYPE_CHECKING:
from _pytest.capture import CaptureFixture

from _pytest.fixtures import FixtureRequest
Copilot is powered by AI and may make mistakes. Always verify output.
from _pytest.fixtures import FixtureRequest

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'FixtureRequest' is not used.

Copilot Autofix

AI 5 months ago

To fix the problem, we should remove the unused import statement from _pytest.fixtures import FixtureRequest on line 13. This will eliminate the unnecessary dependency and improve code readability without affecting the functionality of the code.

Suggested changeset 1
tests/conftest.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -12,3 +12,3 @@
     from _pytest.capture import CaptureFixture
-    from _pytest.fixtures import FixtureRequest
+
     from _pytest.logging import LogCaptureFixture
EOF
@@ -12,3 +12,3 @@
from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest

from _pytest.logging import LogCaptureFixture
Copilot is powered by AI and may make mistakes. Always verify output.
from _pytest.logging import LogCaptureFixture

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'LogCaptureFixture' is not used.

Copilot Autofix

AI 5 months ago

To fix the problem, we will remove the unused import statement from _pytest.logging import LogCaptureFixture on line 14. This will eliminate the unnecessary dependency and improve the code's clarity. No other changes are required, as this import is not used anywhere in the provided code.

Suggested changeset 1
tests/conftest.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -13,3 +13,3 @@
     from _pytest.fixtures import FixtureRequest
-    from _pytest.logging import LogCaptureFixture
+
     from _pytest.monkeypatch import MonkeyPatch
EOF
@@ -13,3 +13,3 @@
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture

from _pytest.monkeypatch import MonkeyPatch
Copilot is powered by AI and may make mistakes. Always verify output.
from _pytest.monkeypatch import MonkeyPatch

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'MonkeyPatch' is not used.

Copilot Autofix

AI 5 months ago

To fix the issue, we should remove the unused import statement from _pytest.monkeypatch import MonkeyPatch on line 15. This will eliminate the unnecessary dependency and improve the clarity of the code. No other changes are required since the import is not used anywhere in the provided code.

Suggested changeset 1
tests/conftest.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -14,3 +14,3 @@
     from _pytest.logging import LogCaptureFixture
-    from _pytest.monkeypatch import MonkeyPatch
+
     from pytest_mock.plugin import MockerFixture
EOF
@@ -14,3 +14,3 @@
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch

from pytest_mock.plugin import MockerFixture
Copilot is powered by AI and may make mistakes. Always verify output.
from pytest_mock.plugin import MockerFixture

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'MockerFixture' is not used.

Copilot Autofix

AI 5 months ago

To fix the problem, we should remove the unused import statement from pytest_mock.plugin import MockerFixture on line 16. This will eliminate the unnecessary dependency and improve code clarity. No other changes are required since this import is not used anywhere in the code.

Suggested changeset 1
tests/conftest.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -15,3 +15,3 @@
     from _pytest.monkeypatch import MonkeyPatch
-    from pytest_mock.plugin import MockerFixture
+
 
EOF
@@ -15,3 +15,3 @@
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock.plugin import MockerFixture


Copilot is powered by AI and may make mistakes. Always verify output.


@pytest.fixture
def sample_json_string() -> str:
"""Return a sample JSON string for testing.
Returns:
str: A sample JSON string
"""
return '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'


@pytest.fixture
def sample_json_dict() -> Dict[str, Any]:
"""Return a sample JSON dictionary for testing.
Returns:
Dict[str, Any]: A sample JSON dictionary
"""
return {
"login": "mojombo",
"id": 1,
"avatar_url": "https://avatars0.githubusercontent.com/u/1?v=4",
}


@pytest.fixture
def sample_json_list() -> List[Dict[str, Any]]:
"""Return a sample JSON list for testing.
Returns:
List[Dict[str, Any]]: A sample list of JSON dictionaries
"""
return [
{
"login": "mojombo",
"id": 1,
"avatar_url": "https://avatars0.githubusercontent.com/u/1?v=4",
},
{
"login": "defunkt",
"id": 2,
"avatar_url": "https://avatars0.githubusercontent.com/u/2?v=4",
},
]


@pytest.fixture
def sample_json_file(tmp_path: Path) -> Path:
"""Create a sample JSON file for testing.
Args:
tmp_path (Path): Pytest temporary path fixture
Returns:
Path: Path to the created JSON file
"""
file_path = tmp_path / "sample.json"

data = {
"login": "mojombo",
"id": 1,
"avatar_url": "https://avatars0.githubusercontent.com/u/1?v=4",
}

with open(file_path, "w") as f:
json.dump(data, f)

return file_path
2 changes: 1 addition & 1 deletion tests/test_dict2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def test_with_custom_attributes(self):

def test_valid_key(self):
xml = dicttoxml.convert_bool('valid_key', False, False)
assert xml == '<valid_key type="bool">false</valid_key>'
assert xml == '<valid_key>false</valid_key>'

def test_convert_kv_with_cdata(self):
result = dicttoxml.convert_kv("key", "value", attr_type=False, cdata=True)
Expand Down
45 changes: 42 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
[tox]
envlist = py310, py311, py312, py313, pypy310, pypy311, py314-full
isolated_build = True
skip_missing_interpreters = True
parallel_show_output = True

[testenv]
passenv =
CI
GITHUB_*
PYTHONPATH
deps =
pytest>=8.0.0
pytest-cov>=6.0.0
pytest-xdist>=3.5.0
ruff>=0.3.0
mypy>=1.0.0
types-setuptools

allowlist_externals =
pytest
pytest-cov
ruff
mypy

allowlist_externals = pytest
commands =
pytest --cov=json2xml --cov-report=xml:coverage/reports/coverage.xml --cov-report=term -xvs {posargs:tests} -n auto

[testenv:lint]
deps =
ruff>=0.3.0
commands =
ruff check json2xml tests

[testenv:typecheck]
deps =
mypy>=1.0.0
types-setuptools
commands =
pytest --cov --cov-report=xml
mypy json2xml tests

[testenv:py314-full]
deps =
{[testenv]deps}
commands =
{[testenv]commands}
ruff check json2xml tests
mypy json2xml tests

[pytest]
testpaths = tests
python_files = test_*.py
Loading