From 7d6dbc1cd1573200ee4766d9c9f2d84e707fcd25 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 31 Dec 2024 03:30:08 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit hooks --- doc/source/api/diffpy.utils.parsers.rst | 1 - doc/source/api/diffpy.utils.rst | 1 - doc/source/api/diffpy.utils.wx.rst | 1 - src/diffpy/utils/validators.py | 9 +++--- tests/test_validators.py | 43 ++++++++++++++----------- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/doc/source/api/diffpy.utils.parsers.rst b/doc/source/api/diffpy.utils.parsers.rst index b08a1840..29ec4782 100644 --- a/doc/source/api/diffpy.utils.parsers.rst +++ b/doc/source/api/diffpy.utils.parsers.rst @@ -34,4 +34,3 @@ diffpy.utils.parsers.serialization module :members: :undoc-members: :show-inheritance: - diff --git a/doc/source/api/diffpy.utils.rst b/doc/source/api/diffpy.utils.rst index 128d914d..e4de1d4f 100644 --- a/doc/source/api/diffpy.utils.rst +++ b/doc/source/api/diffpy.utils.rst @@ -67,4 +67,3 @@ diffpy.utils.resampler module :members: :undoc-members: :show-inheritance: - diff --git a/doc/source/api/diffpy.utils.wx.rst b/doc/source/api/diffpy.utils.wx.rst index 60f60599..76c89035 100644 --- a/doc/source/api/diffpy.utils.wx.rst +++ b/doc/source/api/diffpy.utils.wx.rst @@ -18,4 +18,3 @@ diffpy.utils.wx.gridutils module :members: :undoc-members: :show-inheritance: - diff --git a/src/diffpy/utils/validators.py b/src/diffpy/utils/validators.py index 0f8cd204..dba25b70 100644 --- a/src/diffpy/utils/validators.py +++ b/src/diffpy/utils/validators.py @@ -1,6 +1,5 @@ def is_number(string): - """ - Check if the provided string can be converted to a float. + """Check if the provided string can be converted to a float. Parameters ---------- @@ -31,10 +30,10 @@ def is_number(string): >>> is_number("NaN") True - + >>> is_number("Infinity") True - + >>> is_number("Inf") True """ @@ -42,4 +41,4 @@ def is_number(string): float(string) return True except ValueError: - return False \ No newline at end of file + return False diff --git a/tests/test_validators.py b/tests/test_validators.py index 0d732e77..e340d065 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -1,22 +1,27 @@ -from diffpy.utils.validators import is_number import pytest -@pytest.mark.parametrize("input,expected", [ - ("3.14", True), # Standard float - ("2", True), # Integer - ("-100", True), # Negative integer - ("-3.14", True), # Negative float - ("0", True), # Zero - ("4.5e-1", True), # Scientific notation - ("abc", False), # Non-numeric string - ("", False), # Empty string - ("3.14.15", False), # Multiple dots - ("2+3", False), # Arithmetic expression - ("NaN", True), # Not a Number (special float value) - ("Infinity", True), # Positive infinity - ("-Infinity", True), # Negative infinity - ("Inf", True), # Positive infinity - ("-Inf", True), # Negative infinity -]) +from diffpy.utils.validators import is_number + + +@pytest.mark.parametrize( + "input,expected", + [ + ("3.14", True), # Standard float + ("2", True), # Integer + ("-100", True), # Negative integer + ("-3.14", True), # Negative float + ("0", True), # Zero + ("4.5e-1", True), # Scientific notation + ("abc", False), # Non-numeric string + ("", False), # Empty string + ("3.14.15", False), # Multiple dots + ("2+3", False), # Arithmetic expression + ("NaN", True), # Not a Number (special float value) + ("Infinity", True), # Positive infinity + ("-Infinity", True), # Negative infinity + ("Inf", True), # Positive infinity + ("-Inf", True), # Negative infinity + ], +) def test_is_number(input, expected): - assert is_number(input) == expected \ No newline at end of file + assert is_number(input) == expected