Skip to content
Permalink
Browse files

fix failing unit test

  • Loading branch information...
sdpython committed Mar 21, 2018
1 parent ea0cada commit 20bd3f9a73db029e07f5364799abf946b69d0388
@@ -12,9 +12,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@@ -24,58 +22,117 @@
"<script>\n",
"function repeat_indent_string(n){\n",
" var a = \"\" ;\n",
" for ( ; n > 0 ; --n) {\n",
" for ( ; n > 0 ; --n)\n",
" a += \" \";\n",
" }\n",
" return a;\n",
"}\n",
"var update_menu = function() {\n",
"// look up into all sections and builds an automated menu //\n",
"var update_menu_string = function(begin, lfirst, llast, sformat, send, keep_item, begin_format, end_format) {\n",
" var anchors = document.getElementsByClassName(\"section\");\n",
" if (anchors.length == 0) {\n",
" anchors = document.getElementsByClassName(\"text_cell_render rendered_html\");\n",
" }\n",
" var i;\n",
" var text_menu = \"\";\n",
" var i,t;\n",
" var text_menu = begin;\n",
" var text_memo = \"<pre>\\nlength:\" + anchors.length + \"\\n\";\n",
" var ind = \"\";\n",
" var memo_level = 1;\n",
" var href;\n",
" var tags = [];\n",
" var main_item = 0;\n",
" var format_open = 0;\n",
" for (i = 0; i <= llast; i++)\n",
" tags.push(\"h\" + i);\n",
"\n",
" for (i = 0; i < anchors.length; i++) {\n",
" var child = anchors[i].children[0];\n",
" text_memo += \"**\" + anchors[i].id + \"--\\n\";\n",
"\n",
" var child = null;\n",
" for(t = 0; t < tags.length; t++) {\n",
" var r = anchors[i].getElementsByTagName(tags[t]);\n",
" if (r.length > 0) {\n",
"child = r[0];\n",
"break;\n",
" }\n",
" }\n",
" if (child == null) {\n",
" text_memo += \"null\\n\";\n",
" continue;\n",
" }\n",
" if (anchors[i].hasAttribute(\"id\")) {\n",
" // when converted in RST\n",
" href = anchors[i].id;\n",
" text_memo += \"#1-\" + href;\n",
" // passer \u00e0 child suivant (le chercher)\n",
" }\n",
" else if (child.hasAttribute(\"id\")) {\n",
" // in a notebook\n",
" href = child.id;\n",
" text_memo += \"#2-\" + href;\n",
" }\n",
" else {\n",
" text_memo += \"#3-\" + \"*\" + \"\\n\";\n",
" continue;\n",
" }\n",
" var title = child.textContent;\n",
" var level = parseInt(child.tagName.substring(1,2));\n",
" if ((level <= 2) || (level > 4)) {\n",
"\n",
" text_memo += \"--\" + level + \"?\" + lfirst + \"--\" + title + \"\\n\";\n",
"\n",
" if ((level < lfirst) || (level > llast)) {\n",
" continue ;\n",
" }\n",
" if (title.endsWith('\u00b6')) {\n",
" title = title.substring(0,title.length-1).replace(\"<\", \"&lt;\").replace(\">\", \"&gt;\").replace(\"&\", \"&amp;\")\n",
" title = title.substring(0,title.length-1).replace(\"<\", \"&lt;\")\n",
" .replace(\">\", \"&gt;\").replace(\"&\", \"&amp;\");\n",
" }\n",
" if (title.length == 0) {\n",
" continue;\n",
" }\n",
"\n",
" while (level < memo_level) {\n",
" text_menu += end_format + \"</ul>\\n\";\n",
" format_open -= 1;\n",
" memo_level -= 1;\n",
" }\n",
" if (level == lfirst) {\n",
" main_item += 1;\n",
" }\n",
" if (keep_item != -1 && main_item != keep_item + 1) {\n",
" // alert(main_item + \" - \" + level + \" - \" + keep_item);\n",
" continue;\n",
" }\n",
" while (level > memo_level) {\n",
" text_menu += \"<ul>\\n\";\n",
" memo_level += 1;\n",
" }\n",
" while (level < memo_level) {\n",
" text_menu += \"</ul>\\n\";\n",
" memo_level -= 1;\n",
" }\n",
" text_menu += repeat_indent_string(level-2) + '<li><a href=\"#' + href + '\">' + title + '</a></li>';\n",
" text_menu += repeat_indent_string(level-2);\n",
" text_menu += begin_format + sformat.replace(\"__HREF__\", href).replace(\"__TITLE__\", title);\n",
" format_open += 1;\n",
" }\n",
" while (1 < memo_level) {\n",
" text_menu += \"</ul>\\n\";\n",
" text_menu += end_format + \"</ul>\\n\";\n",
" memo_level -= 1;\n",
" format_open -= 1;\n",
" }\n",
" text_menu += send;\n",
" //text_menu += \"\\n\" + text_memo;\n",
"\n",
" while (format_open > 0) {\n",
" text_menu += end_format;\n",
" format_open -= 1;\n",
" }\n",
" text_menu += \"\";\n",
" return text_menu;\n",
"};\n",
"var update_menu = function() {\n",
" var sbegin = \"\";\n",
" var sformat = '<a href=\"#__HREF__\">__TITLE__</a>';\n",
" var send = \"\";\n",
" var begin_format = '<li>';\n",
" var end_format = '</li>';\n",
" var keep_item = -1;\n",
" var text_menu = update_menu_string(sbegin, 2, 4, sformat, send, keep_item,\n",
" begin_format, end_format);\n",
" var menu = document.getElementById(\"my_id_menu_nb\");\n",
" menu.innerHTML=text_menu;\n",
"};\n",
@@ -108,15 +165,14 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2015-08-13 16:32:33 printed\n"
"2018-03-21 10:49:19 \n",
"2018-03-21 10:49:19 printed\n"
]
}
],
@@ -139,7 +195,6 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [
@@ -299,9 +354,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@@ -345,9 +398,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@@ -374,9 +425,7 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
@@ -395,16 +444,14 @@
}
],
"source": [
"from pyquickhelper.ipythonhelper import set_notebook_name_theNotebook\n",
"from jyquickhelper.helper_in_notebook import set_notebook_name_theNotebook\n",
"set_notebook_name_theNotebook()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"import os\n",
@@ -414,18 +461,16 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['example_about_files.ipynb',\n",
" 'example_completion.ipynb',\n",
" 'example_documentation.ipynb',\n",
" 'example_pyquickhelper.ipynb',\n",
" 'exemple_of_fix_menu.ipynb']"
"['plot_sync.py',\n",
" 'README.txt',\n",
" 'set_jenkins_jobs.py',\n",
" 'check_matplotlib_backend.ipynb',\n",
" 'compare_python_distribution.ipynb']"
]
},
"execution_count": 9,
@@ -465,9 +510,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}
@@ -61,7 +61,7 @@ def test_skip_run_notebook(self):
kernel_name = None if is_travis_or_appveyor() is not None else install_python_kernel_for_unittest(
"pyquickhelper")

