Skip to content

Commit

Permalink
Add is_nan
Browse files Browse the repository at this point in the history
  • Loading branch information
Dani Pinyol committed Jul 11, 2024
1 parent a7acdc5 commit f31b795
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions examples/test_example_functions_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def test_is():
check.is_(x, y)


def test_is_nan():
check.is_nan(42)


def test_is_not():
x = ["foo"]
y = x
Expand Down
4 changes: 3 additions & 1 deletion examples/test_example_functions_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Passing versions of all of the check helper functions.
"""
from pytest_check import check

import math

def test_equal():
check.equal(1, 1)
Expand All @@ -17,6 +17,8 @@ def test_is():
y = x
check.is_(x, y)

def test_is_nan():
check.is_nan(math.nan)

def test_is_not():
x = ["foo"]
Expand Down
11 changes: 10 additions & 1 deletion src/pytest_check/check_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools

import pytest

import math
from .check_log import log_failure

__all__ = [
Expand All @@ -15,6 +15,7 @@
"is_none",
"is_not_none",
"is_in",
"is_nan",
"is_not_in",
"is_instance",
"is_not_instance",
Expand Down Expand Up @@ -75,6 +76,14 @@ def is_(a, b, msg=""):
log_failure(f"check {a} is {b}", msg)
return False

def is_nan(a, msg=""):
__tracebackhide__ = True
if math.isnan(a):
return True
else:
log_failure(f"check {a} is NaN", msg)
return False


def is_not(a, b, msg=""):
__tracebackhide__ = True
Expand Down
4 changes: 2 additions & 2 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
def test_passing_check_functions(pytester):
pytester.copy_example("examples/test_example_functions_pass.py")
result = pytester.runpytest()
result.assert_outcomes(failed=0, passed=23)
result.assert_outcomes(failed=0, passed=24)


def test_failing_check_functions(pytester):
pytester.copy_example("examples/test_example_functions_fail.py")
result = pytester.runpytest()
result.assert_outcomes(failed=23, passed=0)
result.assert_outcomes(failed=24, passed=0)

0 comments on commit f31b795

Please sign in to comment.