Skip to content

Commit

Permalink
Friendy ints (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa authored Aug 29, 2024
1 parent ab45222 commit 251c2c0
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 123 deletions.
4 changes: 2 additions & 2 deletions docs/sections/contributor_guide/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Please follow these guidelines when contributing to the documentation:
.. code-block:: python
n = 88
n = 42
or

Expand All @@ -62,4 +62,4 @@ Please follow these guidelines when contributing to the documentation:
.. code-block:: python
n = 88
n = 42
2 changes: 1 addition & 1 deletion src/uwtools/tests/api/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_realize_update_config_from_stdin():


def test_realize_update_config_none():
input_config = {"n": 88}
input_config = {"n": 42}
output_file = Path("output.yaml")
with patch.object(config, "_realize") as _realize:
config.realize(input_config=input_config, output_file=output_file)
Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/tests/api/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def args():
config=fixture_path("testdriver.yaml"),
module=fixture_path("testdriver.py"),
schema_file=fixture_path("testdriver.jsonschema"),
task="eighty_eight",
task="forty_two",
)


Expand Down Expand Up @@ -98,7 +98,7 @@ def test_tasks_fail_no_cycle(args, caplog, kwargs):
@mark.parametrize("f", [Path, str])
def test_tasks_pass(args, f):
tasks = execute.tasks(classname=args.classname, module=f(args.module))
assert tasks["eighty_eight"] == "88"
assert tasks["forty_two"] == "42"


def test__get_driver_class_explicit_fail_bad_class(caplog, args):
Expand Down
14 changes: 7 additions & 7 deletions src/uwtools/tests/config/formats/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@fixture
def config(tmp_path):
path = tmp_path / "config.yaml"
data = {"foo": 88}
data = {"foo": 42}
with open(path, "w", encoding="utf-8") as f:
yaml.dump(data, f)
return ConcreteConfig(config=path)
Expand Down Expand Up @@ -67,7 +67,7 @@ def dump_dict(cfg, path=None):


def test__characterize_values(config):
values = {1: "", 2: None, 3: "{{ n }}", 4: {"a": 88}, 5: [{"b": 99}], 6: "string"}
values = {1: "", 2: None, 3: "{{ n }}", 4: {"a": 42}, 5: [{"b": 43}], 6: "string"}
complete, template = config._characterize_values(values=values, parent="p")
assert complete == [" p1", " p2", " p4", " p4.a", " pb", " p5", " p6"]
assert template == [" p3: {{ n }}"]
Expand Down Expand Up @@ -153,10 +153,10 @@ def test_dereference(tmp_path):
c: !int '{{ N | int + 11 }}'
d: '{{ X }}'
e:
- !int '88'
- !int '42'
- !float '3.14'
f:
f1: !int '88'
f1: !int '42'
f2: !float '3.14'
N: "22"
""".strip()
Expand All @@ -170,8 +170,8 @@ def test_dereference(tmp_path):
"a": 44,
"b": {"c": 33},
"d": "{{ X }}",
"e": [88, 3.14],
"f": {"f1": 88, "f2": 3.14},
"e": [42, 3.14],
"f": {"f1": 42, "f2": 3.14},
"N": "22",
}

Expand Down Expand Up @@ -206,4 +206,4 @@ def test_update_from(config):
Test that a config object can be updated.
"""
config.data.update({"a": "11", "b": "12", "c": "13"})
assert config == {"foo": 88, "a": "11", "b": "12", "c": "13"}
assert config == {"foo": 42, "a": "11", "b": "12", "c": "13"}
10 changes: 5 additions & 5 deletions src/uwtools/tests/config/formats/test_nml.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ def test_nml__parse_include_mult_sect():


def test_nml_derived_type_dict():
nml = NMLConfig(config={"nl": {"o": {"i": 77, "j": 88}}})
assert nml["nl"]["o"] == {"i": 77, "j": 88}
nml = NMLConfig(config={"nl": {"o": {"i": 41, "j": 42}}})
assert nml["nl"]["o"] == {"i": 41, "j": 42}


