Ejemplo n.º 1
0
    def test_raises_incorrect_exception(self):
        def raise_():
            raise KeyError()

        self._fails(lambda: this(raise_).should.raise_a(IndexError),
            "Should have raised 'IndexError' but raised 'KeyError' instead.")
        self._fails(lambda: this(raise_).should.raise_an(IndexError),
            "Should have raised 'IndexError' but raised 'KeyError' instead.")
Ejemplo n.º 2
0
    def test_raises_with_correct_error_message(self):
        def raise_():
            raise KeyError("Message 123")

        self._passes(
            lambda: this(raise_).should.raise_a(KeyError, "Message 123"))
        self._passes(
            lambda: this(raise_).should.raise_an(KeyError, "Message 123"))
Ejemplo n.º 3
0
 def test_decorate_with_custom_assertion(self):
     def be_5(this):
         this._assert(
             action=lambda: this._value == 5,
             report=lambda: "'{0}' should equal '5'.".format(this._value)
         )
     should_expectation(be_5)
     self._passes(lambda: this(5).should.be_5())
     self._fails(lambda: this(4).should.be_5(), "'4' should equal '5'.")
Ejemplo n.º 4
0
    def test_raises_no_error(self):
        def no_error():
            pass

        self._fails(lambda: this(no_error).should.raise_a(Exception),
            "'no_error' executed successfully but "
            "should have raised 'Exception'!"
        )
        self._fails(lambda: this(no_error).should.raise_an(Exception),
            "'no_error' executed successfully but "
            "should have raised 'Exception'!"
        )
Ejemplo n.º 5
0
def intersect_interval_should_follow_spec(i, j, result):

    i = Interval(*i)
    j = Interval(*j)

    if result is None:
        this(i & j).should.be(None)
        this(j & i).should.be(None)
        return

    k = i & j
    the(k.begin).should.equal(result[0])
    the(k.end).should.equal(result[1])

    k = j & i
    the(k.begin).should.equal(result[0])
    the(k.end).should.equal(result[1])
Ejemplo n.º 6
0
def intersect_interval_should_follow_spec(i, j, result):

    i = Interval(*i)
    j = Interval(*j)

    if result is None:
        this(i & j).should.be(None)
        this(j & i).should.be(None)
        return

    k = i & j
    the(k.begin).should.equal(result[0])
    the(k.end).should.equal(result[1])

    k = j & i
    the(k.begin).should.equal(result[0])
    the(k.end).should.equal(result[1])
Ejemplo n.º 7
0
    def test_raises_with_incorrect_error_message(self):
        def raise_():
            raise KeyError("Specific Error Message")

        self._fails(lambda:
            this(raise_).should.raise_a(KeyError, "Wrong Error Message"),
                "Raised 'KeyError' as expected but "
                "with an incorrect error message:\n"
                "Expected: 'Wrong Error Message'\n"
                "Received: 'Specific Error Message'"
        )
        self._fails(lambda:
            this(raise_).should.raise_an(KeyError, "Wrong Error Message"),
                "Raised 'KeyError' as expected but "
                "with an incorrect error message:\n"
                "Expected: 'Wrong Error Message'\n"
                "Received: 'Specific Error Message'"
        )
Ejemplo n.º 8
0
 def test_failing_should_be_less_than(self):
     self._fails(lambda: this(1).should.be_less_than(0),
         "Expected '1' to be less than '0'."
     )
Ejemplo n.º 9
0
 def test_passing_should_be_less_than(self):
     self._passes(lambda: this(0).should.be_less_than(1))
Ejemplo n.º 10
0
 def test_failing_should_equal(self):
     self._fails(lambda: this(self.lower).should.equal(self.upper),
         "Expected 'string' to equal 'STRING'."
     )
Ejemplo n.º 11
0
    with provided.two_intervals_are_partly_overlapping:
        merged_interval_should_follow_spec((0, 10), (5, 15), (0, 15))

    with provided.one_interval_includes_the_other:
        merged_interval_should_follow_spec((0, 10), (5, 8), (0, 10))

with given.an_interval:

    i = Interval(0, 10)

    with then.the_length_should_be_correct:
        the(i.length).should.equal(10)

with given.two_intervals:

    with provided.have_the_same_left_tip_but_distince_right_tip:
        i = Interval(0, 10)
        j = Interval(0, 5)
        this(i).should_NOT.equal(j)

    with provided.have_the_same_right_tip_but_distinct_left_tip:
        i = Interval(5, 10)
        j = Interval(0, 10)
        this(i).should_NOT.equal(j)

    with provided.the_same_left_right_tips:
        i = Interval(0, 10)
        j = Interval(0, 10)
        this(i).should.equal(j)
Ejemplo n.º 12
0
 def test_passing_be_between(self):
     self._passes(lambda: this(2).should.be_between(1, 3))
Ejemplo n.º 13
0
 def test_passing_should_be(self):
     self._passes(lambda: this(True).should.be(True))
