-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tests/decoding_test.py to use the format used by the current version of toml-test. I also removed Python 2 support (my distro doesn't ship it, so I can't test it). Also add tests/encoding_test.py for encoder tests Still quite a few failures, mostly because it looks like it hasn't been updated to use 1.0 yet: % toml-test ./decoding_test.py | tail -n2 valid tests: 139 passed, 18 failed invalid tests: 230 passed, 53 failed % toml-test ./encoding_test.py -encoder | tail -n1 encoder tests: 146 passed, 11 failed
- Loading branch information
Showing
5 changed files
with
50 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,20 +22,20 @@ jobs: | |
with: | ||
go-version: 1.21 | ||
|
||
- name: get toml-test | ||
- name: install toml-test | ||
run: | | ||
git clone https://github.com/BurntSushi/toml-test | ||
# cd toml-test/cmd/toml-test | ||
# go build | ||
go install github.com/toml-lang/toml-test/cmd/[email protected] | ||
- name: Run python tests | ||
run: | | ||
pip -q install "tox>=4" | ||
tox run-parallel --parallel-no-spinner | ||
# TODO(warchant): this cmd is old, need to update it | ||
# TODO(warchant): many tests fail | ||
# - name: Run go tests | ||
# run: | | ||
# pip -q install setuptools | ||
# python setup.py install | ||
# ./toml-test/cmd/toml-test/toml-test -i ./tests -g ./tests/gotests.sh | ||
# export PYTHONPATH=. | ||
# e=0 | ||
# toml-test ./tests/decoding_test.py || e=1 | ||
# toml-test -encoder ./tests/encoding_test.py || e=1 | ||
# exit $e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Reads tagged JSON and encodes it as TOML""" | ||
|
||
import json | ||
import sys | ||
import toml | ||
|
||
def convert(v): | ||
if type(v) == list: | ||
return [convert(vv) for vv in v] | ||
elif v.get('type', None) is None or v.get('value', None) is None: | ||
return {k: convert(vv) for (k, vv) in v.items()} | ||
elif v['type'] == 'string': | ||
return v['value'] | ||
elif v['type'] == 'integer': | ||
return int(v['value']) | ||
elif v['type'] == 'float': | ||
return float(v['value']) | ||
elif v['type'] == 'bool': | ||
return True if v['value'] == 'true' else False | ||
elif v['type'] in ['datetime', 'datetime-local', 'date-local', 'time-local']: | ||
return toml.loads('a=' + v['value'])['a'] | ||
else: | ||
raise Exception(f'unknown type: {v}') | ||
|
||
j = json.loads(sys.stdin.read()) | ||
print(toml.dumps({k: convert(v) for (k, v) in j.items()})) |