From 6e1eac6fd6b2d1295f5b92150eba0173f9c7edab Mon Sep 17 00:00:00 2001
From: u214892 <u214892@sbb.ch>
Date: Mon, 17 Jun 2019 22:48:33 +0200
Subject: [PATCH] #57 run tests, examples, notebooks from other directory

---
 setup.py | 10 +++++++++-
 tox.ini  | 15 +++++++++------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/setup.py b/setup.py
index c11b99ff..eaabda40 100644
--- a/setup.py
+++ b/setup.py
@@ -68,6 +68,14 @@ def get_all_svg_files(directory='./svg/'):
     return ret
 
 
+def get_all_images_files(directory='./images/'):
+    ret = []
+    for f in os.listdir(directory):
+        if os.path.isfile(os.path.join(directory, f)):
+            ret.append(directory + f)
+    return ret
+
+
 # Gather requirements from requirements_dev.txt
 install_reqs = []
 requirements_path = 'requirements_dev.txt'
@@ -103,7 +111,7 @@ setup(
     keywords='flatland',
     name='flatland-rl',
     packages=find_packages('.'),
-    data_files=[('svg', get_all_svg_files())],
+    data_files=[('svg', get_all_svg_files()), ('images', get_all_images_files())],
     setup_requires=setup_requirements,
     test_suite='tests',
     tests_require=test_requirements,
diff --git a/tox.ini b/tox.ini
index a347bce1..1713b678 100644
--- a/tox.ini
+++ b/tox.ini
@@ -76,10 +76,10 @@ whitelist_externals = sh
 deps =
     -r{toxinidir}/requirements_dev.txt
 commands =
-    sh -c 'echo DISPLAY=$DISPLAY'
-    sh -c 'echo XAUTHORITY=$XAUTHORITY'
+; run examples from subfolder to ensure that resources are accessed via resources and not via relative paths
+    sh -c 'mkdir -p {envtmpdir}/c236d3c240d61a0969d4cb59e2180ce5'
 ; pipe echo into python since some examples expect input to close the window after the example is run
-    sh -c 'ls examples/*.py | xargs -I{} -n 1 sh -c "echo -e \"\n====== Running {} ========\n\"; echo "q" | python {}"'
+    sh -c 'cd {envtmpdir}/c236d3c240d61a0969d4cb59e2180ce5 && ls {toxinidir}/examples/*.py | xargs -I{} -n 1 sh -c "echo -e \"\n====== Running {} ========\n\"; echo "q" | python {}"'
 
 [testenv:notebooks]
 basepython = python
@@ -96,11 +96,13 @@ deps =
     -r{toxinidir}/requirements_dev.txt
     -r{toxinidir}/requirements_continuous_integration.txt
 commands =
+; run tests from subfolder to ensure that resources are accessed via resources and not via relative paths
+    sh -c 'mkdir -p {envtmpdir}/6f59bc68108c3895b1828abdd04b9a06'
     sh -c 'jupyter nbextension enable --py --sys-prefix widgetsnbextension'
     sh -c 'jupyter nbextension enable --py --sys-prefix jpy_canvas'
 ; https://stackoverflow.com/questions/35545402/how-to-run-an-ipynb-jupyter-notebook-from-terminal/35545463
     sh -c 'ls notebooks/*.ipynb  | xargs -n 1 jupyter nbconvert --to python'
-    sh -c 'ls notebooks/*.py  | xargs -I{} -n 1 sh -c "echo -e \"\n====== Running {} ========\n\"; ipython {}"'
+    sh -c 'cd {envtmpdir}/6f59bc68108c3895b1828abdd04b9a06 && ls {toxinidir}/notebooks/*.py  | xargs -I{} -n 1 sh -c "echo -e \"\n====== Running {} ========\n\"; ipython {}"'
 
 [testenv]
 whitelist_externals = sh
@@ -115,5 +117,6 @@ passenv =
 deps =
     -r{toxinidir}/requirements_dev.txt
 commands =
-    sh -c 'echo DISPLAY: $DISPLAY'
-    py.test --basetemp={envtmpdir}
+; run tests from subfolder to ensure that resources are accessed via resources and not via relative paths
+    sh -c 'mkdir -p {envtmpdir}/fefed3ba12bf1ed81dbcc20fb52706ea'
+    sh -c 'cd {envtmpdir}/fefed3ba12bf1ed81dbcc20fb52706ea && py.test --basetemp={envtmpdir} {toxinidir}'
-- 
GitLab