From cea902cfd931b661d50b2c2f2f61c72165678423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?xavier=20dupr=C3=A9?= Date: Tue, 4 Jan 2022 11:08:45 +0100 Subject: [PATCH 1/3] Create test_documentation_examples_show.py --- .../test_documentation_examples_show.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 _unittests/ut_documentation/test_documentation_examples_show.py diff --git a/_unittests/ut_documentation/test_documentation_examples_show.py b/_unittests/ut_documentation/test_documentation_examples_show.py new file mode 100644 index 00000000..a1c0d389 --- /dev/null +++ b/_unittests/ut_documentation/test_documentation_examples_show.py @@ -0,0 +1,45 @@ +""" +@brief test log(time=60s) +""" +import unittest +import os +import sys +import importlib +import subprocess +from datetime import datetime +from pyquickhelper.pycode import skipif_circleci, ExtTestCase + + +class TestDocumentationExampleShow(ExtTestCase): + + def test_documentation_examples_show(self): + + this = os.path.abspath(os.path.dirname(__file__)) + onxc = os.path.normpath(os.path.join(this, '..', '..')) + pypath = os.environ.get('PYTHONPATH', None) + sep = ";" if sys.platform == 'win32' else ':' + pypath = "" if pypath in (None, "") else (pypath + sep) + pypath += onxc + os.environ['PYTHONPATH'] = pypath + fold = os.path.normpath( + os.path.join(this, '..', '..', '_doc', 'examples')) + found = os.listdir(fold) + tested = 0 + for name in sorted(found): + if not name.startswith("plot_") or not name.endswith(".py"): + continue + + with self.subTest(name=name): + full_name = os.path.join(fold, name) + with open(full_name, "r", encoding="utf-8") as f: + content = f.read() + if "plt.show()" in content and "# plt.show()" not in content: + raise AssertionError( + "plt.show() not found in %r." % name) + tested += 1 + if tested == 0: + raise RuntimeError("No example was tested.") + + +if __name__ == "__main__": + unittest.main() From 1a86426b3cb500cb9d27a022cf3807ca5233d9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?xavier=20dupr=C3=A9?= Date: Tue, 4 Jan 2022 12:33:59 +0100 Subject: [PATCH 2/3] lint --- .../test_documentation_examples_show.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/_unittests/ut_documentation/test_documentation_examples_show.py b/_unittests/ut_documentation/test_documentation_examples_show.py index a1c0d389..3dbf61d2 100644 --- a/_unittests/ut_documentation/test_documentation_examples_show.py +++ b/_unittests/ut_documentation/test_documentation_examples_show.py @@ -3,11 +3,7 @@ """ import unittest import os -import sys -import importlib -import subprocess -from datetime import datetime -from pyquickhelper.pycode import skipif_circleci, ExtTestCase +from pyquickhelper.pycode import ExtTestCase class TestDocumentationExampleShow(ExtTestCase): @@ -16,11 +12,6 @@ def test_documentation_examples_show(self): this = os.path.abspath(os.path.dirname(__file__)) onxc = os.path.normpath(os.path.join(this, '..', '..')) - pypath = os.environ.get('PYTHONPATH', None) - sep = ";" if sys.platform == 'win32' else ':' - pypath = "" if pypath in (None, "") else (pypath + sep) - pypath += onxc - os.environ['PYTHONPATH'] = pypath fold = os.path.normpath( os.path.join(this, '..', '..', '_doc', 'examples')) found = os.listdir(fold) From f800ca55275e84ec0d636ff3ff3070d3a57e0a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?xavier=20dupr=C3=A9?= Date: Tue, 4 Jan 2022 14:26:05 +0100 Subject: [PATCH 3/3] lint --- _unittests/ut_documentation/test_documentation_examples_show.py | 1 - 1 file changed, 1 deletion(-) diff --git a/_unittests/ut_documentation/test_documentation_examples_show.py b/_unittests/ut_documentation/test_documentation_examples_show.py index 3dbf61d2..515828ed 100644 --- a/_unittests/ut_documentation/test_documentation_examples_show.py +++ b/_unittests/ut_documentation/test_documentation_examples_show.py @@ -11,7 +11,6 @@ class TestDocumentationExampleShow(ExtTestCase): def test_documentation_examples_show(self): this = os.path.abspath(os.path.dirname(__file__)) - onxc = os.path.normpath(os.path.join(this, '..', '..')) fold = os.path.normpath( os.path.join(this, '..', '..', '_doc', 'examples')) found = os.listdir(fold)