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..a487a118 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -36,9 +36,13 @@ 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 - - name: Test with pytest + - name: Unit tests run: | - pytest + coverage run -m pytest + coverage xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 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 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 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 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")