Skip to content

Commit

Permalink
replace most calls to 'type' with 'isinstance' in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
syntapy committed May 20, 2022
1 parent 21ec17b commit 1712acc
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from tomlkit.items import Table
from tomlkit.items import Trivia
from tomlkit.items import Item
from tomlkit.items import AoT
from tomlkit.items import item
from tomlkit.items import Null
from tomlkit.parser import Parser
Expand Down Expand Up @@ -88,15 +89,16 @@ def test_item_base_has_no_unwrap():
raise AssertionError("`items.Item` should not implement `unwrap`")

def assert_is_ppo(v_unwrapped, TomlkitType, unwrappedType):
assert type(v_unwrapped) != TomlkitType
assert type(v_unwrapped) == unwrappedType
assert not isinstance(v_unwrapped, TomlkitType)
assert isinstance(v_unwrapped, unwrappedType)

def elementary_test(v, TomlkitType, unwrappedType):
v_unwrapped = v.unwrap()
assert type(v) == TomlkitType
assert type(v) != unwrappedType
assert isinstance(v, TomlkitType)
assert_is_ppo(v_unwrapped, TomlkitType, unwrappedType)

# a check thats designed to fail to make sure the tests works
# TODO Remove before merge (maybe?)
def elementary_fail(v, TomlkitType, unwrappedType):
v_unwrapped = v.unwrap()
assert type(v) == TomlkitType
Expand Down Expand Up @@ -124,13 +126,15 @@ def test_aot_unwrap():
d = item([{"a": "A"}, {"b": "B"}])
assert is_tomlkit(d)
unwrapped = d.unwrap()
assert type(unwrapped) == list
for de in unwrapped:
assert type(de) == dict
for k in de:
v = de[k]
assert type(k) == str
assert type(v) == str
assert isinstance(unwrapped, list)
assert not isinstance(unwrapped, AoT)
for du, dw in zip(unwrapped, d):
assert isinstance(du, dict)
assert not isinstance(du, type(dw))
for ku in du:
vu = du[ku]
assert type(ku) == str
assert type(vu) == str

def test_time_unwrap():
t=time(3, 8, 14)
Expand All @@ -145,7 +149,7 @@ def test_array_unwrap():
b=item(False)
a=Array([i, f, b], trivia)
a_unwrapped=a.unwrap()
assert type(a_unwrapped) == list
assert_is_ppo(a_unwrapped, Array, list)
assert_is_ppo(a_unwrapped[0], Integer, int)
assert_is_ppo(a_unwrapped[1], Float, float)
assert_is_ppo(a_unwrapped[2], Bool, bool)
Expand All @@ -155,12 +159,13 @@ def test_abstract_table_unwrap():
assert is_tomlkit(super_table["table"])

table_unwrapped = super_table.unwrap()
assert type(table_unwrapped) == dict
sub_table = table_unwrapped["table"]
assert type(sub_table) == dict
for (k, v) in zip(sub_table.keys(), sub_table):
assert type(k) == str
assert type(v) == str
assert_is_ppo(table_unwrapped, Table, dict)
assert_is_ppo(sub_table, Table, dict)
for ku in sub_table:
vu = sub_table[ku]
assert type(ku) == str
assert type(vu) == str

def test_key_comparison():
k = Key("foo")
Expand Down

0 comments on commit 1712acc

Please sign in to comment.