Comments (1)
Code from the gists for inspection, so you don't have to download random untrusted .py files:
test_bug_148_original.py
r""" Commands to reproduce:
python -m venv test_bug_148
Posix: source test_bug_148/bin.activate.sh
Windows: .\test_bug_148\Scripts\activate.bat
pip install pytest toml tomli tomli-w tomlkit toml_tools
pytest --tb=no -rA -q test_bug_148_original.py
Expected on Windows 10 Python 3.12:
F.FFFFFFF [100%]
======================================================================== short test summary info ========================================================================
PASSED test_bug_148_original.py::test_bug_148_toml
FAILED test_bug_148_original.py::test_inverse_bug_148_toml - AssertionError: assert {'a': 'd'} == {'a': '\\x64'}
FAILED test_bug_148_original.py::test_inverse_bug_148_tomllib - AssertionError: assert {'a': 'd'} == {'a': '\\x64'}
FAILED test_bug_148_original.py::test_inverse_bug_148_tomli - AssertionError: assert {'a': 'd'} == {'a': '\\x64'}
FAILED test_bug_148_original.py::test_inverse_bug_148_tomlkit - AssertionError: assert {'a': 'd'} == {'a': '\\x64'}
FAILED test_bug_148_original.py::test_inverse_bug_148_toml_tools - AssertionError: assert {'a': 'd'} == {'a': '\\x64'}
FAILED test_bug_148_original.py::test_bug_148_tomli_w - assert 'a = "\\u0064"\n' == 'a = "\\\\x64"\n'
FAILED test_bug_148_original.py::test_bug_148_tomlkit - assert 'a = "\\u0064"\n' == 'a = "\\\\x64"\n'
FAILED test_bug_148_original.py::test_bug_148_toml_tools - assert 'a = "\\u0064"\n' == 'a = "\\\\x64"\n'
8 failed, 1 passed in 0.11s
"""
import sys
if sys.version_info >= (3,11):
import tomllib
import tomli
import tomli_w
import tomlkit
import toml
import toml_tools
def make_bug_148_test_function(toml_module):
def test_bug_148():
assert 'a = "\\u0064"\n' == toml_module.dumps({'a': '\\x64'})
assert 'a = "\\\\x64"\n' == toml_module.dumps({'a': '\\\\x64'})
assert 'a = "\\\\\\u0064"\n' == toml_module.dumps({'a': '\\\\\\x64'})
return test_bug_148
def make_inverse_bug_148_test_function(toml_module):
def test_bug_148_inverse():
assert toml_module.loads('a = "\\u0064"\n') == {'a': '\\x64'}
assert toml_module.loads('a = "\\\\x64"\n') == {'a': '\\\\x64'}
assert toml_module.loads('a = "\\\\\\u0064"\n') == {'a': '\\\\\\x64'}
return test_bug_148_inverse
test_inverse_bug_148_toml = make_inverse_bug_148_test_function(toml)
test_bug_148_toml = make_bug_148_test_function(toml)
# native in Python 3.11
try:
test_inverse_bug_148_tomllib = make_inverse_bug_148_test_function(tomllib)
except NameError:
pass
test_inverse_bug_148_tomli = make_inverse_bug_148_test_function(tomli)
test_inverse_bug_148_tomlkit = make_inverse_bug_148_test_function(tomlkit)
test_inverse_bug_148_toml_tools = make_inverse_bug_148_test_function(toml_tools)
test_bug_148_tomli_w = make_bug_148_test_function(tomli_w)
test_bug_148_tomlkit = make_bug_148_test_function(tomlkit)
test_bug_148_toml_tools = make_bug_148_test_function(toml_tools)
test_bug_148_fixed.py
r""" Commands to reproduce:
python -m venv test_bug_148
Posix: source test_bug_148/bin.activate.sh
Windows: .\test_bug_148\Scripts\activate.bat
pip install pytest toml tomli tomli-w tomlkit toml_tools
pytest --tb=no -rA -q test_bug_148_fixed.py
Expected on Windows 10 Python 3.12:
.F....... [100%]
======================================================================== short test summary info ========================================================================
PASSED test_bug_148_correctly.py::test_inverse_bug_148_toml
PASSED test_bug_148_correctly.py::test_inverse_bug_148_tomllib
PASSED test_bug_148_correctly.py::test_inverse_bug_148_tomli
PASSED test_bug_148_correctly.py::test_inverse_bug_148_tomlkit
PASSED test_bug_148_correctly.py::test_inverse_bug_148_toml_tools
PASSED test_bug_148_correctly.py::test_bug_148_tomli_w
PASSED test_bug_148_correctly.py::test_bug_148_tomlkit
PASSED test_bug_148_correctly.py::test_bug_148_toml_tools
FAILED test_bug_148_correctly.py::test_bug_148_toml - assert 'a = "\\\\x64"\n' == 'a = "\\u0064"\n'
1 failed, 8 passed in 0.13s
"""
import sys
if sys.version_info >= (3,11):
import tomllib
import tomli
import tomli_w
import tomlkit
import toml
import toml_tools
def make_correct_bug_148_test_function(toml_module):
def test_bug_148():
assert r'a = "\\x64"' + '\n' == toml_module.dumps({'a': r'\x64'})
assert r'a = "\\\\x64"' + '\n' == toml_module.dumps({'a': r'\\x64'})
assert r'a = "\\\\\\x64"' + '\n' == toml_module.dumps({'a': r'\\\x64'})
# original from
# assert 'a = "\\u0064"\n' == toml_module.dumps({'a': '\\x64'})
# assert 'a = "\\\\x64"\n' == toml_module.dumps({'a': '\\\\x64'})
# assert 'a = "\\\\\\u0064"\n' == toml_module.dumps({'a': '\\\\\\x64'})
return test_bug_148
def make_correct_inverse_bug_148_test_function(toml_module):
def test_bug_148_inverse():
assert toml_module.loads(r'a = "\\x64"' + '\n') == {'a': r'\x64'}
assert toml_module.loads(r'a = "\\\\x64"' + '\n') == {'a': r'\\x64'}
assert toml_module.loads(r'a = "\\\\\\x64"' + '\n') == {'a': r'\\\x64'}
return test_bug_148_inverse
test_inverse_bug_148_toml = make_correct_inverse_bug_148_test_function(toml)
test_bug_148_toml = make_correct_bug_148_test_function(toml)
# native in Python 3.11
try:
test_inverse_bug_148_tomllib = make_correct_inverse_bug_148_test_function(tomllib)
except NameError:
pass
test_inverse_bug_148_tomli = make_correct_inverse_bug_148_test_function(tomli)
test_inverse_bug_148_tomlkit = make_correct_inverse_bug_148_test_function(tomlkit)
test_inverse_bug_148_toml_tools = make_correct_inverse_bug_148_test_function(toml_tools)
test_bug_148_tomli_w = make_correct_bug_148_test_function(tomli_w)
test_bug_148_tomlkit = make_correct_bug_148_test_function(tomlkit)
test_bug_148_toml_tools = make_correct_bug_148_test_function(toml_tools)
from toml.
Related Issues (20)
- Roundtripping inlined tables with `'000..'` fails.. HOT 3
- Why is there a "dynamic inline table" when you normally want a static type to do dumping? HOT 1
- Continuous fuzzing by way of OSS-Fuzz
- Inline tables with inf/nan as values fail to parse HOT 1
- Backslash roundtrip problem HOT 5
- toml.load(path) no directory found HOT 1
- Loaded datetimes with timezone offset cannot be pickled correctly HOT 2
- cannot encode non-string keys HOT 1
- Cannot roundtrip strings with \x in them HOT 3
- keygroup with empty name is allowed in particular formatting, but not in what toml.dump creates. HOT 1
- Toml decoder is trying to convert IP address string to float HOT 3
- Default TomlEncoder does not escape backslashes correctly
- list object of compound type could not be parsed HOT 1
- New lines in multi-line strings trimmed incorrectly
- dump breaks numpy.str_ into lists of characters HOT 1
- TomlDecodeError: Loading with multiple dictionaries within a dictionary. HOT 1
- Does `toml` not implemente the `TOML` v1.0.0? HOT 1
- Dump Multiline string to toml file HOT 1
- toml.dump turns my strings into arrays HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from toml.