Skip to content

Commit

Permalink
test: try fixing "previous item was not torn down properly" (pytest-d…
Browse files Browse the repository at this point in the history
  • Loading branch information
pwwang committed Jul 21, 2024
1 parent 5ea792a commit 5c88717
Showing 1 changed file with 60 additions and 60 deletions.
120 changes: 60 additions & 60 deletions tests/test_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,58 +22,6 @@
)


def test_proc_repr():
assert repr(SimpleProc) == "<Proc:SimpleProc>"


def test_from_proc_no_name():
procs = [None]
with pytest.raises(PipenOrProcNameError):
procs[0] = Proc.from_proc(SimpleProc)


def test_from_proc():
proc = Proc.from_proc(
SimpleProc,
name="new_proc",
desc="new desc",
envs={"a": 1},
cache=True,
forks=2,
plugin_opts={"p": 1},
scheduler="sge",
scheduler_opts={"s": 1},
error_strategy="retry",
num_retries=10,
submission_batch=3,
)
assert proc.name == "new_proc"
assert proc.desc == "new desc"
assert proc.envs == {"a": 1}
assert proc.cache
assert proc.forks == 2
assert proc.plugin_opts == {"p": 1}
assert proc.scheduler == "sge"
assert proc.scheduler_opts == {"s": 1}
assert proc.error_strategy == "retry"
assert proc.num_retries == 10
assert proc.submission_batch == 3


def test_cached_run(caplog, pipen):
NormalProc.nexts = []
# force uncache NormalProc
# shutil.rmtree(pipen.config.workdir)
ret = pipen.set_start(NormalProc).run()
assert ret

# trigger caching
ret = pipen.set_start(NormalProc).run()
assert ret

assert caplog.text.count("Cached jobs:") == 1


@pytest.mark.forked
def test_more_nexts(pipen):
proc1 = Proc.from_proc(NormalProc)
Expand Down Expand Up @@ -112,14 +60,6 @@ def test_proc_with_input_callable(pipen):
assert proc2.output_data.equals(pandas.DataFrame({"output": ["2"]}))


def test_proc_is_singleton(pipen):
pipen.workdir = ".pipen/"
os.makedirs(pipen.workdir, exist_ok=True)
p1 = SimpleProc(pipen)
p2 = SimpleProc(pipen)
assert p1 is p2


@pytest.mark.forked
def test_ignore_input_data_of_start_proc(caplog, pipen):
proc = Proc.from_proc(NormalProc, input_data=[1])
Expand Down Expand Up @@ -160,6 +100,66 @@ def test_script_file_exists(pipen):
pipen.set_starts(ScriptNotExistsProc).run()


def test_proc_repr():
assert repr(SimpleProc) == "<Proc:SimpleProc>"


def test_from_proc_no_name():
procs = [None]
with pytest.raises(PipenOrProcNameError):
procs[0] = Proc.from_proc(SimpleProc)


def test_from_proc():
proc = Proc.from_proc(
SimpleProc,
name="new_proc",
desc="new desc",
envs={"a": 1},
cache=True,
forks=2,
plugin_opts={"p": 1},
scheduler="sge",
scheduler_opts={"s": 1},
error_strategy="retry",
num_retries=10,
submission_batch=3,
)
assert proc.name == "new_proc"
assert proc.desc == "new desc"
assert proc.envs == {"a": 1}
assert proc.cache
assert proc.forks == 2
assert proc.plugin_opts == {"p": 1}
assert proc.scheduler == "sge"
assert proc.scheduler_opts == {"s": 1}
assert proc.error_strategy == "retry"
assert proc.num_retries == 10
assert proc.submission_batch == 3


def test_cached_run(caplog, pipen):
NormalProc.nexts = []
# force uncache NormalProc
# shutil.rmtree(pipen.config.workdir)
ret = pipen.set_start(NormalProc).run()
assert ret

# trigger caching
ret = pipen.set_start(NormalProc).run()
assert ret

assert caplog.text.count("Cached jobs:") == 1


def test_proc_is_singleton(pipen):
pipen.workdir = ".pipen/"
os.makedirs(pipen.workdir, exist_ok=True)
p1 = SimpleProc(pipen)
p2 = SimpleProc(pipen)
assert p1 is p2


def test_invalid_name():
with pytest.raises(PipenOrProcNameError):
Proc.from_proc(SimpleProc, name="a b")
Expand Down

0 comments on commit 5c88717

Please sign in to comment.