forked from arogozhnikov/einops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
56 lines (45 loc) · 1.38 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
"""
Usage: python test.py
1. Installs part of dependencies
2. Installs current version of einops in editable mode
3. Runs tests
"""
import sys
import os
from subprocess import Popen, PIPE
from pathlib import Path
__author__ = 'Alex Rogozhnikov'
def run(cmd, **env):
# keeps printing output when testing
cmd = cmd.split(' ') if isinstance(cmd, str) else cmd
p = Popen(cmd, stdout=sys.stdout, stderr=sys.stderr,
cwd=str(Path(__file__).parent), env={**os.environ, **env})
p.communicate()
return p.returncode
# check we have nvidia-smi
output, _ = Popen('which nvidia-smi'.split(' '), stdout=PIPE).communicate()
have_cuda = b'nvidia' in output
# install cupy
if have_cuda:
return_code = run('pip install cupy --pre')
assert return_code == 0
# install dependencies
dependencies = [
'numpy',
'mxnet',
'torch',
'tensorflow',
'chainer',
'keras',
'nbformat',
]
assert 0 == run('pip install {} --pre'.format(' '.join(dependencies)))
# install einops
assert 0 == run('pip install -e .')
# we need to run tests twice
# - once for tensorflow eager
return_code1 = run('nosetests tests -vds', TF_EAGER='1', EINOPS_SKIP_CUPY='0' if have_cuda else '1')
print('\n' * 5)
# - and once for symbolic tensorflow
return_code2 = run('nosetests tests -vds', TF_EAGER='0', EINOPS_SKIP_CUPY='0' if have_cuda else '1')
assert return_code1 == 0 and return_code2 == 0