Permalink
Browse files

add notebook coverage

  • Loading branch information...
sdpython committed Aug 15, 2017
1 parent d1096ff commit 5f718b83c0b230e020fd686d9681abb23339ce48
@@ -0,0 +1,70 @@
#-*- coding: utf-8 -*-
"""
@brief test log(time=60s)
"""
import sys
import os
import unittest
try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src
try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, add_missing_development_version
from pyquickhelper.ipythonhelper import execute_notebook_list_finalize_ut
from src.code_beatrix.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_notebook
import src.code_beatrix
class TestLONGNotebookScratch(unittest.TestCase):
def setUp(self):
add_missing_development_version(["pymyinstall", "pyensae", "pymmails", "ensae_projects",
"jyquickhelper"], __file__, hide=True)
def test_long_notebook_scratch(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_scratch")
keepnote = ls_notebooks("scratch")
self.assertTrue(len(keepnote) > 0)
res = execute_notebooks(temp, keepnote,
lambda i, n: "deviner" not in n,
fLOG=fLOG,
clean_function=clean_function_notebook)
execute_notebook_list_finalize_ut(
res, fLOG=fLOG, dump=src.code_beatrix)
if __name__ == "__main__":
unittest.main()
@@ -58,9 +58,9 @@ def test_post_parse(self):
"source", "blog", "2015", "2015-04-04_tinkerlab.rst")
p = BlogPost(file)
fLOG(p.title)
assert len(p.title) > 0
assert p.date == "2015-04-04"
assert isinstance(p.Fields, dict)
self.assertTrue(len(p.title) > 0)
self.assertEqual(p.date, "2015-04-04")
self.assertTrue(isinstance(p.Fields, dict))
def test_post_list(self):
fLOG(
@@ -73,21 +73,21 @@ def test_post_list(self):
path = os.path.abspath(os.path.split(__file__)[0])
fold = os.path.join(
path, "..", "..", "_doc", "sphinxdoc", "source", "blog")
assert os.path.exists(fold)
self.assertTrue(os.path.exists(fold))
out = get_temp_folder(__file__, "temp_post_list")
p = BlogPostList(fold)
cats = p.get_categories()
fLOG(cats)
months = p.get_months()
fLOG(months)
assert len(p) > 0
assert len(cats) > 0
assert len(months) > 0
self.assertTrue(len(p) > 0)
self.assertTrue(len(cats) > 0)
self.assertTrue(len(months) > 0)
res = p.write_aggregated(out)
assert len(res) >= 4
self.assertTrue(len(res) >= 4)
for r in res:
assert os.path.exists(r)
self.assertTrue(os.path.exists(r))
if __name__ == "__main__":
@@ -39,7 +39,9 @@
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, add_missing_development_version
from src.code_beatrix.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_notebook, unittest_raise_exception_notebook
from pyquickhelper.ipythonhelper import execute_notebook_list_finalize_ut
from src.code_beatrix.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_notebook
import src.code_beatrix
class TestNotebookAlgorithm (unittest.TestCase):
@@ -55,12 +57,13 @@ def test_notebook_algorithm(self):
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_algorithm")
keepnote = ls_notebooks("algorithmes")
assert len(keepnote) > 0
self.assertTrue(len(keepnote) > 0)
res = execute_notebooks(temp, keepnote,
lambda i, n: "deviner" not in n,
fLOG=fLOG,
clean_function=clean_function_notebook)
unittest_raise_exception_notebook(res, fLOG)
execute_notebook_list_finalize_ut(
res, fLOG=fLOG, dump=src.code_beatrix)
if __name__ == "__main__":
@@ -38,25 +38,32 @@
import pyquickhelper as skip_
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder
from src.code_beatrix.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_notebook, unittest_raise_exception_notebook
from pyquickhelper.pycode import get_temp_folder, add_missing_development_version
from pyquickhelper.ipythonhelper import execute_notebook_list_finalize_ut
from src.code_beatrix.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_notebook
import src.code_beatrix
class TestNotebookExample (unittest.TestCase):
def setUp(self):
add_missing_development_version(
["pyensae", "jyquickhelper"], __file__)
def test_notebook_example(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_exemples")
keepnote = ls_notebooks("exemples")
assert len(keepnote) > 0
self.assertTrue(len(keepnote) > 0)
res = execute_notebooks(temp, keepnote,
lambda i, n: "deviner" not in n,
fLOG=fLOG,
clean_function=clean_function_notebook)
unittest_raise_exception_notebook(res, fLOG)
execute_notebook_list_finalize_ut(
res, fLOG=fLOG, dump=src.code_beatrix)
if __name__ == "__main__":
@@ -0,0 +1,70 @@
#-*- coding: utf-8 -*-
"""
@brief test log(time=60s)
"""
import sys
import os
import unittest
try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src
try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, add_missing_development_version
from pyquickhelper.ipythonhelper import execute_notebook_list_finalize_ut
from src.code_beatrix.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_notebook
import src.code_beatrix
class TestNotebookJavascript(unittest.TestCase):
def setUp(self):
add_missing_development_version(["pymyinstall", "pyensae", "pymmails", "ensae_projects",
"jyquickhelper"], __file__, hide=True)
def test_notebook_javascript(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_javascript")
keepnote = ls_notebooks("javascript")
self.assertTrue(len(keepnote) > 0)
res = execute_notebooks(temp, keepnote,
lambda i, n: "deviner" not in n,
fLOG=fLOG,
clean_function=clean_function_notebook)
execute_notebook_list_finalize_ut(
res, fLOG=fLOG, dump=src.code_beatrix)
if __name__ == "__main__":
unittest.main()
@@ -8,7 +8,7 @@
def voyageur_de_commerce_points():
"""
default value for the notebook ``voyageur_de_commerce``
Default values for the notebook :ref:`voyageurdecommercerst`.
"""
return [(533.61669921875, -201.39999389648438),
(451.6166687011719, -201.39999389648438),
@@ -7,7 +7,7 @@
import sys
from pyquickhelper.loghelper import noLOG
from pyquickhelper.ipythonhelper.notebook_helper import install_python_kernel_for_unittest
from pyquickhelper.ipythonhelper import run_notebook
from pyquickhelper.ipythonhelper import execute_notebook_list
def ls_notebooks(subfolder):
@@ -141,40 +141,6 @@ def valid_cell(cell):
kernel_name = None if "travis" in sys.executable else install_python_kernel_for_unittest(
"code_beatrix")
addpath = get_additional_paths()
results = {}
for i, note in enumerate(notebooks):
if filter(i, note):
fLOG("******", i, os.path.split(note)[-1])
outfile = os.path.join(folder, "out_" + os.path.split(note)[-1])
try:
out = run_notebook(note, working_dir=folder, outfilename=outfile,
additional_path=addpath,
valid=valid_cell,
clean_function=clean_function,
fLOG=deepfLOG,
kernel_name=kernel_name
)
if not os.path.exists(outfile):
raise FileNotFoundError(outfile)
results[note] = (True, out)
except Exception as e:
results[note] = (False, e)
return results
def unittest_raise_exception_notebook(res, fLOG):
"""
same code for all unit tests
@param res output of @see fn execute_notebooks
"""
assert len(res) > 0
fails = [(os.path.split(k)[-1], ) + v
for k, v in sorted(res.items()) if not v[0]]
for f in fails:
fLOG(f)
if len(fails) > 0:
raise fails[0][-1]
for k, v in sorted(res.items()):
fLOG("final", os.path.split(k)[-1], v[0], v[1])
addpaths = get_additional_paths()
return execute_notebook_list(
folder, notebooks, fLOG=fLOG, valid=valid_cell, additional_path=addpaths, kernel_name=kernel_name)

0 comments on commit 5f718b8

Please sign in to comment.