From 31a8c6e1c7af0d2925c5b373dbbfead74cbc5646 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Wed, 20 Apr 2022 15:17:37 +0530 Subject: [PATCH 1/6] fix: check new CI stuff like lint and coverage --- .github/workflows/lint.yml | 43 +++++++++++++++++++++++++++++ .github/workflows/pythonpackage.yml | 20 ++++++++++++-- setup.cfg | 4 +++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..afcabb1c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,43 @@ +name: django CMS linters.yml + +on: [push, pull_request] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + flake8: + name: flake8 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: 3.9 + cache: 'pip' + - run: pip install --upgrade flake8 + - name: flake8 + uses: liskin/gh-problem-matcher-wrap@v1 + with: + linters: flake8 + run: flake8 + + isort: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: 3.9 + cache: 'pip' + - run: python -m pip install isort + - name: isort + uses: liskin/gh-problem-matcher-wrap@v1 + with: + linters: isort + run: isort --check --diff json2xml diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 0139d4a3..81fa36c1 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -39,6 +39,20 @@ jobs: pip install py==1.11.0 # stop the build if there are Python syntax errors or undefined names flake8 json2xml/ --exit-zero - - name: Test with pytest - run: | - pytest + - name: Unit tests + run: coverage run -m pytest + + - name: Coveralls + uses: AndreMiras/coveralls-python-action@develop + with: + parallel: true + flag-name: Unit Test + + coveralls_finish: + needs: test + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: AndreMiras/coveralls-python-action@develop + with: + parallel-finished: true diff --git a/setup.cfg b/setup.cfg index 7ed4a789..7b679c07 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,3 +30,7 @@ no_implicit_optional = true warn_redundant_casts = true warn_unused_ignores = true ignore_missing_imports = true + + +[coverage:run] +relative_files = True From 0cefd9e67a6918b3897bf8c0e0c06658fb2e5ae0 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Wed, 20 Apr 2022 15:21:43 +0530 Subject: [PATCH 2/6] fix: lint issues and CI --- .github/workflows/pythonpackage.yml | 2 +- json2xml/dicttoxml.py | 7 ++----- json2xml/json2xml.py | 5 ++++- json2xml/utils.py | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 81fa36c1..47096d1e 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -49,7 +49,7 @@ jobs: flag-name: Unit Test coveralls_finish: - needs: test + needs: build runs-on: ubuntu-latest steps: - name: Coveralls Finished diff --git a/json2xml/dicttoxml.py b/json2xml/dicttoxml.py index 6c3b0e73..1693712e 100755 --- a/json2xml/dicttoxml.py +++ b/json2xml/dicttoxml.py @@ -15,9 +15,9 @@ import logging import numbers from random import randint -from defusedxml.minidom import parseString +from typing import Any, Dict -from typing import Dict, Any +from defusedxml.minidom import parseString LOG = logging.getLogger("dicttoxml") @@ -137,9 +137,7 @@ def convert(obj, ids, attr_type, item_func, cdata, item_wrap, parent="root"): LOG.info(f'Inside convert(). obj type is: "{type(obj).__name__}", obj="{str(obj)}"') - item_name = item_func(parent) - # since bool is also a subtype of number.Number and int, the check for bool # never comes and hence we get wrong value for the xml type bool # here, we just change order and check for bool first, because no other @@ -303,7 +301,6 @@ def convert_list(items, ids, parent, attr_type, item_func, cdata, item_wrap): ) ) - elif isinstance(item, dict): item_dict_str = convert_dict( item, diff --git a/json2xml/json2xml.py b/json2xml/json2xml.py index ed5614c0..1311fd87 100644 --- a/json2xml/json2xml.py +++ b/json2xml/json2xml.py @@ -1,7 +1,10 @@ -from typing import Optional, Any +from typing import Any, Optional + from defusedxml.minidom import parseString from pyexpat import ExpatError + from json2xml import dicttoxml + from .utils import InvalidDataError diff --git a/json2xml/utils.py b/json2xml/utils.py index c1dddc62..9b6f34d4 100644 --- a/json2xml/utils.py +++ b/json2xml/utils.py @@ -1,6 +1,7 @@ """Utils methods to convert XML data to dict from various sources""" import json from typing import Dict, Optional + import requests From 6457db6026f07b64d86e3633dfcb9387788501f6 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Wed, 20 Apr 2022 15:24:28 +0530 Subject: [PATCH 3/6] fix: add coverage to the mix --- .github/workflows/pythonpackage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 47096d1e..57f6e4d8 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -36,6 +36,7 @@ jobs: pip install flake8 pip install xmltodict==0.12.0 pip install pytest==7.0.1 + pip install coverage==6.3.2 pip install py==1.11.0 # stop the build if there are Python syntax errors or undefined names flake8 json2xml/ --exit-zero From 87e325a188469b7a3ec42a0e0ef3a3f223b6e729 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Wed, 20 Apr 2022 15:28:46 +0530 Subject: [PATCH 4/6] fix: flake8 tests --- tests/test_json2xml.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_json2xml.py b/tests/test_json2xml.py index 54ef4d50..2fa1547f 100644 --- a/tests/test_json2xml.py +++ b/tests/test_json2xml.py @@ -185,7 +185,6 @@ def test_read_boolean_data_from_json(self): assert dict_from_xml["all"]["boolean"]["#text"] != 'True' assert dict_from_xml["all"]["boolean"]["#text"] == 'true' - def test_read_boolean_data_from_json2(self): """Test correct return for boolean types.""" data = readfromjson("examples/booleanjson2.json") From 077f75e9ac96085ac136f3bcf92b90ebbfef29a2 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Wed, 20 Apr 2022 15:37:11 +0530 Subject: [PATCH 5/6] feat: use codecov --- .github/workflows/pythonpackage.yml | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 57f6e4d8..a487a118 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -41,19 +41,8 @@ jobs: # stop the build if there are Python syntax errors or undefined names flake8 json2xml/ --exit-zero - name: Unit tests - run: coverage run -m pytest - - - name: Coveralls - uses: AndreMiras/coveralls-python-action@develop - with: - parallel: true - flag-name: Unit Test - - coveralls_finish: - needs: build - runs-on: ubuntu-latest - steps: - - name: Coveralls Finished - uses: AndreMiras/coveralls-python-action@develop - with: - parallel-finished: true + run: | + coverage run -m pytest + coverage xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 From 4891b2ffaa9fbcaba788d54ec3efec031b189460 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Wed, 20 Apr 2022 15:43:07 +0530 Subject: [PATCH 6/6] feat: add correct badge --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index d5597ca0..41b62178 100644 --- a/README.rst +++ b/README.rst @@ -11,8 +11,8 @@ json2xml .. image:: https://readthedocs.org/projects/json2xml/badge/?version=latest :target: https://json2xml.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status -.. image:: https://coveralls.io/repos/github/vinitkumar/json2xml/badge.svg?branch=master - :target: https://coveralls.io/github/vinitkumar/json2xml?branch=master +.. image:: https://codecov.io/gh/vinitkumar/json2xml/branch/master/graph/badge.svg?token=Yt2h55eTL2 + :target: https://codecov.io/gh/vinitkumar/json2xml Simple Python Library to convert JSON to XML