From 48d8f126685709af64894cfee474792facac5c0d Mon Sep 17 00:00:00 2001
From: u214892 <u214892@sbb.ch>
Date: Fri, 7 Jun 2019 13:01:36 +0200
Subject: [PATCH] #51 run examples and notebooks in ci

---
 .../simple_example_1.py                           |  0
 .../simple_example_2.py                           |  0
 .../simple_example_3.py                           |  0
 setup.py                                          |  2 +-
 tox.ini                                           | 15 +++++++++------
 5 files changed, 10 insertions(+), 7 deletions(-)
 rename {examples => examples-not-running}/simple_example_1.py (100%)
 rename {examples => examples-not-running}/simple_example_2.py (100%)
 rename {examples => examples-not-running}/simple_example_3.py (100%)

diff --git a/examples/simple_example_1.py b/examples-not-running/simple_example_1.py
similarity index 100%
rename from examples/simple_example_1.py
rename to examples-not-running/simple_example_1.py
diff --git a/examples/simple_example_2.py b/examples-not-running/simple_example_2.py
similarity index 100%
rename from examples/simple_example_2.py
rename to examples-not-running/simple_example_2.py
diff --git a/examples/simple_example_3.py b/examples-not-running/simple_example_3.py
similarity index 100%
rename from examples/simple_example_3.py
rename to examples-not-running/simple_example_3.py
diff --git a/setup.py b/setup.py
index e1a84fd..d517c27 100644
--- a/setup.py
+++ b/setup.py
@@ -39,7 +39,7 @@ if os.name == 'nt':
     try:
         import pycairo
     except:
-        call_cmd = "pip install --user " + url
+        call_cmd = "pip install " + url
         os.system(call_cmd)
 
         import site
diff --git a/tox.ini b/tox.ini
index 6e6205b..c5a1ce1 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py36, py37, flake8, examples, docs, coverage, benchmark, sh
+envlist = py36, py37, examples, notebooks, flake8, docs, coverage, benchmarks
 
 [travis]
 python =
@@ -46,7 +46,7 @@ deps =
 commands =
     make coverage
 
-[testenv:benchmark]
+[testenv:benchmarks]
 basepython = python
 setenv =
     PYTHONPATH = {toxinidir}
@@ -68,6 +68,7 @@ setenv =
     PYTHONPATH = {toxinidir}
 passenv =
     DISPLAY
+    XAUTHORITY
 ; HTTP_PROXY+HTTPS_PROXY required behind corporate proxies
     HTTP_PROXY
     HTTPS_PROXY
@@ -75,7 +76,10 @@ whitelist_externals = sh
 deps =
     -r{toxinidir}/requirements_dev.txt
 commands =
-    sh -c 'ls examples/*.py  | xargs -n 1 python'
+    sh -c 'echo DISPLAY=$DISPLAY'
+    sh -c 'echo XAUTHORITY=$XAUTHORITY'
+; 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 | python {}"'
 
 [testenv:notebooks]
 basepython = python
@@ -83,6 +87,7 @@ setenv =
     PYTHONPATH = {toxinidir}
 passenv =
     DISPLAY
+    XAUTHORITY
 ; HTTP_PROXY+HTTPS_PROXY required behind corporate proxies
     HTTP_PROXY
     HTTPS_PROXY
@@ -95,7 +100,7 @@ commands =
     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 -n 1 ipython'
+    sh -c 'ls notebooks/*.py  | xargs -I{} -n 1 sh -c "echo -e \"\n====== Running {} ========\n\"; ipython {}"'
 
 [testenv]
 whitelist_externals = sh
@@ -112,5 +117,3 @@ deps =
 commands =
     sh -c 'echo DISPLAY: $DISPLAY'
     py.test --basetemp={envtmpdir}
-
-
-- 
GitLab