Exemple #1
0
    def test_raises_incorrect_exception(self):
        def raise_():
            raise KeyError()

        with self.assertRaises(AssertionError):
            this(raise_).should.raise_a(IndexError)
        with self.assertRaises(AssertionError):
            this(raise_).should.raise_an(IndexError)
Exemple #2
0
    def test_raises_no_error(self):
        def no_error():
            pass

        with self.assertRaises(AssertionError):
            this(no_error).should.raise_a(Exception)
        with self.assertRaises(AssertionError):
            this(no_error).should.raise_an(Exception)
Exemple #3
0
    def test_raises_with_incorrect_error_message(self):
        def raise_():
            raise KeyError("Specific Error Message")

        with self.assertRaises(AssertionError):
            this(raise_).should.raise_a(KeyError, "Wrong Error Message")
        with self.assertRaises(AssertionError):
            this(raise_).should.raise_an(KeyError, "Wrong Error Message")
Exemple #4
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)

        this(5).should.be_5()
        with self.assertRaises(AssertionError):
            this(4).should.be_5()
Exemple #5
0
 def test_passing_should_be_in(self):
     this('f').should.be_in('foo')
Exemple #6
0
 def test_passing_be_between(self):
     this(2).should.be_between(1, 3)
Exemple #7
0
 def test_passing_should_be(self):
     this(True).should.be(True)
Exemple #8
0
 def test_passing_should_be_less_than_or_equal_to(self):
     this(0).should.be_less_than_or_equal_to(0)
     this(-1).should.be_less_than_or_equal_to(0)
Exemple #9
0
 def test_failing_should_be_less_than(self):
     with self.assertRaises(AssertionError) as e:
         this(1).should.be_less_than(0)
Exemple #10
0
 def test_failing_should_be_greater_than(self):
     with self.assertRaises(AssertionError) as e:
         this(0).should.be_greater_than(1)
Exemple #11
0
 def test_passing_empty(self):
     this(list()).should.be_empty()
     this(str()).should.be_empty()
     this(dict()).should.be_empty()
     this(tuple()).should.be_empty()
     this(set()).should.be_empty()
Exemple #12
0
 def test_failing_when_not_equal(self):
     with self.assertRaises(AssertionError):
         this('foo').should.equal('bar')
Exemple #13
0
    def test_raises_with_correct_error_message(self):
        def raise_():
            raise KeyError("Message 123")

        this(raise_).should.raise_a(KeyError, "Message 123")
        this(raise_).should.raise_an(KeyError, "Message 123")
Exemple #14
0
 def test_passing_when_equal(self):
     this('foo').should.equal('foo')
Exemple #15
0
 def test_failing_should_be_in(self):
     with self.assertRaises(AssertionError) as e:
         this('x').should.be_in('foo')
Exemple #16
0
 def test_failing_empty(self):
     with self.assertRaises(AssertionError):
         this('asdf').should.be_empty()
Exemple #17
0
 def test_passing_should_be_greater_than(self):
     this(1).should.be_greater_than(0)
Exemple #18
0
 def test_NOT_inverts_assertion_logic(self):
     this('foo').should_not.equal('bar')
Exemple #19
0
 def test_passing_should_be_less_than(self):
     this(0).should.be_less_than(1)
Exemple #20
0
 def test_NOT_embellishes_syntax_error(self):
     with self.assertRaises(AssertionError) as e:
         this('foo').equal('foo')
     self.assertEquals(PREPARATION_ERROR, str(e.exception))
Exemple #21
0
 def test_passing_should_be_greater_than_or_equal_to(self):
     this(0).should.be_greater_than_or_equal_to(0)
     this(1).should.be_greater_than_or_equal_to(0)
Exemple #22
0
    def test_NOT_embellishes_error_message_on_failure_accordingly(self):
        with self.assertRaises(AssertionError) as e:
            this('foo').should_not.equal('foo')

        self.assertEquals("Expected 'foo' NOT to equal 'foo'.", str(e.exception))
Exemple #23
0
 def test_failing_should_be_less_than_or_equal_to(self):
     with self.assertRaises(AssertionError) as e:
         this(0).should.be_less_than_or_equal_to(-1)
Exemple #24
0
 def test_passing_should_be_a(self):
     this('foo').should.be_a(str)
Exemple #25
0
 def test_failing_should_be(self):
     with self.assertRaises(AssertionError) as e:
         this(True).should.be(False)
Exemple #26
0
 def test_passing_should_contain(self):
     this('foo').should.contain('o')
Exemple #27
0
 def test_failing_be_between(self):
     with self.assertRaises(AssertionError) as e:
         this(1).should.be_between(2, 3)
Exemple #28
0
    def test_raises_with_unspecified_message(self):
        def raise_():
            raise KeyError()

        this(raise_).should.raise_a(KeyError)
        this(raise_).should.raise_an(KeyError)