Skip to content

Commit

Permalink
Draft: add black formatting for tests directory (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
XzzX authored Jan 7, 2025
1 parent 402b3d2 commit 6aed9fe
Show file tree
Hide file tree
Showing 21 changed files with 183 additions and 174 deletions.
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@ ignore = ["E501"] #ignore line-length violations

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # Ignore unused imports in init files -- we specify APIs this way

[tool.black]
extend-exclude = '''
(
^/docs
)
'''
2 changes: 1 addition & 1 deletion tests/integration/test_output_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_without_parent(self):
d1,
d2,
msg="Outside the scope of a parent, we can't expect to re-access an "
"equivalent node",
"equivalent node",
)
self.assertEqual(
d1.label,
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_parallel_speedup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def make_workflow(label):
dt_parallel,
0.5 * dt_serial,
msg=f"Expected the parallel solution to be at least 2x faster, but got"
f"{dt_parallel} and {dt_serial} for parallel and serial times, "
f"respectively",
f"{dt_parallel} and {dt_serial} for parallel and serial times, "
f"respectively",
)
self.assertLess(
dt_cached_parallel,
0.01 * t,
msg="The cache should be trivially fast compared to actual execution of "
"a sleep node",
"a sleep node",
)

def test_executor_instructions(self):
Expand All @@ -93,8 +93,8 @@ def test_executor_instructions(self):
dt,
1.1 * t,
msg="Expected the sleeps to run in parallel with minimal overhead (since "
"it's just a thread pool executor) -- the advantage is that the "
"constructors should survive (de)serialization",
"it's just a thread pool executor) -- the advantage is that the "
"constructors should survive (de)serialization",
)


Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def test_executed_provenance(self):
["t", "slow", "fast", "double"],
self.wf.prov.provenance_by_execution,
msg="Later connections get priority over earlier connections, so we expect "
"the t-node to trigger 'slow' before 'fast'",
"the t-node to trigger 'slow' before 'fast'",
)

self.assertListEqual(
self.wf.prov.provenance_by_execution,
self.wf.prov.provenance_by_completion,
msg="The macro is running on an executor, but its children are in serial,"
"so completion and execution order should be the same",
"so completion and execution order should be the same",
)

def test_execution_vs_completion(self):
Expand All @@ -82,14 +82,14 @@ def test_execution_vs_completion(self):
["t", "slow", "fast", "double"],
self.wf.prov.provenance_by_execution,
msg="Later connections get priority over earlier connections, so we expect "
"the t-node to trigger 'slow' before 'fast'",
"the t-node to trigger 'slow' before 'fast'",
)

self.assertListEqual(
["t", "fast", "slow", "double"],
self.wf.prov.provenance_by_completion,
msg="Since 'slow' is slow it shouldn't _finish_ until after 'fast' (but "
"still before 'double' since 'double' depends on 'slow')",
"still before 'double' since 'double' depends on 'slow')",
)

self.assertListEqual(
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_list(self):
inp_class,
inp.__class__,
msg="Regardless of origin, we expect to be constructing the exact same "
"class",
"class",
)
self.assertIs(out_class, out.__class__)

Expand Down
20 changes: 10 additions & 10 deletions tests/integration/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_executors(self):
self.assertFalse(
wf.running,
msg="The workflow should stop. For thread pool this required a "
"little sleep",
"little sleep",
)
wf.executor = None

Expand All @@ -192,8 +192,8 @@ def test_executors(self):
self.assertFalse(
any(n.running for n in wf),
msg=f"All children should be done running -- for thread pools this "
f"requires a very short sleep -- got "
f"{[(n.label, n.running) for n in wf]}",
f"requires a very short sleep -- got "
f"{[(n.label, n.running) for n in wf]}",
)
for child in wf:
child.executor = None
Expand All @@ -218,8 +218,8 @@ def Sleep(t):
first_out,
second_out,
msg="Even thought the _input_ hasn't changed, we expect to avoid the first "
"(cached) result by virtue of resetting the cache when the body of "
"the composite graph has changed",
"(cached) result by virtue of resetting the cache when the body of "
"the composite graph has changed",
)

t0 = time.perf_counter()
Expand All @@ -234,7 +234,7 @@ def Sleep(t):
dt,
0.1 * wf.c.inputs.t.value,
msg="And because it used the cache we expect it much faster than the sleep "
"time",
"time",
)