def test_nml_derived_type_file(tmp_path):
s = """
&nl
o%i = 77
o%j = 88
o%i = 41
o%j = 42
/
"""
path = tmp_path / "a.nml"
with open(path, "w", encoding="utf-8") as f:
print(dedent(s).strip(), file=f)
nml = NMLConfig(config=path)
assert nml["nl"]["o"] == {"i": 77, "j": 88}
assert nml["nl"]["o"] == {"i": 41, "j": 42}


def test_nml_dump_dict_dict(data, tmp_path):
Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/tests/config/formats/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_yaml_constructor_error_not_dict_from_file(tmp_path):

def test_yaml_constructor_error_not_dict_from_stdin():
# Test that a useful exception is raised if the YAML stdin input is a non-dict value.
with StringIO("88") as sio, patch.object(sys, "stdin", new=sio):
with StringIO("42") as sio, patch.object(sys, "stdin", new=sio):
with raises(exceptions.UWConfigError) as e:
YAMLConfig()
assert "Parsed an int value from stdin, expected a dict" in str(e.value)
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_yaml_stdin_plus_relpath_failure(caplog):
def test_yaml_unexpected_error(tmp_path):
cfgfile = tmp_path / "cfg.yaml"
with open(cfgfile, "w", encoding="utf-8") as f:
print("{n: 88}", file=f)
print("{n: 42}", file=f)
with patch.object(yaml, "load") as load:
msg = "Unexpected error"
load.side_effect = yaml.constructor.ConstructorError(note=msg)
Expand Down
12 changes: 6 additions & 6 deletions src/uwtools/tests/config/test_jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_dereference_local_values():
}


@mark.parametrize("val", (True, 3.14, 88, None))
@mark.parametrize("val", (True, 3.14, 42, None))
def test_dereference_no_op(val):
# These types of values pass through dereferencing unmodified:
assert jinja2.dereference(val=val, context={}) == val
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_dereference_str_filter_rendered():
def test_derefrence_str_variable_rendered_mixed():
# A mixed result remains a str.
val = "{{ n }} is an {{ t }}"
assert jinja2.dereference(val=val, context={"n": 88, "t": "int"}) == "88 is an int"
assert jinja2.dereference(val=val, context={"n": 42, "t": "int"}) == "42 is an int"


def test_dereference_str_variable_rendered_str():
Expand Down Expand Up @@ -290,7 +290,7 @@ def test__deref_convert_no(caplog, tag):
assert regex_logged(caplog, "Conversion failed")


