Skip to content

Commit

Permalink
support tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elcarpenterNOAA committed Dec 27, 2024
1 parent 5a659c2 commit 5cca04c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/uwtools/tests/config/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def loader(self):
# demonstrate that those nodes' convert() methods return representations in the type specified
# by the tag.

@mark.parametrize("value, expected", [("False", False), ("True", True)])
def test_bool_values(self, expected, loader, value):
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!bool", value=value))
assert ts.convert() == expected

def test_datetime_no(self, loader):
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!datetime", value="foo"))
with raises(ValueError):
Expand All @@ -100,6 +105,16 @@ def test_datetime_ok(self, loader):
assert ts.convert() == datetime(2024, 8, 9, 12, 22, 42)
self.comp(ts, "!datetime '2024-08-09 12:22:42'")

def test_dict_no(self, loader):
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!dict", value="42"))
with raises(TypeError):
ts.convert()

def test_dict_ok(self, loader):
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!dict", value="{a0: 0, a1: 1}"))
assert ts.convert() == {"a0": 0, "a1": 1}
self.comp(ts, "!dict '{a0: 0, a1: 1}'")

def test_float_no(self, loader):
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!float", value="foo"))
with raises(ValueError):
Expand All @@ -120,6 +135,16 @@ def test_int_ok(self, loader):
assert ts.convert() == 42
self.comp(ts, "!int '42'")

def test_list_no(self, loader):
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!list", value="null"))
with raises(TypeError):
ts.convert()

def test_list_ok(self, loader):
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!list", value="[1, 2, 3,]"))
assert ts.convert() == [1, 2, 3]
self.comp(ts, "!list '[1, 2, 3,]'")

def test___repr__(self, loader):
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!int", value="42"))
assert str(ts) == "!int 42"
Expand Down

0 comments on commit 5cca04c

Please sign in to comment.