def test_failure(self):
Expand Down Expand Up @@ -322,10 +322,10 @@ def test_failure(self):
self.assertFalse(
wf.as_path().exists(),
msg=f"The parent-most object is the _only_ one who should have "
f"written a recovery file, so after removing that the whole "
f"node directory for the workflow should be cleaned up."
f"Instead, {wf.as_path()} exists and has content "
f"{[f for f in wf.as_path().iterdir()] if wf.as_path().is_dir() else None}",
f"written a recovery file, so after removing that the whole "
f"node directory for the workflow should be cleaned up."
f"Instead, {wf.as_path()} exists and has content "
f"{[f for f in wf.as_path().iterdir()] if wf.as_path().is_dir() else None}",
)


Expand Down
10 changes: 6 additions & 4 deletions tests/unit/mixin/test_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def Mixed(x, y: int = 42):
{"x": (None, NOT_DATA), "y": (int, 42)},
Mixed.preview_inputs(),
msg="Input specifications should be available at the class level, with or "
"without type hints and/or defaults provided.",
"without type hints and/or defaults provided.",
)

with (
Expand Down Expand Up @@ -179,10 +179,12 @@ def Branched(x) -> bool:
with self.subTest("Uninspectable function"):

def _uninspectable():
template = dedent("""
template = dedent(
"""
def __source_code_not_available(x):
return x
""")
"""
)
exec(template)
return locals()["__source_code_not_available"]

Expand All @@ -191,7 +193,7 @@ def __source_code_not_available(x):
with self.assertRaises(
OSError,
msg="If the source code cannot be inspected for output labels, they "
"_must_ be provided.",
"_must_ be provided.",
):
as_scraper()(f)

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/mixin/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def test_runnable_not_ready(self):
runnable.expected_run_output,
result,
msg="We should be able to bypass the readiness check with a flag, and "
"in this simple case expect to get perfectly normal behaviour "
"afterwards",
"in this simple case expect to get perfectly normal behaviour "
"afterwards",
)

def test_failure(self):
Expand All @@ -100,7 +100,7 @@ def test_failure(self):
self.assertTrue(
runnable.failed,
msg="We should be able to stop the exception from getting raised, but the "
"status should still be failed",
"status should still be failed",
)

def test_runnable_run_local(self):
Expand Down Expand Up @@ -165,7 +165,7 @@ def maybe_get_executor(get_executor):
with self.assertRaises(
TypeError,
msg="Callables are ok, but if they don't return an executor we should get "
"and error.",
"and error.",
):
runnable.executor = (maybe_get_executor, (False,), {})
runnable.run()
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/mixin/test_semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def test_semantic_delimiter(self):
"/",
Semantic.semantic_delimiter,
msg="This is just a hard-code to the current value, update it freely so "
"the test passes; if it fails it's just a reminder that your change is "
"not backwards compatible, and the next release number should reflect "
"this.",
"the test passes; if it fails it's just a reminder that your change is "
"not backwards compatible, and the next release number should reflect "
"this.",
)

def test_parent(self):
Expand Down Expand Up @@ -121,26 +121,26 @@ def test_detached_parent_path(self):
orphan.detached_parent_path.split(orphan.semantic_delimiter),
self.child2.semantic_path.split(orphan.semantic_delimiter)[:-1],
msg="Despite not having a parent, the detached path should store semantic "
"path info through the get/set state routine",
"path info through the get/set state routine",
)
self.assertEqual(
orphan.semantic_path,
self.child2.semantic_path,
msg="The detached path should carry through to semantic path in the "
"absence of a parent",
"absence of a parent",
)
orphan.label = "orphan" # Re-set label after getting state
orphan.parent = self.child2.parent
self.assertIsNone(
orphan.detached_parent_path,
msg="Detached paths aren't necessary and shouldn't co-exist with the "
"presence of a parent",
"presence of a parent",
)
self.assertListEqual(
orphan.semantic_path.split(orphan.semantic_delimiter)[:-1],
self.child2.semantic_path.split(self.child2.semantic_delimiter)[:-1],
msg="Sanity check -- except for the now-different labels, we should be "
"recovering the usual semantic path on setting a parent.",
"recovering the usual semantic path on setting a parent.",
)


Expand Down
36 changes: 18 additions & 18 deletions tests/unit/nodes/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def bar(x: int = 0) -> int:
self.assertIsNone(
from_instance.parent,
msg="Wrappers are not creators, wrapping from the instance makes no "
"difference",
"difference",
)

def test_node_addition(self):
Expand Down Expand Up @@ -118,9 +118,9 @@ def test_node_access(self):
with self.assertRaises(
AttributeError,
msg="Composites should override the attribute access portion of their "
"`HasIOWithInjection` mixin to guarantee that attribute access is "
"always looking for children. If attribute access is actually desired, "
" it can be accomplished with a `GetAttr` node.",
"`HasIOWithInjection` mixin to guarantee that attribute access is "
"always looking for children. If attribute access is actually desired, "
" it can be accomplished with a `GetAttr` node.",
):
self.comp.not_a_child_or_attribute # noqa: B018

