Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Improved tests by converting warnings to errors #4113

Merged
merged 3 commits into from
Apr 30, 2024
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
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@ build-backend = "setuptools.build_meta"
required-version = 23
target-version = ["py37", "py38", "py39", "py310", "py311", "py312"]
safe = true

[tool.pytest.ini_options]
minversion = "6.0"
python_files = [
"test/test*.py",
"test/Test*.py",
]
python_classes = "Test"
python_functions = "test"
filterwarnings = [
"error",
# note the use of single quote below to denote "raw" strings in TOML
'ignore:tostring\(\) is deprecated. Use tobytes\(\) instead\.:DeprecationWarning:OpenGL',
'ignore:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning',
Comment on lines +26 to +27
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listing here general warnings from our dependencies

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the jupyter path warnings you do not specify the module but I guess there are several? I don't remember but in our CI I do this instead of ignoring the warnings:

test-3.11:
  extends: .test-3.11_glx
  variables:
    JUPYTER_PLATFORM_DIRS: 1

I'm fine with it either way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR, it occurs once through an import, during the test collections I think.
But indeed, the env var does the job

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep it like that for now: it's set at a single place instead of appveyor+github configs, and also works when running locally.

]
6 changes: 0 additions & 6 deletions pytest.ini

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def get_project_configuration():
]

test_requires = [
"pytest",
"pytest>=6.0",
"pytest-xvfb",
"pytest-mock",
"bitshuffle",
Expand Down
3 changes: 3 additions & 0 deletions src/silx/gui/plot/test/testPlotWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,7 @@ def testBoundingRectArguments(self):
with self.assertRaises(Exception):
item.setBounds((-1000, 1000, 2000, -2000))

@pytest.mark.filterwarnings("ignore:Attempting to set identical low and high ylims makes transformation singular; automatically expanding.:UserWarning")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore warnings only during tests: Those 3 warnings are about erroneous conditions so thet are not ignored in silx code.

def testBoundingRectWithLog(self):
item = BoundingRect()
self.plot.addItem(item)
Expand All @@ -1549,6 +1550,7 @@ def testBoundingRectWithLog(self):
self.plot.getYAxis()._setLogarithmic(False)
self.assertIsNone(item.getBounds())

@pytest.mark.filterwarnings("ignore:Attempting to set identical low and high ylims makes transformation singular; automatically expanding.:UserWarning")
def testAxisExtent(self):
"""Test XAxisExtent and yAxisExtent"""
for cls, axis in (
Expand Down Expand Up @@ -2054,6 +2056,7 @@ class TestSpecial_ExplicitMplBackend(TestSpecialBackend):
backend = "mpl"


@pytest.mark.filterwarnings("ignore:All-NaN slice encountered:RuntimeWarning")
@pytest.mark.parametrize("plotWidget", ("mpl", "gl"), indirect=True)
@pytest.mark.parametrize(
"xerror,yerror",
Expand Down
13 changes: 9 additions & 4 deletions src/silx/utils/number.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*##########################################################################
#
# Copyright (c) 2016-2018 European Synchrotron Radiation Facility
# Copyright (c) 2016-2024 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -31,6 +31,7 @@
import numpy
import re
import logging
import warnings


_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -70,7 +71,7 @@ def is_longdouble_64bits():
def min_numerical_convertible_type(string, check_accuracy=True):
"""
Parse the string and try to return the smallest numerical type to use for
a safe conversion. It has some known issues: precission loss.
a safe conversion. It has some known issues: precision loss.

:param str string: Representation of a float/integer with text
:param bool check_accuracy: If true, a warning is pushed on the logger
Expand Down Expand Up @@ -105,13 +106,17 @@ def min_numerical_convertible_type(string, check_accuracy=True):
exponent = "0"

nb_precision_digits = int(exponent) - len(decimal) - 1
precision = _biggest_float(10) ** nb_precision_digits * 1.2
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "overflow encountered in scalar power", RuntimeWarning)
precision = _biggest_float(10) ** nb_precision_digits * 1.2
previous_type = _biggest_float
for numpy_type in _float_types:
if numpy_type == _biggest_float:
# value was already casted using the bigger type
continue
reduced_value = numpy_type(value)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "overflow encountered in cast", RuntimeWarning)
reduced_value = numpy_type(value)
Comment on lines +109 to +119
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having tests for raise those warnings, I expects that overflows were taken into accounts when writing the code 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says "It has some known issues: precision loss." so I guess.

if not numpy.isfinite(reduced_value):
break
# numpy isclose(atol=is not accurate enough)
Expand Down
Loading