Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table.update(TOMLDocument) is missing a nesting level #230

Closed
thvitt opened this issue Aug 20, 2022 · 0 comments · Fixed by #234
Closed

Table.update(TOMLDocument) is missing a nesting level #230

thvitt opened this issue Aug 20, 2022 · 0 comments · Fixed by #234
Labels
bug Something isn't working

Comments

@thvitt
Copy link

thvitt commented Aug 20, 2022

Trying to update a Table entry from a TOMLDocument should insert the top-level entries of the document into the table entry, however it inserts them at the top level. Test case:

import tomlkit
import tomli


def test_parsed_subentry():
    example = "[entry]\nfoo = 'bar'"
    subentry = "bar = 23\n\n[subentry]\n'subkey' = 'subvalue'"

    doc_tomlkit = tomlkit.loads(example)
    doc_tomli = tomlkit.loads(example)

    doc_tomlkit["entry"].update(tomlkit.loads(subentry))
    doc_tomli["entry"].update(tomli.loads(subentry))

    doc_tomlkit_output = tomlkit.dumps(doc_tomlkit)
    doc_tomli_output = tomlkit.dumps(doc_tomli)

    print("## Inserted tomli-parsed subentry ##", doc_tomli_output, sep="\n")
    print("## Inserted tomlkit-parsed subentry ##", doc_tomlkit_output, sep="\n")

    assert tomli.loads(doc_tomlkit_output) == tomli.loads(doc_tomli_output)

Output:

## Inserted tomli-parsed subentry ##
[entry]
foo = 'bar'
bar = 23

[entry.subentry]
subkey = "subvalue"

## Inserted tomlkit-parsed subentry ##
[entry]
foo = 'bar'
bar = 23

[subentry]
'subkey' = 'subvalue'
@frostming frostming added the bug Something isn't working label Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants