From 881eb5544e9c33724d155d796f534794c9505105 Mon Sep 17 00:00:00 2001 From: Spencer Young Date: Sat, 31 Jul 2021 20:15:24 -0700 Subject: [PATCH 1/5] add test for regular dump of spec files --- tests/test_json5_official_tests.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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: From ef2c8cedb3d15f3cd45a7b3d206ac314dfa55319 Mon Sep 17 00:00:00 2001 From: Spencer Young Date: Sat, 31 Jul 2021 20:16:33 -0700 Subject: [PATCH 2/5] allow dumping of identifiers --- json5/dumper.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) 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): From 43390cd427d8d902fe3af4a3abbdbd66d5f8bda3 Mon Sep 17 00:00:00 2001 From: Spencer Young Date: Sat, 31 Jul 2021 20:29:05 -0700 Subject: [PATCH 3/5] add github actions --- .github/workflows/unittests.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/unittests.yml diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml new file mode 100644 index 0000000..2cd92ba --- /dev/null +++ b/.github/workflows/unittests.yml @@ -0,0 +1,26 @@ +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 + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} From cfe748c001389b73c5ea1efa145c7885681e6864 Mon Sep 17 00:00:00 2001 From: Spencer Young Date: Sat, 31 Jul 2021 20:32:17 -0700 Subject: [PATCH 4/5] coveralls step --- .github/workflows/unittests.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 2cd92ba..d7c94b2 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -21,6 +21,8 @@ jobs: coverage run -m pytest tests - name: Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + pip install --upgrade coveralls + coveralls --service=github From d50b2ed3c1feb6d5b7fdca3e9d7b65edf46646c0 Mon Sep 17 00:00:00 2001 From: Spencer Young Date: Sat, 31 Jul 2021 20:34:44 -0700 Subject: [PATCH 5/5] remove travis --- .travis.yml | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .travis.yml 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