Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Mar 6, 2022
1 parent 3dcca15 commit 581f23f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mlprodict/asv_benchmark/common_asv_skl.py
Expand Up @@ -93,7 +93,7 @@ def _get_dataset(self, nf, dtype):
Xt = X_test.astype(xdtype)
yt = y_test.astype(self.par_ydtype)
if X_train.shape[0] < X_train.shape[1]:
raise RuntimeError(
raise RuntimeError( # pragma: no cover
"Unable to train a model with less observations than features "
"shape=%r." % (X_train.shape, ))
return (X_train, y_train), (Xt, yt)
Expand Down
19 changes: 11 additions & 8 deletions mlprodict/cli/validate.py
Expand Up @@ -40,9 +40,11 @@ def _save(df, name):
elif ext == '.csv':
df.to_csv(name, index=False)
else:
raise ValueError("Unexpected extension in %r." % name)
raise ValueError( # pragma: no cover
"Unexpected extension in %r." % name)
if verbose > 1:
fLOG("[mlprodict] wrote '{}'".format(name))
fLOG( # pragma: no cover
"[mlprodict] wrote '{}'".format(name))

from pyquickhelper.loghelper import run_cmd
from pyquickhelper.loghelper.run_cmd import get_interpreter_path
Expand All @@ -52,7 +54,7 @@ def _save(df, name):
register_converters()
try:
register_rewritten_operators()
except KeyError:
except KeyError: # pragma: no cover
warnings.warn("converter for HistGradientBoosting* not not exist. "
"Upgrade sklearn-onnx")

Expand All @@ -79,7 +81,8 @@ def _save(df, name):
if black_list is not None and op in black_list:
continue
if verbose > 0:
pbar.set_description("[%s]" % (op + " " * (25 - len(op))))
pbar.set_description( # pragma: no cover
"[%s]" % (op + " " * (25 - len(op))))

loop_out_raw = os.path.join(
dump_dir, "bench_raw_%s_%s.csv" % (runtime, op))
Expand All @@ -89,9 +92,9 @@ def _save(df, name):
'--benchmark=1 --dump_folder={3} --runtime={4} --models={5}'.format(
get_interpreter_path(), loop_out_raw, loop_out_sum, dump_dir, runtime, op))
if verbose > 1:
fLOG("[mlprodict] cmd '{}'.".format(cmd))
fLOG("[mlprodict] cmd '{}'.".format(cmd)) # pragma: no cover
out, err = run_cmd(cmd, wait=True, fLOG=None)
if not os.path.exists(loop_out_sum):
if not os.path.exists(loop_out_sum): # pragma: no cover
if verbose > 2:
fLOG("[mlprodict] unable to find '{}'.".format(loop_out_sum))
if verbose > 1:
Expand Down Expand Up @@ -580,7 +583,7 @@ def latency(model, law='normal', size=1, number=10, repeat=10, max_time=0,
max_time = None

if law != "normal":
raise ValueError(
raise ValueError( # pragma: no cover
"Only law='normal' is supported, not %r." % law)

if profiling in ('name', 'type') and profile_output in (None, ''):
Expand All @@ -599,7 +602,7 @@ def latency(model, law='normal', size=1, number=10, repeat=10, max_time=0,
gr = gr.reset_index(drop=False)
if ext == '.csv':
gr.to_csv(profile_output, index=False)
elif ext == '.xlsx':
elif ext == '.xlsx': # pragma: no cover
gr.to_excel(profile_output, index=False)
else:
raise ValueError( # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion mlprodict/npy/xop.py
Expand Up @@ -1137,7 +1137,7 @@ def _node_to_graph_preprocess_list(inputs):
def _node_to_graph_process_input(inputs, set_inputs, node, inp,
new_inputs, new_stack, inputs_dtype):
if inputs is None and inputs_dtype is None:
raise RuntimeError(
raise RuntimeError( # pragma: no cover
"Both inputs and inputs_dtype cannot be None at the same time "
"for inp=%r." % (inp, ))
if isinstance(inp, OnnxOperator):
Expand Down
2 changes: 1 addition & 1 deletion mlprodict/onnxrt/ops_shape/shape_container.py
Expand Up @@ -248,7 +248,7 @@ def vars_in_values(values):
for k, v in self.shapes.items():
try:
results[k] = v.resolve(variables)
except RuntimeError as e:
except RuntimeError as e: # pragma: no cover
raise RuntimeError(
"Unable to resolve shapes and constraints:\n%s"
"" % pprint.pformat(self.shapes)) from e
Expand Down
4 changes: 2 additions & 2 deletions mlprodict/onnxrt/ops_shape/shape_result.py
Expand Up @@ -119,7 +119,7 @@ class ShapeResult:
def __init__(self, name, shape=None, dtype=None, sparse=False,
mtype=OnnxKind.Tensor, constraints=None):
if not isinstance(name, str):
raise TypeError(
raise TypeError( # pragma: no cover
"name must be a string not %r." % type(name))
if not isinstance(sparse, bool):
raise TypeError( # pragma: no cover
Expand Down Expand Up @@ -184,7 +184,7 @@ def n_dims(self):
Raises an exception otherwise.
"""
if self.mtype != OnnxKind.Tensor:
raise ShapeInferenceException(
raise ShapeInferenceException( # pragma: no cover
"This shape is not a tensor %r." % self)
return len(self.shape)

Expand Down
4 changes: 2 additions & 2 deletions mlprodict/onnxrt/validate/validate.py
Expand Up @@ -681,13 +681,13 @@ def fct_batch(se=sess, xo=Xort_test, it=init_types): # pylint: disable=W0102
try:
max_rel_diff = measure_relative_difference(
ypred, opred[:, 1])
except AttributeError:
except AttributeError: # pragma: no cover
max_rel_diff = numpy.nan
else:
try:
max_rel_diff = measure_relative_difference(
ypred, opred)
except AttributeError:
except AttributeError: # pragma: no cover
max_rel_diff = numpy.nan

if max_rel_diff >= 1e9 and debug: # pragma: no cover
Expand Down

0 comments on commit 581f23f

Please sign in to comment.