Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/pyquickhelper/filehelper/compression_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def unzip_files(zipf, where_to=None, fLOG=noLOG, fvalid=None, remove_space=True,
os.path.abspath(finalfolder))
try:
os.makedirs(finalfolder)
except FileNotFoundError as e:
except FileNotFoundError as e: # pragma: no cover
mes = "Unexpected error\ninfo.filename={0}\ntos={1}\nfinalfolder={2}\nlen(nfinalfolder)={3}".format(
info.filename, tos, finalfolder, len(finalfolder))
raise FileNotFoundError(mes) from e
Expand Down Expand Up @@ -160,9 +160,9 @@ def unzip_files(zipf, where_to=None, fLOG=noLOG, fvalid=None, remove_space=True,
files.append(tos)
fLOG("[unzip_files] unzipped ",
info.filename, " to ", tos)
elif not tos.endswith("/"):
elif not tos.endswith("/"): # pragma: no cover
files.append(tos)
elif not info.filename.endswith("/"):
elif not info.filename.endswith("/"): # pragma: no cover
files.append(tos)
return files

Expand Down Expand Up @@ -276,7 +276,7 @@ def zip7_files(filename_7z, file_set, fLOG=noLOG, temp_folder="."):
if not os.path.exists(exe):
raise FileNotFoundError("unable to find: {0}".format(exe))
elif sys.platform.startswith("darwin"):
exe = "7za"
exe = "7za" # pragma: no cover
else:
exe = "7z"

Expand Down Expand Up @@ -322,12 +322,13 @@ def un7zip_files(zipf, where_to=None, fLOG=noLOG, fvalid=None,
See :ref:`Why module pylzma does not work? <faq-pylzma-ref>`.
"""
if cmd_line:
if not isinstance(zipf, str # unicode
):
raise TypeError("Cannot use command line unless zipf is a file.")
if not isinstance(zipf, str):
raise TypeError( # pragma: no cover
"Cannot use command line unless zipf is a file.")
if remove_space:
warnings.warn(
'[un7zip_files] remove_space and cmd_line are incompatible options.', UserWarning)
warnings.warn( # pragma: no cover
'[un7zip_files] remove_space and cmd_line are incompatible options.',
UserWarning)
if fvalid:
warnings.warn(
'fvalid and cmd_line are incompatible options.', UserWarning)
Expand All @@ -339,7 +340,7 @@ def un7zip_files(zipf, where_to=None, fLOG=noLOG, fvalid=None,
if where_to is None:
where_to = os.path.abspath(".")
elif sys.platform.startswith("darwin"):
exe = "7za"
exe = "7za" # pragma: no cover
else:
exe = "7z"

Expand Down Expand Up @@ -378,8 +379,8 @@ def un7zip_files(zipf, where_to=None, fLOG=noLOG, fvalid=None,
tos = os.path.join(where_to, clean)
if not os.path.exists(tos):
if fvalid and not fvalid(info.filename, tos):
fLOG("[un7zip_files] skipping", info.filename)
continue
fLOG("[un7zip_files] skipping", info.filename) # pragma: no cover
continue # pragma: no cover
try:
data = info.read()
except NotImplementedError as e: # pragma: no cover
Expand All @@ -404,15 +405,15 @@ def un7zip_files(zipf, where_to=None, fLOG=noLOG, fvalid=None,
os.path.abspath(finalfolder))
try:
os.makedirs(finalfolder)
except FileNotFoundError as e:
except FileNotFoundError as e: # pragma: no cover
mes = "Unexpected error\ninfo.filename={0}\ntos={1}\nfinalfolder={2}\nlen(nfinalfolder)={3}".format(
info.filename, tos, finalfolder, len(finalfolder))
raise FileNotFoundError(mes) from e
if not info.filename.endswith("/"):
try:
with open(tos, "wb") as u:
u.write(data)
except FileNotFoundError as e:
except FileNotFoundError as e: # pragma: no cover
# probably an issue in the path name
# the next lines are just here to distinguish
# between the two cases
Expand All @@ -433,9 +434,9 @@ def un7zip_files(zipf, where_to=None, fLOG=noLOG, fvalid=None,
files.append(tos)
fLOG("[un7zip_files] unzipped ",
info.filename, " to ", tos)
elif not tos.endswith("/"):
elif not tos.endswith("/"): # pragma: no cover
files.append(tos)
elif not info.filename.endswith("/"):
elif not info.filename.endswith("/"): # pragma: no cover
files.append(tos)
return files

Expand Down Expand Up @@ -477,7 +478,7 @@ def unrar_files(zipf, where_to=None, fLOG=noLOG, fvalid=None, remove_space=True)
cmd = '"{0}" x "{1}"'.format(exe, zipf)
out, err = run_cmd(cmd, wait=True, fLOG=fLOG, change_path=where_to)
if len(err) > 0:
raise FileException(
raise FileException( # pragma: no cover
"Unable to unrar file '{0}'\n--CMD--\n{3}\n--OUT--\n{1}\n--ERR--\n{2}".format(zipf, out, err, cmd))

return explore_folder(where_to)[1]
Expand Down
18 changes: 9 additions & 9 deletions src/pyquickhelper/helpgen/post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def startss(line):
if cmp is not None:
lines[memopos] = "{0}\n :linenos:\n".format(
".. code-block:: python")
except Exception:
except Exception: # pragma: no cover
pass

memopos = None
Expand Down Expand Up @@ -464,7 +464,7 @@ def startss(line):
break
if "blob/master/build" in path or "build/notebooks" in path:
# raise RuntimeError( # pragma: no cover
warnings.warn(
warnings.warn( # pragma: no cover
"Unexpected substring found in %r in folder %r\n"
"--TRIED--\n%r" % (path, folder, "\n".join(map(str, tried))))
links.append(
Expand Down Expand Up @@ -628,11 +628,11 @@ def post_process_slides_output(file, pdf, python, slides, exc=True,
@param fLOG logging function
"""
if (len(file) > 5000 or not os.path.exists(file)) and "<html" in file:
text = file
save = False
text = file # pragma: no cover
save = False # pragma: no cover
else:
if not os.path.exists(file):
raise FileNotFoundError(file)
raise FileNotFoundError(file) # pragma: no cover
if fLOG:
fLOG("[post_process_slides_output] clean %r" % file)
# fold, name = os.path.split(file)
Expand All @@ -651,8 +651,8 @@ def post_process_slides_output(file, pdf, python, slides, exc=True,
lines = text.split("\n")
for i, line in enumerate(lines):
if '<script src="reveal.js/lib/js/head.min.js"></script>' in line:
lines[
i] = '<script src="reveal.js/js/jquery.min.js"></script>\n' + lines[i]
lines[i] = (
'<script src="reveal.js/js/jquery.min.js"></script>\n' + lines[i])
if '<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>' in line:
lines[i] = ""
if '<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/' in line:
Expand Down Expand Up @@ -846,7 +846,7 @@ def clean_line(line):
"\\usepackage{svg}\\usepackage{hyperref}",
"\\usepackage{hyperref}\\usepackage{amssymb}\\usepackage{latexsym}\\usepackage{amsfonts}\\usepackage{ulem}\\usepackage{textcomp}")
else:
raise HelpGenException(
raise HelpGenException( # pragma: no cover
"unable to add new instructions usepackage in file {0}".format(info))

# SVG does not work unless it is converted (nbconvert should handle that
Expand All @@ -868,7 +868,7 @@ def clean_line(line):

# end
if custom_latex_processing is not None:
st = custom_latex_processing(st)
st = custom_latex_processing(st) # pragma: no cover

if remove_unicode:
encoding = 'ascii'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,6 @@ def __init__(self, srcdir, confdir, outdir, doctreedir, buildername="memoryhtml"
self.project = None
self.registry = SphinxComponentRegistry()
self.post_transforms = []
self.html_themes = {}

if doctreedir is None:
doctreedir = "IMPOSSIBLE:TOFIND"
Expand Down
32 changes: 15 additions & 17 deletions src/pyquickhelper/loghelper/flog.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def init(path=None, filename=None, create=True, path_add=None):
path = flog_static.store_log_values["__log_path"]

if path == "###":
if sys.platform.startswith("win"):
if sys.platform.startswith("win"): # pragma: no cover
path = "d:\\temp" if os.path.exists("d:\\temp") else "c:\\temp"
path = os.path.join(path, "log_pyquickhelper")
else:
path = "/tmp"
path = os.path.join(path, "log_pyquickhelper")

if len(path_add) > 0:
if len(path_add) > 0: # pragma: no cover
if not isinstance(path_add, list):
path_add = [path_add]
temp = []
Expand All @@ -86,9 +86,9 @@ def init(path=None, filename=None, create=True, path_add=None):
if create:
if not os.path.exists(flog_static.store_log_values["__log_path"]):
os.makedirs(flog_static.store_log_values["__log_path"])
else:
else: # pragma: no cover
if not os.path.exists(flog_static.store_log_values["__log_path"]):
raise PQHException( # pragma: no cover
raise PQHException(
"unable to find path " + flog_static.store_log_values["__log_path"])


Expand Down Expand Up @@ -520,7 +520,7 @@ def _check_zip_file(filename, path_unzip, outfile, flatten=True, fLOG=noLOG):
_zip7_path = r"c:\Program Files\7-Zip"
zip7 = not flatten and os.path.exists(_zip7_path)
if zip7:
fLOG("[loghelper.flog] using ", _zip7_path)
fLOG("[loghelper.flog] using ", _zip7_path) # pragma: no cover
wait = []
for info in file.infolist():
# equivalent to is_dir (Python 3.6+)
Expand Down Expand Up @@ -577,7 +577,7 @@ def _check_zip_file(filename, path_unzip, outfile, flatten=True, fLOG=noLOG):
while not ch:
ch = True
for a in wait:
if not os.path.exists(a):
if not os.path.exists(a): # pragma: no cover
ch = False
break
time.sleep(0.5)
Expand Down Expand Up @@ -697,16 +697,16 @@ def _check_url_file(url, path_download, outfile, fLOG=noLOG):
else:
fLOG("[loghelper.flog] downloading ", url)

if len(
url) > 4 and url[-4].lower() in [".txt", ".csv", ".tsv", ".log"]:
if (len(url) > 4 and
url[-4].lower() in [".txt", ".csv", ".tsv", ".log"]):
fLOG("[loghelper.flog] creating text file '{0}'".format(dest))
formatopen = "w"
else:
fLOG(
"[loghelper.flog] creating binary file '{0}'".format(dest))
formatopen = "wb"

if os.path.exists(nyet):
if os.path.exists(nyet): # pragma: no cover
size = os.stat(dest).st_size
fLOG("[loghelper.flog] resume downloading (stop at",
size, ") from '{0}'".format(url))
Expand Down Expand Up @@ -902,18 +902,16 @@ def get_default_value_type(ty, none=True):
"""
if ty is None and none:
return None
elif (ty == str
):
if ty == str:
return ""
elif ty == int:
if ty == int:
return 0
elif ty == decimal.Decimal:
if ty == decimal.Decimal:
return decimal.Decimal(0)
elif ty == float:
if ty == float:
return 0.0
else:
raise PQHException( # pragma: no cover
"type expected in " + str(guess_type_value_type()))
raise PQHException( # pragma: no cover
"type expected in " + str(guess_type_value_type()))


def guess_type_list(args, tolerance=0.01, none=True):
Expand Down
Loading