55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
from trainmap_backup import \
|
|
camel_to_snake, transform_dict, RETAIN_KEY, RETAIN_VALUE, DISCARD, \
|
|
JsonRoundingFloat, JsonLonLatCoord, json_encode
|
|
|
|
|
|
def test_camel_to_snake():
|
|
assert camel_to_snake("testcase") == "testcase"
|
|
assert camel_to_snake("test_case") == "test_case"
|
|
assert camel_to_snake("Testcase") == "testcase"
|
|
assert camel_to_snake("TestCase") == "test_case"
|
|
assert camel_to_snake("AnotherTestCase") == "another_test_case"
|
|
assert camel_to_snake("Test_Case") == "test__case"
|
|
|
|
|
|
def test_transform_dict():
|
|
assert transform_dict(
|
|
{
|
|
"discard": DISCARD,
|
|
"otherkey": ("newkey", RETAIN_VALUE),
|
|
"uppervalue": (RETAIN_KEY, str.upper),
|
|
"retainboth": (RETAIN_KEY, RETAIN_VALUE)
|
|
},
|
|
{
|
|
"discard": True,
|
|
"passthrough": True,
|
|
"otherkey": True,
|
|
"uppervalue": "value",
|
|
"retainboth": "value",
|
|
}
|
|
) == {
|
|
"passthrough": True,
|
|
"newkey": True,
|
|
"uppervalue": "VALUE",
|
|
"retainboth": "value",
|
|
}
|
|
|
|
|
|
def test_JsonRoundingFloat():
|
|
assert str(JsonRoundingFloat(1.1234567890123456789012345678901234567890, 2)) == "1.12"
|
|
assert str(JsonRoundingFloat(1.1234567890123456789012345678901234567890, 3)) == "1.123"
|
|
assert str(JsonRoundingFloat(1.1, 3)) == "1.1"
|
|
|
|
|
|
def test_JsonLonLatCoord():
|
|
assert str(JsonLonLatCoord(1.1234567890123456789012345678901234567890, 50.1234)) == \
|
|
"[1.123457, 50.1234]"
|
|
|
|
|
|
def test_json_encode():
|
|
assert json_encode(JsonLonLatCoord(1, 2)) == "[1, 2]"
|
|
assert json_encode([
|
|
JsonLonLatCoord(1, 2),
|
|
JsonLonLatCoord(3, 4),
|
|
]) == "[[1, 2], [3, 4]]"
|