Skip to content

Commit

Permalink
test: arrange tests alphabetically by format
Browse files Browse the repository at this point in the history
  • Loading branch information
dbohdan committed Nov 14, 2024
1 parent e5bba1a commit b68844f
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions tests/test_remarshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ def convert_and_read(tmp_path):


class TestRemarshal:
def test_cbor2cbor(self, convert_and_read) -> None:
output = convert_and_read("example.cbor", "cbor", "cbor")
reference = read_file("example.cbor")
assert_cbor_same(output, reference)

def test_json2json(self, convert_and_read) -> None:
output = convert_and_read("example.json", "json", "json")
reference = read_file("example.json")
Expand All @@ -159,43 +164,38 @@ def test_yaml2yaml(self, convert_and_read) -> None:
reference = read_file("example.yaml")
assert output == reference

def test_cbor2cbor(self, convert_and_read) -> None:
output = convert_and_read("example.cbor", "cbor", "cbor")
reference = read_file("example.cbor")
assert_cbor_same(output, reference)

def test_json2msgpack(self, convert_and_read) -> None:
def test_json2cbor(self, convert_and_read) -> None:
def patch(x: Any) -> Any:
x["owner"]["dob"] = datetime.datetime(
1979, 5, 27, 7, 32, tzinfo=datetime.timezone.utc
1979, 5, 27, 7, 32, 0, 0, datetime.timezone.utc
)
return x

output = convert_and_read(
"example.json",
"json",
"msgpack",
"cbor",
transform=patch,
)
reference = read_file("example.msgpack")
assert output == reference

def test_json2cbor(self, convert_and_read) -> None:
reference = read_file("example.cbor")
assert_cbor_same(output, reference)

def test_json2msgpack(self, convert_and_read) -> None:
def patch(x: Any) -> Any:
x["owner"]["dob"] = datetime.datetime(
1979, 5, 27, 7, 32, 0, 0, datetime.timezone.utc
1979, 5, 27, 7, 32, tzinfo=datetime.timezone.utc
)
return x

output = convert_and_read(
"example.json",
"json",
"cbor",
"msgpack",
transform=patch,
)

reference = read_file("example.cbor")
assert_cbor_same(output, reference)
reference = read_file("example.msgpack")
assert output == reference

def test_json2toml(self, convert_and_read) -> None:
output = convert_and_read("example.json", "json", "toml").decode("utf-8")
Expand All @@ -216,6 +216,15 @@ def test_json2yaml(self, convert_and_read) -> None:
)
assert output == reference_patched

def test_msgpack2cbor(self, convert_and_read) -> None:
output = convert_and_read(
"example.msgpack",
"msgpack",
"cbor",
)
reference = read_file("example.cbor")
assert_cbor_same(output, reference)

def test_msgpack2json(self, convert_and_read) -> None:
output = convert_and_read("example.msgpack", "msgpack", "json", stringify=True)
reference = read_file("example.json")
Expand All @@ -231,10 +240,10 @@ def test_msgpack2yaml(self, convert_and_read) -> None:
reference = read_file("example.yaml")
assert output == reference

def test_msgpack2cbor(self, convert_and_read) -> None:
def test_toml2cbor(self, convert_and_read) -> None:
output = convert_and_read(
"example.msgpack",
"msgpack",
"example.toml",
"toml",
"cbor",
)
reference = read_file("example.cbor")
Expand All @@ -259,10 +268,10 @@ def test_toml2yaml(self, convert_and_read) -> None:
reference = read_file("example.yaml")
assert output == reference

def test_toml2cbor(self, convert_and_read) -> None:
def test_yaml2cbor(self, convert_and_read) -> None:
output = convert_and_read(
"example.toml",
"toml",
"example.yaml",
"yaml",
"cbor",
)
reference = read_file("example.cbor")
Expand All @@ -287,20 +296,20 @@ def test_yaml2toml(self, convert_and_read) -> None:
reference = read_file("example.toml")
assert toml_signature(output) == toml_signature(reference)

def test_yaml2cbor(self, convert_and_read) -> None:
output = convert_and_read(
"example.yaml",
"yaml",
"cbor",
)
reference = read_file("example.cbor")
assert_cbor_same(output, reference)

def test_cbor2json(self, convert_and_read) -> None:
output = convert_and_read("example.cbor", "cbor", "json", stringify=True)
reference = read_file("example.json")
assert output == reference

def test_cbor2msgpack(self, convert_and_read) -> None:
output = convert_and_read(
"example.cbor",
"cbor",
"msgpack",
)
reference = read_file("example.msgpack")
assert output == reference

def test_cbor2toml(self, convert_and_read) -> None:
output = convert_and_read("example.cbor", "cbor", "toml")
reference = read_file("example.toml")
Expand All @@ -313,15 +322,6 @@ def test_cbor2yaml(self, convert_and_read) -> None:
reference = read_file("example.yaml")
assert output == reference

def test_cbor2msgpack(self, convert_and_read) -> None:
output = convert_and_read(
"example.cbor",
"cbor",
"msgpack",
)
reference = read_file("example.msgpack")
assert output == reference

def test_missing_wrap(self, convert_and_read) -> None:
with pytest.raises(TypeError):
convert_and_read("array.json", "json", "toml")
Expand Down Expand Up @@ -356,6 +356,9 @@ def test_binary_to_json(self, convert_and_read) -> None:
with pytest.raises(ValueError):
convert_and_read("bin.yml", "yaml", "json")

def test_binary_to_cbor(self, convert_and_read) -> None:
convert_and_read("bin.msgpack", "msgpack", "cbor")

def test_binary_to_msgpack(self, convert_and_read) -> None:
convert_and_read("bin.yml", "yaml", "msgpack")

Expand All @@ -368,9 +371,6 @@ def test_binary_to_toml(self, convert_and_read) -> None:
def test_binary_to_yaml(self, convert_and_read) -> None:
convert_and_read("bin.msgpack", "msgpack", "yaml")

def test_binary_to_cbor(self, convert_and_read) -> None:
convert_and_read("bin.msgpack", "msgpack", "cbor")

def test_yaml_null(self, convert_and_read) -> None:
output = convert_and_read("null.json", "json", "yaml")
reference = read_file("null.yaml")
Expand Down

0 comments on commit b68844f

Please sign in to comment.