1010
1111import climada
1212
13- NOTEBOOK_DIR = Path (__file__ ).parent .joinpath ('doc' , 'tutorial' )
14- '''The path to the notebook directories.'''
1513
1614BOUND_TO_FAIL = '# Note: execution of this cell will fail'
1715'''Cells containing this line will not be executed in the test'''
1816
1917EXCLUDED_FROM_NOTEBOOK_TEST = ['climada_installation_step_by_step.ipynb' ]
2018'''These notebooks are excluded from being tested'''
2119
20+
2221class NotebookTest (unittest .TestCase ):
2322 '''Generic TestCase for testing the executability of notebooks
2423
@@ -117,10 +116,17 @@ def test_notebook(self):
117116 os .chdir (cwd )
118117
119118
120- def main ():
119+ def main (install_dir ):
120+ import xmlrunner
121+
122+ sys .path .append (str (install_dir ))
123+
124+ notebook_dir = install_dir .joinpath ('doc' , 'tutorial' )
125+ '''The path to the notebook directories.'''
126+
121127 # list notebooks in the NOTEBOOK_DIR
122128 notebooks = [f .absolute ()
123- for f in sorted (NOTEBOOK_DIR .iterdir ())
129+ for f in sorted (notebook_dir .iterdir ())
124130 if os .path .splitext (f )[1 ] == ('.ipynb' )
125131 and not f .name in EXCLUDED_FROM_NOTEBOOK_TEST ]
126132
@@ -132,22 +138,16 @@ class NBTest(NotebookTest): pass
132138 setattr (NBTest , test_name , NBTest .test_notebook )
133139 suite .addTest (NBTest (test_name , notebook .parent , notebook .name ))
134140
135- # run the tests depending on the first input argument: None or 'report'.
136- # write xml reports for 'report'
137- if sys .argv [1 :]:
138- arg = sys .argv [1 ]
139- if arg == 'report' :
140- import xmlrunner
141- outdirstr = str (Path (__file__ ).parent .joinpath ('tests_xml' ))
142- xmlrunner .XMLTestRunner (output = outdirstr ).run (suite )
143- else :
144- jd , nb = os .path .split (arg )
145- unittest .TextTestRunner (verbosity = 2 ).run (NotebookTest ('test_notebook' , jd , nb ))
146- # with no argument just run the test
147- else :
148- unittest .TextTestRunner (verbosity = 2 ).run (suite )
141+ # run the tests and write xml reports to tests_xml
142+ output_dir = install_dir .joinpath ('tests_xml' )
143+ xmlrunner .XMLTestRunner (output = str (output_dir )).run (suite )
149144
150145
151146if __name__ == '__main__' :
152- sys .path .append (str (Path .cwd ()))
153- main ()
147+ if sys .argv [1 ] == 'report' :
148+ install_dir = Path (sys .argv [2 ]) if len (sys .argv ) > 2 else Path .cwd ()
149+ main (install_dir )
150+
151+ else :
152+ jd , nb = os .path .split (sys .argv [1 ])
153+ unittest .TextTestRunner (verbosity = 2 ).run (NotebookTest ('test_notebook' , jd , nb ))
0 commit comments