def test_or_operator(self) -> None: assert 5 == IsInstance(float) | 5 assert 5 != EqualTo(6) | IsInstance(float) assert str(EqualTo(5) | IsInstance(int)) == '(EqualTo(5) | IsInstance(int))' failing_or_operator = EqualTo(5) | IsInstance(float) assert not 6 == failing_or_operator assert str( failing_or_operator ) == '(EqualTo(5)[FAILED for 6] | IsInstance(float)[FAILED for 6])[FAILED for 6]' one_or = EqualTo(5) | IsInstance(int) another_or = IsOdd() | IsTruthy() combo_or = one_or | another_or assert 5 == combo_or assert 6 == combo_or assert str(combo_or ) == '(EqualTo(5) | IsInstance(int) | IsOdd() | IsTruthy())' or_or_normal = one_or | IsTruthy() assert 6 == or_or_normal assert str( or_or_normal) == '(EqualTo(5) | IsInstance(int) | IsTruthy())'
def test_assert_that_matches(): assert that(5).matches(And(EqualTo(5), IsInstance(int))) with pytest.raises(AssertionError) as exc_info: assert that(5).matches(EqualTo(4)) assert str(exc_info.value).split( '\n')[0] == 'assert that(5).matches(EqualTo(4)[FAILED for 5])'
def test_and_operator(self) -> None: assert 5 == IsInstance(int) & 5 assert 5 != EqualTo(5) & IsInstance(float) assert str(EqualTo(5) & IsInstance(int)) == '(EqualTo(5) & IsInstance(int))' failing_and_operator = EqualTo(5) & IsInstance(float) assert not 5 == failing_and_operator assert str( failing_and_operator ) == '(EqualTo(5) & IsInstance(float)[FAILED for 5])[FAILED for 5]' one_and = EqualTo(5) & IsInstance(int) another_and = IsOdd() & IsTruthy() combo_and = one_and & another_and assert 5 == combo_and assert 6 != combo_and assert str(combo_and ) == '(EqualTo(5) & IsInstance(int) & IsOdd() & IsTruthy())' and_and_normal = one_and & IsTruthy() assert 5 == and_and_normal assert str( and_and_normal) == '(EqualTo(5) & IsInstance(int) & IsTruthy())'
def test_equal_to(): assert EQ is EqualTo assert [1] == [EqualTo(1)] assert {'a': 1} == {'a': EqualTo(True)} assert not [0] == [EqualTo(1)] assert str(EqualTo(1)) == 'EqualTo(1)'
def test_is_none_or(): assert Optionally is IsNoneOr assert [None, 1] == All(Optionally(1)) assert [None, 1] == [IsNoneOr(1), IsNoneOr(LessThan(0), EqualTo(1))] assert not [2] == [IsNoneOr(1)] assert str([IsNoneOr('1')]) == "[IsNoneOr('1')]"
def test_slice(): assert 'abcdef' == Slice[3:](EqualTo('def')) assert 'abcdef' == Slice[:3](All(LessThan('d'))) assert [1, 2, 3] == Slice[1](EqualTo(2)) with pytest.raises(AssertionError): assert [1, 2, 3] == Slice[2] with pytest.raises(TypeError) as te_info: assert [1, 2, 3] == Slice[2:3]([0, 1])([2]) # type: ignore[operator] assert str(te_info.value) == "'_Slice' object is not callable" with pytest.raises(AssertionError) as exc_info: assert [1, 2, 3] == Slice[0](EqualTo(0)) assert ( str(exc_info.value).split('\n')[0] == 'assert [1, 2, 3] == Slice[0](EqualTo(0)[FAILED for 1])[FAILED for [1, 2, 3]]' )
def make_not_or_123() -> Iterator[Not]: yield Not(Or(EqualTo(1), 2, 3))
def make_not_not_eq_one_eq_two() -> Iterator[Not]: yield Not(Not(EqualTo(1), EqualTo(2)))
def make_not_not_eq_one() -> Iterator[Not]: yield Not(Not(EqualTo(1)))