forked from devbisme/skidl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_teardown.py
49 lines (34 loc) · 1.21 KB
/
setup_teardown.py
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
import os
from skidl import *
no_files()
this_file_dir = os.path.dirname(os.path.abspath(__file__))
files_at_start = set([])
def setup_function(f):
# Record files originally in directory so we know which ones not to delete.
global files_at_start
files_at_start = set(os.listdir(os.getcwd()))
default_circuit.reset()
lib_search_paths.clear()
lib_search_paths.update({tool: [os.getcwd(), this_file_dir] for tool in ALL_TOOLS})
lib_search_paths.update({SKIDL: [os.getcwd(), this_file_dir, get_filename("../skidl/libs")]})
set_default_tool(KICAD)
set_query_backup_lib(INITIAL_QUERY_BACKUP_LIB)
def teardown_function(f):
# Delete files created during testing.
files_at_end = set(os.listdir(os.getcwd()))
for file in files_at_end - files_at_start:
try:
os.remove(file)
except Exception:
pass
def get_filename(fn):
"""
Resolves a filename relative to the "tests" directory.
"""
abs_fn = fn if os.path.isabs(fn) else os.path.join(this_file_dir, fn)
return os.path.realpath(abs_fn)
if __name__ == "__main__":
setup_function(None)
with open("test.txt", "wb") as f:
f.write("test")
teardown_function(None)