Skip to content

Commit 17d71bb

Browse files
committed
FIX(TCs): don't cretae Ops EARLY in pytest-params ...
not to confuse debugging other TCs, AND not to crash early, during refactorings.
1 parent dc399ec commit 17d71bb

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

test/test_base.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ def compute(self, named_inputs, outputs=None):
148148
[
149149
# NO old-stuff Operation(fn=_jetsamed_fn, name="test", needs="['a']", provides=[]),
150150
(
151-
fnt.partial(
151+
lambda: fnt.partial(
152152
operation(name="test", needs=["a"], provides=["b"])(_scream).compute,
153153
named_inputs={"a": 1},
154154
),
155155
"outputs provides aliases results_fn results_op operation args".split(),
156156
),
157157
(
158-
fnt.partial(
158+
lambda: fnt.partial(
159159
network.ExecutionPlan(*([None] * 6))._handle_task,
160160
op=_ScreamingOperation(),
161161
solution=Solution(MagicMock(), {}),
@@ -168,6 +168,7 @@ def compute(self, named_inputs, outputs=None):
168168
)
169169
def test_jetsam_sites_screaming_func(acallable, expected_jetsam):
170170
# Check jetsams when the underlying function fails.
171+
acallable = acallable()
171172
with pytest.raises(Exception, match="ABC") as excinfo:
172173
acallable()
173174

@@ -181,11 +182,13 @@ def test_jetsam_sites_screaming_func(acallable, expected_jetsam):
181182
[
182183
# NO old-stuff Operation(fn=_jetsamed_fn, name="test", needs="['a']", provides=[]),
183184
(
184-
fnt.partial(operation(_scream, name="test")().compute, named_inputs=None),
185+
lambda: fnt.partial(
186+
operation(_scream, name="test")().compute, named_inputs=None
187+
),
185188
"outputs provides aliases results_fn results_op operation args".split(),
186189
),
187190
(
188-
fnt.partial(
191+
lambda: fnt.partial(
189192
network.ExecutionPlan(*([None] * 6))._handle_task,
190193
op=operation(_scream, name="Ah!")(),
191194
solution=Solution(MagicMock(), {}),
@@ -194,13 +197,13 @@ def test_jetsam_sites_screaming_func(acallable, expected_jetsam):
194197
"plan solution task".split(),
195198
),
196199
(
197-
fnt.partial(
200+
lambda: fnt.partial(
198201
network.ExecutionPlan(*([None] * 6)).execute, named_inputs=None
199202
),
200203
["solution"],
201204
),
202205
(
203-
fnt.partial(
206+
lambda: fnt.partial(
204207
NetworkOperation([operation(str)()], "name").compute,
205208
named_inputs=None,
206209
outputs="bad",
@@ -211,6 +214,7 @@ def test_jetsam_sites_screaming_func(acallable, expected_jetsam):
211214
)
212215
def test_jetsam_sites_scream(acallable, expected_jetsam):
213216
# Check jetsams when the site fails.
217+
acallable = acallable()
214218
with pytest.raises(Exception) as excinfo:
215219
acallable()
216220

@@ -482,7 +486,7 @@ def test_func_sourcelines_func(fn):
482486
exp = "def _foo():\n pass"
483487
got = base.func_sourcelines(fn, human=1)
484488
assert "".join(got[0]).strip() == exp
485-
assert got[1] == 225
489+
assert got[1] == 229
486490

487491

488492
@pytest.mark.parametrize(
@@ -499,7 +503,7 @@ def test_func_sourcelines_method(fn):
499503
exp = "def foo(self):\n pass"
500504
got = base.func_sourcelines(fn, human=1)
501505
assert "".join(got[0]).strip() == exp
502-
assert got[1] == 230
506+
assert got[1] == 234
503507

504508

505509
@pytest.mark.parametrize("fn", [eval, fnt.partial(eval)])

test/test_op.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,31 +292,29 @@ def test_as_renames(inp, exp):
292292

293293

294294
@pytest.mark.parametrize(
295-
"opbuilder, ex",
295+
"op_kw, ex",
296296
[
297297
(
298-
operation(str, aliases={"a": 1}),
298+
dict(aliases={"a": 1}),
299299
r"The `aliases` for ['a'] rename ['a'], not found in op_provides []!",
300300
),
301301
(
302-
operation(str, name="t", provides="a", aliases={"a": 1, "b": 2}),
302+
dict(name="t", provides="a", aliases={"a": 1, "b": 2}),
303303
r"The `aliases` for ['a', 'b'] rename ['b'], not found in op_provides ['a']!",
304304
),
305305
(
306-
operation(
307-
str, name="t", provides=sideffect("a"), aliases={sideffect("a"): 1}
308-
),
306+
dict(name="t", provides=sideffect("a"), aliases={sideffect("a"): 1}),
309307
"must not contain `sideffects",
310308
),
311309
(
312-
operation(str, name="t", provides="a", aliases={"a": sideffect("AA")}),
310+
dict(name="t", provides="a", aliases={"a": sideffect("AA")}),
313311
"must not contain `sideffects",
314312
),
315313
],
316314
)
317-
def test_provides_aliases_BAD(opbuilder, ex):
315+
def test_provides_aliases_BAD(op_kw, ex):
318316
with pytest.raises(ValueError, match=re.escape(ex)):
319-
opbuilder()
317+
operation(str, **op_kw)()
320318

321319

322320
def test_provides_aliases():
@@ -498,7 +496,13 @@ def _opsattrs(ops, attr, value):
498496

499497

500498
@pytest.mark.parametrize(
501-
"op", [Operation, FunctionalOperation, operation(str)(), operation(lambda: None)()]
499+
"op_fact",
500+
[
501+
lambda: Operation,
502+
lambda: FunctionalOperation,
503+
lambda: operation(str)(),
504+
lambda: operation(lambda: None)(),
505+
],
502506
)
503-
def test_dill_ops(op):
504-
dill.loads(dill.dumps(op))
507+
def test_dill_ops(op_fact):
508+
dill.loads(dill.dumps(op_fact()))

0 commit comments

Comments
 (0)