From 66d12dd72adc30be5212df075baee90a2db6eef5 Mon Sep 17 00:00:00 2001 From: Vinit kumar Date: Sun, 11 May 2025 02:35:00 +0530 Subject: [PATCH 1/3] fix: trying some approaches --- .coverage | Bin 53248 -> 53248 bytes .github/workflows/pythonpackage.yml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.coverage b/.coverage index 80c2a68fb078d0d4503bedb5f4bd59af098a1e0e..846c56904b694a09f87b34cc89830efa2e9d742c 100644 GIT binary patch delta 152 zcmZozz}&Eac|tOy=Ejso@@x+o_}}wC+$<2sffATNkpTlp>FV4@&_Zz7GDc|HjeGcsLEUb*2jdqir`;{!d&;F_X|NsB* wpZDwDcr0)KuV3^3?Y!Up_DmoC3o@Mf^EKxD*FW|QDBw^0=WM3UbNW*p0J@Gk;{X5v delta 162 zcmZozz}&Eac|tOy#>SLI@@x+n_}}qA*eob;gu_(FNK!A~1TCyy) zs5mn}&s@(;&(LU-0b78;9|r!P{7d-f@Z0c9@N@C~0cw55H~Dv;1A80`D Date: Sun, 11 May 2025 02:47:06 +0530 Subject: [PATCH 2/3] fix: make test setup better --- .coverage | Bin 53248 -> 53248 bytes .github/workflows/pythonpackage.yml | 42 +++++++++++--- pyproject.toml | 3 + tests/conftest.py | 85 ++++++++++++++++++++++++++++ tests/test_dict2xml.py | 2 +- tox.ini | 45 ++++++++++++++- 6 files changed, 166 insertions(+), 11 deletions(-) create mode 100644 tests/conftest.py diff --git a/.coverage b/.coverage index 846c56904b694a09f87b34cc89830efa2e9d742c..43a4e1ef44bfb9dd1bb2f7d3f741a73914c189ad 100644 GIT binary patch delta 371 zcmZozz}&Ead4e>f@I)DBM&XSKOYC`A_~$Y3Kj%Nkzk`3?WgLvr6NR_nHlu6 ziu3b~Dspr5OG`3yiuDRA#hI8HOyQ#O@tJvbVHk_AlS%%+@hwo*1_l%_GcZti0lGV7WB>pF delta 680 zcmZuv&ubG=5PrL}yN{J7)0RluR8SN>2qqx(P@@!74D?cHpcfBY@CRLKV<8)2Tk@m+ z1GVg_kS00wAJC{hh|ST1hqm-0mNY2Tf;9<-YK$?ivni>q_zpAg%?#gs@8e5mA(@3I zeS*4h>V}{`9a|pk<~YLeGp^xFOyL}k<4CTn^C}LxI56LX@WasMN0Sr2h@nq}y;IX} z1z7)KwSA#RuMBL!xED6UK09hhT4s9KBf7y{A9e?N#p7dl^*e^WfDl{)Ej&QbG(Dsn znnu+Vj4_TuhAX&)ItFnM*YPn?yoN(3!6&r$95UoR(EqpEZWEH?fdS$F3}rK;dCWDf z#|!@q9pNXsz^5MPmuqVLOgDEn7}jx_^z)+|RcC|f?KrP@a7j=-+`F6F%&=yMV!xEp z#d!WlgP)b@bxR)aOP;@ERAwrXS|}3Tnp_DbtWf^P)QqGxh7$eBOUEUa$hIl~~P6H?95j*7Vy(y}nbLy`3nR%iBxQ z=!e)JMj`>~Ss+|sSh#JA#mOBN(mb&3ZfZ!m1&K9=wk7V#Z!kn(hL?#>rz7Blii z&h0M 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 \ No newline at end of file diff --git a/tests/test_dict2xml.py b/tests/test_dict2xml.py index 88e472e..aac5a7d 100644 --- a/tests/test_dict2xml.py +++ b/tests/test_dict2xml.py @@ -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 == 'false' + assert xml == 'false' def test_convert_kv_with_cdata(self): result = dicttoxml.convert_kv("key", "value", attr_type=False, cdata=True) diff --git a/tox.ini b/tox.ini index ecb51f6..82af3dc 100644 --- a/tox.ini +++ b/tox.ini @@ -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 From 2e42334f0e94583feea01e6745484339e6e817d7 Mon Sep 17 00:00:00 2001 From: Vinit kumar Date: Sun, 11 May 2025 02:48:41 +0530 Subject: [PATCH 3/3] fix: lint --- tests/conftest.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 58cbc37..aa5b29b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,7 @@ import json import os from pathlib import Path -from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union import pytest @@ -19,7 +19,7 @@ @pytest.fixture def sample_json_string() -> str: """Return a sample JSON string for testing. - + Returns: str: A sample JSON string """ @@ -29,7 +29,7 @@ def sample_json_string() -> str: @pytest.fixture def sample_json_dict() -> Dict[str, Any]: """Return a sample JSON dictionary for testing. - + Returns: Dict[str, Any]: A sample JSON dictionary """ @@ -43,7 +43,7 @@ def sample_json_dict() -> Dict[str, Any]: @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 """ @@ -64,22 +64,22 @@ def sample_json_list() -> List[Dict[str, Any]]: @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 \ No newline at end of file + + return file_path