@@ -26,27 +26,51 @@ def remove_readonly(func, path, _):
2626
2727 shutil .rmtree (directory , onerror = remove_readonly )
2828
29+ # Source tests from yaml config
2930tests = None
30- with open ("circle.yml" , "r" ) as f :
31- types = yaml .load_all (f )
32- for t in types :
33- for k ,v in t .items ():
34- if k == 'test' :
35- tests = v ['override' ]
36-
37- if tests :
38- cwd = os .path .abspath (os .path .dirname (__file__ ))
39-
40- if os .path .exists (os .path .join (cwd , '.tests' )):
41- rmtree_readonly (os .path .join (cwd , '.tests' ))
42- os .mkdir (os .path .join (cwd , '.tests' ))
43-
44- for cmd in tests :
45- os .chdir (cwd )
46- print "\n ----------\n EXEC: \" %s\" " % cmd
47- proc = subprocess .Popen (cmd , shell = True )
48- proc .communicate ()
49-
50- if proc .returncode != 0 :
51- print "\n ------------\n ERROR: \" %s\" " % cmd
52- sys .exit (1 )
31+ with open ('.circleci/config.yml' , 'r' ) as f :
32+ data = yaml .safe_load (f )
33+
34+ # Read yaml tree
35+ if sys .version_info [0 ] == 3 :
36+ tests = data ['jobs' ]['py3' ]['steps' ]
37+ else :
38+ tests = data ['jobs' ]['py2' ]['steps' ]
39+
40+ # Filter command list to only contain commands
41+ tests = [item ['run' ] for item in list (filter (lambda x : type (x ) is dict , tests ))]
42+
43+ # ... and replace new lines with ampersands
44+ tests = [item .replace ('\n ' , ' && ' ) for item in tests ]
45+
46+ # Exit if no tests are found
47+ if tests == None :
48+ sys .exit (1 )
49+
50+ # Ignore all tests found before `pip install -e`
51+ startIndex = - 1
52+ for cmd in tests :
53+ if 'pip install -e' in cmd :
54+ startIndex = tests .index (cmd ) + 1
55+ break
56+
57+ if startIndex == - 1 :
58+ sys .exit (1 )
59+
60+ # Delete `.test` directory if it exists
61+ cwd = os .path .abspath (os .path .dirname (__file__ ))
62+
63+ if os .path .exists (os .path .join (cwd , '.tests' )):
64+ rmtree_readonly (os .path .join (cwd , '.tests' ))
65+ os .mkdir (os .path .join (cwd , '.tests' ))
66+
67+ # Run tests
68+ for cmd in tests [startIndex :]:
69+ os .chdir (cwd )
70+ print ("\n ----------\n EXEC: \" %s\" " % cmd )
71+ proc = subprocess .Popen (cmd , shell = True )
72+ proc .communicate ()
73+
74+ if proc .returncode != 0 :
75+ print "\n ------------\n ERROR: \" %s\" " % cmd
76+ sys .exit (1 )
0 commit comments