-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_cleanup.py
More file actions
55 lines (44 loc) · 1.53 KB
/
test_cleanup.py
File metadata and controls
55 lines (44 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from guppylang import guppy
from guppylang.std.quantum import discard, qubit
from selene_sim.build import build
from selene_sim import Quest
def test_delete_files():
@guppy
def main() -> None:
q0 = qubit()
discard(q0)
runner = build(main.compile())
got = list(runner.run(Quest(), n_qubits=1))
runner.delete_files()
with pytest.raises(FileNotFoundError):
got = list(runner.run(Quest(), n_qubits=1))
assert not runner.root.exists()
# these are included in case we later decide to move files
# out of the build root. In this case we may have neglected
# to clean them up.
#
# If at the time this is intentional behaviour,
# then we can change this test.
assert not runner.executable.exists()
assert not runner.runs.exists()
assert not runner.artifacts.exists()
def test_delete_run_directories():
@guppy
def main() -> None:
q0 = qubit()
discard(q0)
runner = build(main.compile())
got = list(runner.run(Quest(), n_qubits=1))
assert len(list(runner.runs.iterdir())) == 1
runner.delete_run_directories()
# we are only cleaning up runs, so everything needed
# for creating new runs should still work.
assert runner.root.exists()
assert runner.artifacts.exists()
assert runner.runs.exists()
assert len(list(runner.runs.iterdir())) == 0
# this should not fail
got = list(runner.run(Quest(), n_qubits=1))
# and we should see one run dir
assert len(list(runner.runs.iterdir())) == 1