This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
executable file
·64 lines (49 loc) · 1.41 KB
/
test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
from __future__ import print_function
import subprocess as sp
import sys
import os
from contextlib import contextmanager
@contextmanager
def chdir(path):
old_path = os.getcwd()
try:
os.chdir(path)
yield
finally:
os.chdir(old_path)
def main():
tag = 'srwalker101/dotfilestesting'
if len(sys.argv) == 1:
print('Program usage: {} {{build,shell,rmi,validate}}'.format(
sys.argv[0]), file=sys.stderr)
sys.exit(1)
for arg in sys.argv[1:]:
if arg == 'build':
with chdir('testing'):
run('docker', 'build', '-t', tag, '.')
elif arg == 'shell':
run('docker', 'run', '-it', '--rm', '-v', '{}:/dotfiles'.format(
os.getcwd()), tag, 'zsh')
elif arg == 'validate':
validate()
elif arg == 'rmi':
run('docker', 'rmi', tag)
else:
print('Unexpected command: {}'.format(arg), file=sys.stderr)
def validate():
test_paths = [
'~/.zsh',
'~/.vim/vimrc',
'~/.config/flake8',
]
for path in test_paths:
fullpath = os.path.expanduser(path)
if not os.path.exists(fullpath):
print('Cannot find path: %s' % fullpath, file=sys.stderr)
sys.exit(1)
print('OK')
def run(*args):
sp.check_call(list(map(str, args)))
if __name__ == '__main__':
main()