@mark.parametrize("converted,tag,value", [(3.14, "!float", "3.14"), (88, "!int", "88")])
@mark.parametrize("converted,tag,value", [(3.14, "!float", "3.14"), (42, "!int", "42")])
def test__deref_convert_ok(caplog, converted, tag, value):
log.setLevel(logging.DEBUG)
loader = yaml.SafeLoader(os.devnull)
Expand Down Expand Up @@ -340,10 +340,10 @@ def test__report(caplog):
Internal arguments when rendering template:
---------------------------------------------------------------------
foo: bar
longish_variable: 88
longish_variable: 42
---------------------------------------------------------------------
""".strip()
jinja2._report(dict(foo="bar", longish_variable=88))
jinja2._report(dict(foo="bar", longish_variable=42))
assert "\n".join(record.message for record in caplog.records) == expected


Expand Down Expand Up @@ -541,7 +541,7 @@ def test_searchpath_stdin_explicit(self, searchpath_assets):
assert J2Template(values={}, searchpath=[a.d1]).render() == "2"

def test_undeclared_variables(self):
s = "{{ a }} {{ b.c }} {{ d.e.f[g] }} {{ h[i] }} {{ j[88] }} {{ k|default(l) }}"
s = "{{ a }} {{ b.c }} {{ d.e.f[g] }} {{ h[i] }} {{ j[42] }} {{ k|default(l) }}"
uvs = {"a", "b", "d", "g", "h", "i", "j", "k", "l"}
assert J2Template(values={}, template_source=s).undeclared_variables == uvs

Expand Down
12 changes: 6 additions & 6 deletions src/uwtools/tests/config/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from uwtools.utils.file import FORMAT


@mark.parametrize("d,n", [({1: 88}, 1), ({1: {2: 88}}, 2), ({1: {2: {3: 88}}}, 3), ({1: {}}, 2)])
@mark.parametrize("d,n", [({1: 42}, 1), ({1: {2: 42}}, 2), ({1: {2: {3: 42}}}, 3), ({1: {}}, 2)])
def test_depth(d, n):
assert support.depth(d) == n

Expand Down Expand Up @@ -103,13 +103,13 @@ def test_int_no(self, loader):
ts.convert()

def test_int_ok(self, loader):
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!int", value="88"))
assert ts.convert() == 88
self.comp(ts, "!int '88'")
ts = support.UWYAMLConvert(loader, yaml.ScalarNode(tag="!int", value="42"))
assert ts.convert() == 42
self.comp(ts, "!int '42'")

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


class Test_UWYAMLRemove:
Expand Down
32 changes: 16 additions & 16 deletions src/uwtools/tests/config/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@fixture
def compare_configs_assets(tmp_path):
d = {"foo": {"bar": 88}, "baz": {"qux": 99}}
d = {"foo": {"bar": 42}, "baz": {"qux": 43}}
a = tmp_path / "a"
b = tmp_path / "b"
with writable(a) as f:
Expand All @@ -50,7 +50,7 @@ def realize_config_testobj(realize_config_yaml_input):
@fixture
def realize_config_yaml_input(tmp_path):
path = tmp_path / "a.yaml"
d = {1: {2: {3: 88}}} # depth 3
d = {1: {2: {3: 42}}} # depth 3
with writable(path) as f:
yaml.dump(d, f)
return path
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_compare_configs_changed_value(compare_configs_assets, caplog):
assert not tools.compare_configs(
config_1_path=a, config_1_format=FORMAT.yaml, config_2_path=b, config_2_format=FORMAT.yaml
)
assert logged(caplog, "baz: qux: - 99 + 11")
assert logged(caplog, "baz: qux: - 43 + 11")


def test_compare_configs_missing_key(compare_configs_assets, caplog):
Expand All @@ -130,7 +130,7 @@ def test_compare_configs_missing_key(compare_configs_assets, caplog):
assert not tools.compare_configs(
config_1_path=b, config_1_format=FORMAT.yaml, config_2_path=a, config_2_format=FORMAT.yaml
)
assert logged(caplog, "baz: qux: - None + 99")
assert logged(caplog, "baz: qux: - None + 43")


def test_compare_configs_bad_format(caplog):
Expand Down Expand Up @@ -544,7 +544,7 @@ def test__ensure_format_bad_no_path_no_format():


def test__ensure_format_config_obj():
config = NMLConfig({"nl": {"n": 88}})
config = NMLConfig({"nl": {"n": 42}})
assert tools._ensure_format(desc="foo", config=config) == FORMAT.nml


Expand Down Expand Up @@ -653,7 +653,7 @@ def test__realize_config_input_setup_ini_stdin(caplog):
data = """
[section]
foo = bar
baz = 88
baz = 42
"""
stdinproxy.cache_clear()
log.setLevel(logging.DEBUG)
Expand All @@ -662,7 +662,7 @@ def test__realize_config_input_setup_ini_stdin(caplog):
sio.seek(0)
with patch.object(sys, "stdin", new=sio):
input_obj = tools._realize_config_input_setup(input_format=FORMAT.ini)
assert input_obj.data == {"section": {"foo": "bar", "baz": "88"}} # note: 88 is str, not int
assert input_obj.data == {"section": {"foo": "bar", "baz": "42"}} # note: 42 is str, not int
assert logged(caplog, "Reading input from stdin")


Expand Down Expand Up @@ -780,24 +780,24 @@ def test__realize_config_output_setup(caplog, tmp_path):


def test__realize_config_update_cfgobj(realize_config_testobj):
assert realize_config_testobj[1][2][3] == 88
update_config = YAMLConfig(config={1: {2: {3: 99}}})
assert realize_config_testobj[1][2][3] == 42
update_config = YAMLConfig(config={1: {2: {3: 43}}})
o = tools._realize_config_update(input_obj=realize_config_testobj, update_config=update_config)
assert o[1][2][3] == 99
assert o[1][2][3] == 43


def test__realize_config_update_stdin(caplog, realize_config_testobj):
stdinproxy.cache_clear()
log.setLevel(logging.DEBUG)
assert realize_config_testobj[1][2][3] == 88
assert realize_config_testobj[1][2][3] == 42
with StringIO() as sio:
print("{1: {2: {3: 99}}}", file=sio)
print("{1: {2: {3: 43}}}", file=sio)
sio.seek(0)
with patch.object(sys, "stdin", new=sio):
o = tools._realize_config_update(
input_obj=realize_config_testobj, update_format=FORMAT.yaml
)
assert o[1][2][3] == 99
assert o[1][2][3] == 43
assert logged(caplog, "Reading update from stdin")


Expand All @@ -806,13 +806,13 @@ def test__realize_config_update_noop(realize_config_testobj):


def test__realize_config_update_file(realize_config_testobj, tmp_path):
assert realize_config_testobj[1][2][3] == 88
values = {1: {2: {3: 99}}}
assert realize_config_testobj[1][2][3] == 42
values = {1: {2: {3: 43}}}
update_config = tmp_path / "config.yaml"
with open(update_config, "w", encoding="utf-8") as f:
yaml.dump(values, f)
o = tools._realize_config_update(input_obj=realize_config_testobj, update_config=update_config)
assert o[1][2][3] == 99
assert o[1][2][3] == 43


def test__realize_config_values_needed(caplog, tmp_path):
Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/tests/config/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def config(tmp_path) -> dict[str, Any]:
return {
"color": "blue",
"dir": str(tmp_path),
"number": 88,
"number": 42,
"sub": {
"dir": str(tmp_path),
},
Expand All @@ -59,7 +59,7 @@ def rocoto_assets():
"metatask": {
"var": {"member": "foo bar baz"},
"task": {
"cores": 88,
"cores": 42,
"command": "some-command",
"walltime": "00:01:00",
"dependency": {
Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/tests/drivers/test_upp.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_UPP_namelist_file(caplog, driverobj):
log.setLevel(logging.DEBUG)
datestr = "2024-05-05_12:00:00"
with open(driverobj.config["namelist"]["base_file"], "w", encoding="utf-8") as f:
print("&model_inputs datestr='%s' / &nampgb kpv=88 /" % datestr, file=f)
print("&model_inputs datestr='%s' / &nampgb kpv=42 /" % datestr, file=f)
dst = driverobj.rundir / "itag"
assert not dst.is_file()
path = Path(refs(driverobj.namelist_file()))
Expand All @@ -132,7 +132,7 @@ def test_UPP_namelist_file(caplog, driverobj):
assert nml["model_inputs"]["datestr"] == datestr
assert nml["model_inputs"]["grib"] == "grib2"
assert nml["nampgb"]["kpo"] == 3
assert nml["nampgb"]["kpv"] == 88
assert nml["nampgb"]["kpv"] == 42


def test_UPP_namelist_file_fails_validation(caplog, driverobj):
Expand Down
8 changes: 4 additions & 4 deletions src/uwtools/tests/fixtures/testdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class TestDriver(AssetsCycleBased):
"""

@task
def eighty_eight(self):
def forty_two(self):
"""
88
42
"""
yield "88"
yield asset(88, lambda: True)
yield "42"
yield asset(42, lambda: True)
yield None

@classmethod
Expand Down
Loading

0 comments on commit 251c2c0

Please sign in to comment.