Skip to content

Commit 7dede02

Browse files
move test_xy.py files to scrpt directory
1 parent 4f3a73c commit 7dede02

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ data_test : ## Test data APIs
3333

3434
.PHONY : notebook_test
3535
notebook_test : ## Test notebooks in doc/tutorial
36-
python script/jenkins/test_notebooks.py
36+
python script/jenkins/test_notebooks.py report
3737

3838
.PHONY : integ_test
3939
integ_test : ## Integration tests execution with xml reports

script/jenkins/test_data_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,6 @@ def test_icon_centroids_download(self):
122122
# Execute Tests
123123
if __name__ == '__main__':
124124
TESTS = unittest.TestLoader().loadTestsFromTestCase(TestDataAvail)
125-
xmlrunner.XMLTestRunner(output=str(Path(__file__).parent.joinpath('tests_xml'))).run(TESTS)
125+
from sys import argv
126+
outputdir = argv[1] if len(argv) > 1 else str(Path.cwd().joinpath('tests_xml'))
127+
xmlrunner.XMLTestRunner(output=outputdir).run(TESTS)

script/jenkins/test_notebooks.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010

1111
import climada
1212

13-
NOTEBOOK_DIR = Path(__file__).parent.joinpath('doc', 'tutorial')
14-
'''The path to the notebook directories.'''
1513

1614
BOUND_TO_FAIL = '# Note: execution of this cell will fail'
1715
'''Cells containing this line will not be executed in the test'''
1816

1917
EXCLUDED_FROM_NOTEBOOK_TEST = ['climada_installation_step_by_step.ipynb']
2018
'''These notebooks are excluded from being tested'''
2119

20+
2221
class 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

151146
if __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

Comments
 (0)