Exemplo n.º 1
0
def test__assert_expected__when_the_matcher_takes_multiple_args__prints_the_failure_reason(
):
    expectation = Expectation(
        "to_meet_some_conditions_of",
        Matcher("some_matcher", lambda subject, *params: False))

    expect_expectation_to_fail_with_message(
        lambda: expectation.assert_expected("some-subject", "first-arg",
                                            222222, "third-arg"),
        "Expected <'some-subject'> to meet some conditions of <<'first-arg'>, <222222>, <'third-arg'>>"
    )
Exemplo n.º 2
0
def test__assert_expected__when_the_matcher_takes_no_args__prints_the_failure_reason(
):
    class MatcherWithNoArgs(Matcher):
        def __init__(self):
            super().__init__("some_matcher", lambda subject, *params: False)

    expectation = Expectation("to_meet_some_condition", MatcherWithNoArgs())

    expect_expectation_to_fail_with_message(
        lambda: expectation.assert_expected("some-subject"),
        "Expected <'some-subject'> to meet some condition")
Exemplo n.º 3
0
def test__assert_expected__when_the_matcher_comparator_fails__treats_it_as_not_matching(
):
    def comparator_that_raises(subject, *params):
        return subject.do_something() is True

    expectation = Expectation("to_meet_some_condition",
                              Matcher("some_matcher", comparator_that_raises))

    expect_expectation_to_fail_with_message(
        lambda: expectation.assert_expected("some-subject"),
        "Expected <'some-subject'> to meet some condition but comparator raised <AttributeError: 'str' object has no attribute 'do_something'>"
    )
Exemplo n.º 4
0
def test__assert_expected__when_the_matcher_match_fails__treats_it_as_not_matching(
):
    class BadMatcher(Matcher):
        def matches(self, subject):
            raise Exception("some error when matching")

    expectation = Expectation("to_meet_some_condition",
                              BadMatcher('bad_matcher', equal_to_comparator))

    expect_expectation_to_fail_with_message(
        lambda: expectation.assert_expected("some-subject"),
        "Expected <'some-subject'> to meet some condition but matcher raised <Exception: some error when matching>"
    )
Exemplo n.º 5
0
def test__assert_expected__when_the_matcher_has_a_failure_reason__prints_the_failure_reason(
):
    class MatcherWithFailureReason(Matcher):
        def __init__(self):
            super().__init__("some_matcher", lambda subject, *params: False)

        def reason(self):
            return "it was not like that, yo"

    expectation = Expectation("to_meet_some_condition",
                              MatcherWithFailureReason())

    expect_expectation_to_fail_with_message(
        lambda: expectation.assert_expected("some-subject"),
        "Expected <'some-subject'> to meet some condition"
        " but it was not like that, yo")
Exemplo n.º 6
0
 def to_be_about(self, number, tolerance=0.001):
     expectation = Expectation(
         "to_be_about",
         about(number, tolerance),
         message_format="Expected <{subject}> to be about <{0}>")
     expectation.assert_expected(self.subject, number, tolerance)
Exemplo n.º 7
0
 def to_match_list(self, expected_list):
     expectation = Expectation("to_match_list", matches_list(expected_list))
     expectation.assert_expected(self.subject, expected_list)
Exemplo n.º 8
0
 def not_to_contain(self, item_or_text):
     expectation = Expectation("to_contain",
                               contains(item_or_text)).get_inverse()
     expectation.assert_expected(self.subject, item_or_text)
Exemplo n.º 9
0
 def not_to_be_none(self):
     expectation = Expectation(
         "to_be_none",
         is_none(),
         message_format="Expected <{subject}> to be None").get_inverse()
     expectation.assert_expected(self.subject)
Exemplo n.º 10
0
 def to_be_a(self, class_):
     Expectation("to_be_a",
                 instance_of(class_)).assert_expected(self.subject, class_)
Exemplo n.º 11
0
 def to_contain(self, item_or_text):
     Expectation("to_contain", contains(item_or_text)).assert_expected(
         self.subject, item_or_text)
Exemplo n.º 12
0
 def not_to_have_length(self, length):
     Expectation("to_have_length",
                 has_length(length)).get_inverse().assert_expected(
                     self.subject, length)
Exemplo n.º 13
0
 def to_have_length(self, length):
     Expectation("to_have_length",
                 has_length(length)).assert_expected(self.subject, length)
Exemplo n.º 14
0
 def not_to_be(self, expected):
     Expectation("to_be", equal_to(expected)).get_inverse().assert_expected(
         self.subject, expected)
Exemplo n.º 15
0
 def to_be(self, expected):
     Expectation("to_be", equal_to(expected)).assert_expected(
         self.subject, expected)
Exemplo n.º 16
0
 def unmatcherify(self, params, subject):
     return Expectation.unmatcherify(self, params, Spy.get_spy(subject))