temp = get_temp_folder(__file__, "temp_run_notebooks_pyq_long")
temp = get_temp_folder(__file__, "temp_skip_run_notebooks_pyq_long")

fnb = os.path.normpath(os.path.join(
os.path.abspath(os.path.dirname(__file__)), "..", "..", "_doc", "notebooks"))
@@ -5,7 +5,6 @@
import sys
import os
import unittest
import warnings

if "temp_" in os.path.abspath(__file__):
raise ImportError(
@@ -28,7 +27,8 @@
from src.pyquickhelper.loghelper import fLOG
from src.pyquickhelper.pycode import get_temp_folder
from src.pyquickhelper.filehelper import gzip_files, zip_files, zip7_files, download, unzip_files, ungzip_files, un7zip_files, unrar_files
from src.pyquickhelper.pycode import is_travis_or_appveyor, skipif_travis, skipif_circleci, skipif_appveyor
from src.pyquickhelper.pycode import skipif_travis, skipif_circleci, skipif_appveyor, skipif_linux, skipif_vless
from src.pyquickhelper.pycode import is_travis_or_appveyor


class TestCompressHelper(unittest.TestCase):
@@ -96,16 +96,13 @@ def test_compress_helper_text(self):
res = ungzip_files(rg, encoding="utf-8")
self.assertTrue("test_compress_helper_text" in res)

@skipif_vless((3, 6), "only available for python 3.6+ (pylzma not compiled)")
def test_uncompress_7zip(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

if is_travis_or_appveyor() == "appveyor" and sys.version_info[:2] <= (3, 5):
# Only available on 3.6.
return

import pylzma
self.assertTrue(pylzma)

@@ -114,6 +111,7 @@ def test_uncompress_7zip(self):
files = un7zip_files(data, where_to=fold, fLOG=fLOG)
self.assertEqual(len(files), 1)

@skipif_linux('py7zlib not available')
def test_compress_7zip(self):
fLOG(
__file__,
@@ -123,15 +121,10 @@ def test_compress_7zip(self):
url = "https://docs.python.org/3/library/ftplib.html"
f = download(url, fold)

if is_travis_or_appveyor() == "appveyor":
out7 = os.path.join(fold, "try.7z")
zip7_files(out7, [f], fLOG=fLOG, temp_folder=fold)
if not os.path.exists(out7):
raise FileNotFoundError(out7)
else:
warnings.warn(
"unzipping files with 7z on a is not tested on linux")
return
out7 = os.path.join(fold, "try.7z")
zip7_files(out7, [f], fLOG=fLOG, temp_folder=fold)
if not os.path.exists(out7):
raise FileNotFoundError(out7)

if sys.version_info[0] == 2:
typbytes = bytearray
@@ -37,7 +37,7 @@ def test_transfer_ftp_true(self):

if sys.version_info[0] < 3:
warnings.warn(
"No testing transfer FTP on Pyghon 2.7 (issue with str and bytes)")
"No testing transfer FTP on Python 2.7 (issue with str and bytes)")
return
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
@@ -60,6 +60,7 @@ def test_transfer_ftp_true(self):
r = web.ls(".")
fLOG(r)
self.assertTrue(isinstance(r, list))
web.close()


if __name__ == "__main__":
@@ -13,7 +13,7 @@
from .tkinter_helper import fix_tkinter_issues_virtualenv
from .trace_execution import get_call_stack
from .unittestclass import ExtTestCase
from .unittestclass import skipif_appveyor, skipif_travis, skipif_circleci
from .unittestclass import skipif_appveyor, skipif_travis, skipif_circleci, skipif_linux, skipif_vless
from .utils_tests import main_wrapper_tests
from .utils_tests_helper import get_temp_folder, check_pep8, add_missing_development_version
from .venv_helper import create_virtual_env, run_venv_script, compare_module_version, run_base_script
@@ -5,6 +5,7 @@
.. versionadded:: 1.5
"""
import os
import sys
import unittest
import warnings
import decimal
@@ -251,3 +252,27 @@ def skipif_circleci(msg):
return lambda x: x
msg = 'Test does not work on circleci due to: ' + msg
return unittest.skip(msg)


def skipif_linux(msg):
"""
Skips a unit test if it runs on :epkg:`linux`.
.. versionadded:: 1.7
"""
if sys.platform.startswith('win'):
return lambda x: x
msg = 'Test does not work on travis due to: ' + msg
return unittest.skip(msg)


def skipif_vless(version, msg):
"""
Skips a unit test if the version is stricly below *version* (tuple).
.. versionadded:: 1.7
"""
if sys.version_info[:3] >= version:
return lambda x: x
msg = 'Python {} < {}: {}'.format(sys.version_info[:3], version, msg)
return unittest.skip(msg)

0 comments on commit 20bd3f9

Please sign in to comment.
You can’t perform that action at this time.