Skip to content
Permalink
Browse files

add a couple of unit tests to slightly increase the coverage

  • Loading branch information...
sdpython committed Apr 17, 2015
1 parent 69076b3 commit 5ba5bae56a6e9abff08ca4b1a09c5a119ada5b75
Showing with 74 additions and 2 deletions.
  1. +65 −0 _unittests/ut_loghelper/test_log2.py
  2. +1 −0 build_setup_help_on_windows_27.bat
  3. +8 −2 src/pyquickhelper/loghelper/flog.py
@@ -0,0 +1,65 @@
"""
@brief test tree node (time=5s)
"""


import sys
import os
import unittest
import re

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

from src.pyquickhelper.loghelper.flog import fLOG, _get_file_url, _get_file_txt, get_default_value_type, run_cmd


class TestLog2 (unittest.TestCase):

def test_synchro(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

url = "http://www.xavierdupre.fr/?blogpost=1"
uu = _get_file_url(url, "/this/")
assert uu == "/this//http!!www-xavierdupre-fr!_blogpost_1"
uu = _get_file_txt("/g/r.zip")
assert uu == "r.txt"

def test_get_default_value_type(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

assert get_default_value_type(None) is None
assert get_default_value_type(int) == 0

def test_run_cmd(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

cmd = "dir" if sys.platform.startswith("win") else "ls"
cmd += " " + os.path.split(__file__)[0]
out, err = run_cmd(cmd, wait=True)
assert os.path.split(__file__)[-1] in out

out, err = run_cmd(cmd, wait=True, communicate=False)
assert os.path.split(__file__)[-1] in out

if __name__ == "__main__":
unittest.main()
@@ -20,6 +20,7 @@ set pythonexe34=c:\Python34_x64\python
:utpy34:
%pythonexe34% setup.py copy27
if %errorlevel% neq 0 exit /b %errorlevel%
set PYTHONPATH=
cd dist_module27\_unittests

for /d %%d in (ut_*) do %pythonexe27%\..\Scripts\nosetests.exe -w %%d
@@ -420,13 +420,19 @@ def unzip(file, path_unzip=None, outfile=None):


def _get_file_url(url, path):
"""build a filename knowing an url
"""
build a filename knowing an url
@param url url
@param path where to download the file
@return filename
"""
path = path + "/" + \
url.replace("/", "!").replace(":", "").replace(".", "-")
url.replace("/", "!") \
.replace(":", "") \
.replace(".", "-") \
.replace("=", "_") \
.replace("?", "_")
spl = path.split("-")
if len(spl) >= 2:
ext = spl[len(spl) - 1].lower()

0 comments on commit 5ba5bae

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