diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml new file mode 100644 index 0000000..d7c94b2 --- /dev/null +++ b/.github/workflows/unittests.yml @@ -0,0 +1,28 @@ +on: [ push, pull_request ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.9 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install sly coverage regex pytest + + - name: Test with coverage/pytest + run: | + coverage run -m pytest tests + + - name: Coveralls + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + pip install --upgrade coveralls + coveralls --service=github diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5ebec80..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: python - - -python: - - "3.6" - - "3.7" - - "3.8" - -install: - - pip install sly regex coverage coveralls - - git clone https://github.com/spyoungtech/json5-tests.git - -script: - - coverage run -m pytest tests - -after_success: - - coveralls diff --git a/json5/dumper.py b/json5/dumper.py index ee2b340..f8b98f7 100644 --- a/json5/dumper.py +++ b/json5/dumper.py @@ -1,3 +1,4 @@ +from .loader import JsonIdentifier from .utils import singledispatchmethod from json5.model import * from collections import UserDict @@ -80,24 +81,26 @@ def dict_to_json(self, d): @to_json(int) def int_to_json(self, i): self.env.write(str(i), indent=0) - + + @to_json(JsonIdentifier) + def identifier_to_json(self, s): + if isinstance(s, JsonIdentifier): + quote_char = None + elif "'" in s: + quote_char = '"' + else: + quote_char = "'" + + if quote_char: + self.env.write(quote_char, indent=0) + self.env.write(s, indent=0) + if quote_char: + self.env.write(quote_char, indent=0) @to_json(str) def str_to_json(self, s): self.env.write(json.dumps(s), indent=0) - # if isinstance(s, JsonIdentifier): - # quote_char = None - # elif "'" in s: - # quote_char = '"' - # else: - # quote_char = "'" - # - # if quote_char: - # self.env.write(quote_char, indent=0) - # self.env.write(s, indent=0) - # if quote_char: - # self.env.write(quote_char, indent=0) - + @to_json(list) def list_to_json(self, l): diff --git a/tests/test_json5_official_tests.py b/tests/test_json5_official_tests.py index a359fd3..bc4e978 100644 --- a/tests/test_json5_official_tests.py +++ b/tests/test_json5_official_tests.py @@ -27,7 +27,15 @@ def test_official_files(fp): load(open(fp, encoding='utf-8')) @pytest.mark.parametrize('fp', specs) -def test_official_files_rt(fp): +def test_official_files_rt_dumps_no_error(fp): + if not os.path.exists(tests_path): + pytest.mark.skip("Tests repo was not present in expected location. Skipping.") + with open(fp, encoding='utf-8') as f: + json_string = f.read() + dumps(loads(json_string)) + +@pytest.mark.parametrize('fp', specs) +def test_official_files_rt_model(fp): if not os.path.exists(tests_path): pytest.mark.skip("Tests repo was not present in expected location. Skipping.") with open(fp, encoding='utf-8') as f: