コード例 #1
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
    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.")
コード例 #2
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
    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"))
コード例 #3
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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'.")
コード例 #4
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
    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'!"
        )
コード例 #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])
コード例 #6
0
ファイル: test_interval.py プロジェクト: yu-liang-kono/Thor
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])
コード例 #7
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
    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'"
        )
コード例 #8
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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'."
     )
コード例 #9
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_passing_should_be_less_than(self):
     self._passes(lambda: this(0).should.be_less_than(1))
コード例 #10
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_failing_should_equal(self):
     self._fails(lambda: this(self.lower).should.equal(self.upper),
         "Expected 'string' to equal 'STRING'."
     )
コード例 #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)
コード例 #12
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_passing_be_between(self):
     self._passes(lambda: this(2).should.be_between(1, 3))
コード例 #13
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_passing_should_be(self):
     self._passes(lambda: this(True).should.be(True))
コード例 #14
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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))
コード例 #15
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_passing_should_contain(self):
     self._passes(lambda: this(self.lower).should.contain(self.lower[0]))
コード例 #16
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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)
     )
コード例 #17
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_passing_should_be_a(self):
     self._passes(lambda: this(self.lower).should.be_a(type(str())))
コード例 #18
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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'."
     )
コード例 #19
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_NOT_inverts_assertion_logic(self):
     self._passes(lambda: this(self.lower).should_NOT.equal(self.upper))
コード例 #20
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_failing_empty(self):
     self._fails(lambda: this('asdf').should.be_empty(),
         "Expected 'asdf' to be empty."
     )
コード例 #21
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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))
コード例 #22
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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'."
     )
コード例 #23
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_failing_should_contain(self):
     self._fails(lambda: this(self.lower).should.contain('x'),
         "Expected 'string' to contain 'x'."
     )
コード例 #24
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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'."
     )
コード例 #25
0
ファイル: test_interval.py プロジェクト: yu-liang-kono/Thor
    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)
コード例 #26
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_failing_should_be(self):
     self._fails(lambda: this(True).should.be(False),
         "Expected 'True' to be 'False'."
     )
コード例 #27
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_passing_should_be_greater_than(self):
     self._passes(lambda: this(1).should.be_greater_than(0))
コード例 #28
0
ファイル: test_pdfpage.py プロジェクト: yu-liang-kono/Thor
 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)
コード例 #29
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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'."
     )
コード例 #30
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_passing_should_be_in(self):
     self._passes(lambda: this(self.lower[0]).should.be_in(self.lower))
コード例 #31
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 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())
コード例 #32
0
ファイル: test_should.py プロジェクト: magmax/pyspecs
 def test_failing_should_be_in(self):
     self._fails(lambda: this('x').should.be_in(self.lower),
         "Expected 'x' to be in 'string'."
     )
コード例 #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)