-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unwrap method to recursive convert to plain old python objects (#187
) * add as_ppo method for elementary types * rename as_popo to unwrap; add recursive arg * add unwrap methods to collection types + Null * remove dangling 'def' * Container loops through items() instead of _body * add Integer and Item unit tests * added passing tests for everything up to Array * remove recursive option * remove unused is_ppo function * refactor Container unwrap to reuse code * add AbstractTable test * add string, null, and aot tests * add test for Container * type(..) to isinstance(..) in Container unwrap * try/catch ensure v has unwrap in Container.unwrap * replace 'type' with 'isinstance' in test_items.py * refactor assert_is_ppo to pass only ppo type * refactory test_document_is_a_dict to not call 'type' * remove elementary_fail function * minor change in Container unwrap method * use isinstance not is_tomlkit in AoT.unwrap * run pre-commit
- Loading branch information
Showing
6 changed files
with
290 additions
and
0 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
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,57 @@ | ||
from tomlkit.items import AoT | ||
from tomlkit.items import Array | ||
from tomlkit.items import Bool | ||
from tomlkit.items import Comment | ||
from tomlkit.items import Date | ||
from tomlkit.items import DateTime | ||
from tomlkit.items import Float | ||
from tomlkit.items import InlineTable | ||
from tomlkit.items import Integer | ||
from tomlkit.items import Item | ||
from tomlkit.items import KeyType | ||
from tomlkit.items import Null | ||
from tomlkit.items import SingleKey as Key | ||
from tomlkit.items import String | ||
from tomlkit.items import StringType | ||
from tomlkit.items import Table | ||
from tomlkit.items import Time | ||
from tomlkit.items import Trivia | ||
from tomlkit.toml_document import TOMLDocument | ||
|
||
|
||
TOMLKIT_TYPES = [ | ||
Bool, | ||
Comment, | ||
InlineTable, | ||
Integer, | ||
Float, | ||
DateTime, | ||
Date, | ||
Time, | ||
Array, | ||
KeyType, | ||
Key, | ||
String, | ||
StringType, | ||
Table, | ||
Trivia, | ||
Item, | ||
AoT, | ||
Null, | ||
TOMLDocument, | ||
] | ||
|
||
|
||
def assert_not_tomlkit_type(v): | ||
for i, T in enumerate(TOMLKIT_TYPES): | ||
assert not isinstance(v, T) | ||
|
||
|
||
def assert_is_ppo(v_unwrapped, unwrappedType): | ||
assert_not_tomlkit_type(v_unwrapped) | ||
assert isinstance(v_unwrapped, unwrappedType) | ||
|
||
|
||
def elementary_test(v, unwrappedType): | ||
v_unwrapped = v.unwrap() | ||
assert_is_ppo(v_unwrapped, unwrappedType) |
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,12 @@ | ||
def is_tomlkit(v): | ||
from .container import Container | ||
from .container import OutOfOrderTableProxy | ||
from .items import Item as _Item | ||
|
||
if isinstance(v, _Item): | ||
return True | ||
if isinstance(v, Container): | ||
return True | ||
if isinstance(v, OutOfOrderTableProxy): | ||
return True | ||
return False |
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
Oops, something went wrong.