]> git.phdru.name Git - ppu.git/blob - tests/ppu_tu.py
Refactor tests: move common functions to ppu_tu.py
[ppu.git] / tests / ppu_tu.py
1 """PPU test utilities"""
2
3
4 import os
5 import shutil
6 from tempfile import mkdtemp
7
8
9 def setup():
10     global tmp_dir
11     tmp_dir = mkdtemp()
12     os.chdir(tmp_dir)
13
14
15 def teardown():
16     os.chdir(os.sep)  # To the root of the FS
17     shutil.rmtree(tmp_dir)
18
19
20 def find_in_path(name):
21     for path in os.environ["PATH"].split(os.pathsep):
22         path = path.strip('"')
23         test_prog_path = os.path.join(path, name)
24         if os.path.exists(test_prog_path):
25             return test_prog_path
26
27
28 def create_files(files, subdirectory=None):
29     if subdirectory:
30         os.makedirs(subdirectory)
31     else:
32         subdirectory = ''
33     for fname in files:
34         with open(os.path.join(subdirectory, fname), 'w'):
35             pass
36
37
38 def assert_files_exist(files):
39     if isinstance(files, str):
40         files = [files]
41     for fname in files:
42         assert os.path.exists(fname)
43
44
45 def assert_files_not_exist(files):
46     if isinstance(files, str):
47         files = [files]
48     for fname in files:
49         assert not os.path.exists(fname)