Expand Down Expand Up @@ -169,7 +169,7 @@ def test_label_uniqueness(self):
with self.assertRaises(
AttributeError,
msg="The provided label is ok, but then assigning to baz should give "
"trouble since that name is already occupied",
"trouble since that name is already occupied",
):
self.comp.foo = Composite.create.function_node(plus_one, label="whatever")

Expand Down Expand Up @@ -206,7 +206,7 @@ def test_label_uniqueness(self):
["foo", "foo0"],
list(self.comp.children.keys()),
msg="When adding a node with an existing name and relaxed naming, the new "
"node should get an index on its label so each label is still unique",
"node should get an index on its label so each label is still unique",
)

def test_singular_ownership(self):
Expand Down Expand Up @@ -293,7 +293,7 @@ def different_output_channel(x: int = 0) -> int:
self.comp.n3,
replacement,
msg="Sanity check -- when replacing with class, a _new_ instance "
"should be created",
"should be created",
)
self.comp.replace_child(self.comp.n3, n3)

Expand All @@ -302,7 +302,7 @@ def different_output_channel(x: int = 0) -> int:
(0 + 2) + 1 + 1,
self.comp.run(n1__x=0).n3__y,
msg="Assigning a new _class_ to an existing node should be a shortcut "
"for replacement",
"for replacement",
)
self.comp.replace_child(self.comp.n1, n1) # Return to original state

Expand All @@ -311,7 +311,7 @@ def different_output_channel(x: int = 0) -> int:
(0 + 10) + 1 + 1,
self.comp.run(n1__z=0).n3__y,
msg="Different IO should be compatible as long as what's missing is "
"not connected",
"not connected",
)
self.comp.replace_child(self.comp.n1, n1)

Expand All @@ -320,7 +320,7 @@ def different_output_channel(x: int = 0) -> int:
(0 + 1) + 1 + 100,
self.comp.run(n1__x=0).n3__z,
msg="Different IO should be compatible as long as what's missing is "
"not connected",
"not connected",
)
self.comp.replace_child(self.comp.n3, n3)

Expand Down Expand Up @@ -373,7 +373,7 @@ def wrong_hint(x: float = 0) -> float:
3,
self.comp.run().n3__y,
msg="Failed replacements should always restore the original state "
"cleanly",
"cleanly",
)

def test_length(self):
Expand Down Expand Up @@ -441,7 +441,7 @@ def test_return(self):
1,
self.comp.outputs.n1__y.value,
msg="Sanity check that the output has been filled and is stored under the "
"name we think it is",
"name we think it is",
)
# Make sure the returned object is functionally a dot-dict
self.assertEqual(1, out["n1__y"], msg="Should work with item-access")
Expand Down Expand Up @@ -499,7 +499,7 @@ def test_graph_info(self):
self.assertTrue(
top.middle_composite.deep_node.graph_path.startswith(top.graph_path),
msg="The path should go to the parent-most object, recursively from "
"all depths.",
"all depths.",
)

with self.subTest("test_graph_root"):
Expand Down Expand Up @@ -535,7 +535,7 @@ def test_import_ready(self):
self.assertFalse(
bad_class.import_ready,
msg="The node is in an importable location, but the imported object is not "
"the node class (but rather the node function)",
"the node class (but rather the node function)",
)
with self.subTest(msg="Made up module"):
og_module = totally_findable.__class__.__module__
Expand All @@ -552,7 +552,7 @@ def test_import_ready(self):
self.assertTrue(
self.comp.import_ready,
msg="Sanity check on initial condition -- tests are in the path, so this "
"is importable",
"is importable",
)
self.comp.totally_findable = totally_findable
self.assertTrue(
Expand All @@ -575,13 +575,13 @@ def test_with_executor(self):
self.comp.sub_composite.parent,
self.comp,
msg="After processing a remotely-executed self, the local self should "
"retain its parent",
"retain its parent",
)
self.assertIs(
self.comp.sub_composite.executor,
exe,
msg="After processing a remotely-executed self, the local self should "
"retain its executor",
"retain its executor",
)

def test_result_serialization(self):
Expand Down Expand Up @@ -613,7 +613,7 @@ def test_result_serialization(self):
self.assertFalse(
self.comp.as_path().is_dir(),
msg="Actually, we expect cleanup to have removed empty directories up to "
"and including the semantic root's own directory",
"and including the semantic root's own directory",
)


Expand Down
Loading

0 comments on commit 6aed9fe

Please sign in to comment.