File tree 1 file changed +48
-0
lines changed
1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ # This is a test to ensure all of the examples run.
2
+ import os
3
+ import sys
4
+ import unittest
5
+ import pytest
6
+ from os .path import abspath , dirname , join , basename
7
+ from subprocess import call
8
+ from glob import glob
9
+
10
+ testdir = dirname (abspath (str (__file__ )))
11
+ examplesdir = join (testdir , ".." , ".." , "examples" )
12
+
13
+
14
+ class TestExamples (unittest .TestCase ):
15
+ @classmethod
16
+ def setUpClass (self ):
17
+ import pecos
18
+
19
+ self .pecos = pecos
20
+
21
+ @classmethod
22
+ def tearDownClass (self ):
23
+ pass
24
+
25
+ @pytest .mark .time_consuming
26
+ def test_that_examples_run (self ):
27
+ cwd = os .getcwd ()
28
+ example_files = []
29
+ failed_examples = []
30
+ flag = 0
31
+ for f in glob (join (examplesdir , '**' , '*.py' ), recursive = True ):
32
+ filename = basename (f )
33
+ directory = dirname (f )
34
+ example_files .append (filename )
35
+ os .chdir (directory )
36
+ tmp_flag = call ([sys .executable , filename ])
37
+ print (filename , tmp_flag )
38
+ if tmp_flag == 1 :
39
+ failed_examples .append (filename )
40
+ flag = 1
41
+ os .chdir (cwd )
42
+ if len (failed_examples ) > 0 :
43
+ print ("failed examples: {0}" .format (failed_examples ))
44
+ self .assertEqual (flag , 0 )
45
+
46
+
47
+ if __name__ == "__main__" :
48
+ unittest .main ()
You can’t perform that action at this time.
0 commit comments