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.")
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"))
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'.")
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'!" )
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])
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])
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'" )
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'." )
def test_passing_should_be_less_than(self): self._passes(lambda: this(0).should.be_less_than(1))
def test_failing_should_equal(self): self._fails(lambda: this(self.lower).should.equal(self.upper), "Expected 'string' to equal 'STRING'." )
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)
def test_passing_be_between(self): self._passes(lambda: this(2).should.be_between(1, 3))
def test_passing_should_be(self): self._passes(lambda: this(True).should.be(True))
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))
def test_passing_should_contain(self): self._passes(lambda: this(self.lower).should.contain(self.lower[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) )
def test_passing_should_be_a(self): self._passes(lambda: this(self.lower).should.be_a(type(str())))
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'." )
def test_NOT_inverts_assertion_logic(self): self._passes(lambda: this(self.lower).should_NOT.equal(self.upper))
def test_failing_empty(self): self._fails(lambda: this('asdf').should.be_empty(), "Expected 'asdf' to be empty." )
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))
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'." )
def test_failing_should_contain(self): self._fails(lambda: this(self.lower).should.contain('x'), "Expected 'string' to contain 'x'." )
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'." )
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)
def test_failing_should_be(self): self._fails(lambda: this(True).should.be(False), "Expected 'True' to be 'False'." )
def test_passing_should_be_greater_than(self): self._passes(lambda: this(1).should.be_greater_than(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)
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'." )
def test_passing_should_be_in(self): self._passes(lambda: this(self.lower[0]).should.be_in(self.lower))
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())
def test_failing_should_be_in(self): self._fails(lambda: this('x').should.be_in(self.lower), "Expected 'x' to be in 'string'." )
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)