Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "tests/toml-test"]
path = tests/toml-test
url = https://github.com/BurntSushi/toml-test.git
[submodule "tests/toml-spec-tests"]
path = tests/toml-spec-tests
url = https://github.com/iarna/toml-spec-tests.git
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [unreleased]

### Changed

- Update parser to support TOML spec v1.1.0. ([#456](https://github.com/python-poetry/tomlkit/pull/456)

## [0.14.0] - 2026-01-13

### Changed
Expand Down
64 changes: 0 additions & 64 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,67 +39,3 @@ def _example(name):
return f.read()

return _example


TEST_DIR = os.path.join(os.path.dirname(__file__), "toml-test", "tests")
IGNORED_TESTS = {
"valid": [
"float/inf-and-nan", # Can't compare nan
]
}


def get_tomltest_cases():
dirs = sorted(
f for f in os.listdir(TEST_DIR) if os.path.isdir(os.path.join(TEST_DIR, f))
)
assert dirs == ["invalid", "valid"]
rv = {"invalid_encode": {}}
for d in dirs:
rv[d] = {}
ignored = IGNORED_TESTS.get(d, [])

for root, _, files in os.walk(os.path.join(TEST_DIR, d)):
relpath = os.path.relpath(root, os.path.join(TEST_DIR, d))
if relpath == ".":
relpath = ""
for f in files:
try:
bn, ext = f.rsplit(".", 1)
except ValueError:
bn, ext = f.rsplit("-", 1)
key = f"{relpath}/{bn}"
if ext == "multi":
continue
if key in ignored:
continue
if d == "invalid" and relpath == "encoding":
rv["invalid_encode"][bn] = os.path.join(root, f)
continue
if key not in rv[d]:
rv[d][key] = {}
with open(os.path.join(root, f), encoding="utf-8") as inp:
rv[d][key][ext] = inp.read()
return rv


def pytest_generate_tests(metafunc):
test_list = get_tomltest_cases()
if "valid_case" in metafunc.fixturenames:
metafunc.parametrize(
"valid_case",
test_list["valid"].values(),
ids=list(test_list["valid"].keys()),
)
elif "invalid_decode_case" in metafunc.fixturenames:
metafunc.parametrize(
"invalid_decode_case",
test_list["invalid"].values(),
ids=list(test_list["invalid"].keys()),
)
elif "invalid_encode_case" in metafunc.fixturenames:
metafunc.parametrize(
"invalid_encode_case",
test_list["invalid_encode"].values(),
ids=list(test_list["invalid_encode"].keys()),
)
1 change: 0 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def test_parsed_document_are_properly_json_representable(
("inline_table_no_comma", UnexpectedCharError),
("inline_table_duplicate_comma", UnexpectedCharError),
("inline_table_leading_comma", UnexpectedCharError),
("inline_table_trailing_comma", UnexpectedCharError),
],
)
def test_parse_raises_errors_for_invalid_toml_files(
Expand Down
111 changes: 0 additions & 111 deletions tests/test_toml_spec_tests.py

This file was deleted.

88 changes: 80 additions & 8 deletions tests/test_toml_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os

import pytest

Expand All @@ -9,6 +10,10 @@
from tomlkit.exceptions import TOMLKitError


TESTS_ROOT = os.path.join(os.path.dirname(__file__), "toml-test", "tests")
FILES_LIST = os.path.join(TESTS_ROOT, "files-toml-1.1.0")


def to_bool(s):
assert s in ["true", "false"]

Expand Down Expand Up @@ -43,20 +48,87 @@ def untag(value):
return {k: untag(v) for k, v in value.items()}


def test_valid_decode(valid_case):
json_val = untag(json.loads(valid_case["json"]))
toml_val = parse(valid_case["toml"])
def _load_case_list():
with open(FILES_LIST, encoding="utf-8") as f:
return [line.strip() for line in f if line.strip()]


def _build_cases():
valid_cases = []
valid_ids = []
invalid_decode_cases = []
invalid_decode_ids = []
invalid_encode_cases = []
invalid_encode_ids = []

for relpath in _load_case_list():
full_path = os.path.join(TESTS_ROOT, relpath)
if not relpath.endswith(".toml"):
continue

case_id = relpath.rsplit(".", 1)[0]

if relpath.startswith("invalid/encoding/"):
invalid_encode_cases.append(full_path)
invalid_encode_ids.append(case_id)
elif relpath.startswith("valid/"):
with open(full_path, encoding="utf-8", newline="") as f:
toml_content = f.read()

json_path = full_path.rsplit(".", 1)[0] + ".json"
with open(json_path, encoding="utf-8") as f:
json_content = f.read()

valid_cases.append({"toml": toml_content, "json": json_content})
valid_ids.append(case_id)
elif relpath.startswith("invalid/"):
with open(full_path, encoding="utf-8", newline="") as f:
toml_content = f.read()

invalid_decode_cases.append({"toml": toml_content})
invalid_decode_ids.append(case_id)

return (
valid_cases,
valid_ids,
invalid_decode_cases,
invalid_decode_ids,
invalid_encode_cases,
invalid_encode_ids,
)


(
VALID_CASES,
VALID_IDS,
INVALID_DECODE_CASES,
INVALID_DECODE_IDS,
INVALID_ENCODE_CASES,
INVALID_ENCODE_IDS,
) = _build_cases()


@pytest.mark.parametrize("toml11_valid_case", VALID_CASES, ids=VALID_IDS)
def test_valid_decode(toml11_valid_case):
json_val = untag(json.loads(toml11_valid_case["json"]))
toml_val = parse(toml11_valid_case["toml"])

assert toml_val == json_val
assert toml_val.as_string() == valid_case["toml"]
assert toml_val.as_string() == toml11_valid_case["toml"]


def test_invalid_decode(invalid_decode_case):
@pytest.mark.parametrize(
"toml11_invalid_decode_case", INVALID_DECODE_CASES, ids=INVALID_DECODE_IDS
)
def test_invalid_decode(toml11_invalid_decode_case):
with pytest.raises(TOMLKitError):
parse(invalid_decode_case["toml"])
parse(toml11_invalid_decode_case["toml"])


def test_invalid_encode(invalid_encode_case):
with open(invalid_encode_case, encoding="utf-8") as f:
@pytest.mark.parametrize(
"toml11_invalid_encode_case", INVALID_ENCODE_CASES, ids=INVALID_ENCODE_IDS
)
def test_invalid_encode(toml11_invalid_encode_case):
with open(toml11_invalid_encode_case, encoding="utf-8") as f:
with pytest.raises((TOMLKitError, UnicodeDecodeError)):
load(f)
3 changes: 0 additions & 3 deletions tests/toml-spec-tests/.gitattributes

This file was deleted.

14 changes: 0 additions & 14 deletions tests/toml-spec-tests/LICENSE

This file was deleted.

14 changes: 0 additions & 14 deletions tests/toml-spec-tests/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions tests/toml-spec-tests/errors/array-of-tables-1.toml

This file was deleted.

10 changes: 0 additions & 10 deletions tests/toml-spec-tests/errors/array-of-tables-2.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/toml-spec-tests/errors/bare-key-1.toml

This file was deleted.

2 changes: 0 additions & 2 deletions tests/toml-spec-tests/errors/bare-key-2.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/toml-spec-tests/errors/bare-key-3.toml

This file was deleted.

Binary file removed tests/toml-spec-tests/errors/comment-control-1.toml
Binary file not shown.
1 change: 0 additions & 1 deletion tests/toml-spec-tests/errors/comment-control-2.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/toml-spec-tests/errors/comment-control-3.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/toml-spec-tests/errors/comment-control-4.toml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/toml-spec-tests/errors/inline-table-imutable-1.toml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/toml-spec-tests/errors/inline-table-imutable-2.toml

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tests/toml-spec-tests/errors/int-0-padded.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/toml-spec-tests/errors/int-signed-bin.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/toml-spec-tests/errors/int-signed-hex.toml

This file was deleted.

Loading
Loading