Ejemplo n.º 14
0
 def test_passing_should_be_less_than_or_equal_to(self):
     self._passes(lambda: this(0).should.be_less_than_or_equal_to(0))
     self._passes(lambda: this(-1).should.be_less_than_or_equal_to(0))
Ejemplo n.º 15
0
 def test_passing_should_contain(self):
     self._passes(lambda: this(self.lower).should.contain(self.lower[0]))
Ejemplo n.º 16
0
 def test_failing_should_be_a(self):
     self._fails(lambda: this(self.lower).should.be_a(list),
                 "Expected 'string' to be a {1} (was a {0})."
                 .format(str, list)
     )
Ejemplo n.º 17
0
 def test_passing_should_be_a(self):
     self._passes(lambda: this(self.lower).should.be_a(type(str())))
Ejemplo n.º 18
0
 def test_NOT_embellishes_error_message_on_failure_accordingly(self):
     self._fails(lambda: this(self.lower).should_NOT.equal(self.lower),
         "Expected 'string' NOT to equal 'string'."
     )
Ejemplo n.º 19
0
 def test_NOT_inverts_assertion_logic(self):
     self._passes(lambda: this(self.lower).should_NOT.equal(self.upper))
Ejemplo n.º 20
0
 def test_failing_empty(self):
     self._fails(lambda: this('asdf').should.be_empty(),
         "Expected 'asdf' to be empty."
     )
Ejemplo n.º 21
0
 def test_passing_should_be_greater_than_or_equal_to(self):
     self._passes(lambda: this(0).should.be_greater_than_or_equal_to(0))
     self._passes(lambda: this(1).should.be_greater_than_or_equal_to(0))
Ejemplo n.º 22
0
 def test_failing_should_be_greater_than_or_equal_to(self):
     self._fails(lambda: this(0).should.be_greater_than_or_equal_to(1),
         "Expected '0' to be greater than or equal to '1'."
     )
Ejemplo n.º 23
0
 def test_failing_should_contain(self):
     self._fails(lambda: this(self.lower).should.contain('x'),
         "Expected 'string' to contain 'x'."
     )
Ejemplo n.º 24
0
 def test_failing_should_be_less_than_or_equal_to(self):
     self._fails(lambda: this(0).should.be_less_than_or_equal_to(-1),
         "Expected '0' to be less than or equal to '-1'."
     )
Ejemplo n.º 25
0
    with provided.two_intervals_are_partly_overlapping:
        merged_interval_should_follow_spec((0, 10), (5, 15), (0, 15))

    with provided.one_interval_includes_the_other:
        merged_interval_should_follow_spec((0, 10), (5, 8), (0, 10))

with given.an_interval:

    i = Interval(0, 10)

    with then.the_length_should_be_correct:
        the(i.length).should.equal(10)

with given.two_intervals:

    with provided.have_the_same_left_tip_but_distince_right_tip:
        i = Interval(0, 10)
        j = Interval(0, 5)
        this(i).should_NOT.equal(j)

    with provided.have_the_same_right_tip_but_distinct_left_tip:
        i = Interval(5, 10)
        j = Interval(0, 10)
        this(i).should_NOT.equal(j)

    with provided.the_same_left_right_tips:
        i = Interval(0, 10)
        j = Interval(0, 10)
        this(i).should.equal(j)
Ejemplo n.º 26
0
 def test_failing_should_be(self):
     self._fails(lambda: this(True).should.be(False),
         "Expected 'True' to be 'False'."
     )
Ejemplo n.º 27
0
 def test_passing_should_be_greater_than(self):
     self._passes(lambda: this(1).should.be_greater_than(0))
Ejemplo n.º 28
0
 def bboxes_almost_the_same(bbox1, bbox2):
     for i in xrange(4):
         this(abs(bbox1[i] - bbox2[i])).should.be_less_than(1.0e-3)
Ejemplo n.º 29
0
 def test_failing_should_be_greater_than(self):
     self._fails(lambda: this(0).should.be_greater_than(1),
         "Expected '0' to be greater than '1'."
     )
Ejemplo n.º 30
0
 def test_passing_should_be_in(self):
     self._passes(lambda: this(self.lower[0]).should.be_in(self.lower))
Ejemplo n.º 31
0
 def test_passing_empty(self):
     self._passes(lambda: this(list()).should.be_empty())
     self._passes(lambda: this(str()).should.be_empty())
     self._passes(lambda: this(dict()).should.be_empty())
     self._passes(lambda: this(tuple()).should.be_empty())
     self._passes(lambda: this(set()).should.be_empty())
Ejemplo n.º 32
0
 def test_failing_should_be_in(self):
     self._fails(lambda: this('x').should.be_in(self.lower),
         "Expected 'x' to be in 'string'."
     )
Ejemplo n.º 33
0
 def bboxes_almost_the_same(bbox1, bbox2):
     for i in xrange(4):
         this(abs(bbox1[i] - bbox2[i])).should.be_less_than(1.0e-3)