Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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()
Exemplo n.º 5
0
 def test_passing_should_be_in(self):
     this('f').should.be_in('foo')
Exemplo n.º 6
0
 def test_passing_be_between(self):
     this(2).should.be_between(1, 3)
Exemplo n.º 7
0
 def test_passing_should_be(self):
     this(True).should.be(True)
Exemplo n.º 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)
Exemplo n.º 9
0
 def test_failing_should_be_less_than(self):
     with self.assertRaises(AssertionError) as e:
         this(1).should.be_less_than(0)
Exemplo n.º 10
0
 def test_failing_should_be_greater_than(self):
     with self.assertRaises(AssertionError) as e:
         this(0).should.be_greater_than(1)
Exemplo n.º 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()
Exemplo n.º 12
0
 def test_failing_when_not_equal(self):
     with self.assertRaises(AssertionError):
         this('foo').should.equal('bar')
Exemplo n.º 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")
Exemplo n.º 14
0
 def test_passing_when_equal(self):
     this('foo').should.equal('foo')
Exemplo n.º 15
0
 def test_failing_should_be_in(self):
     with self.assertRaises(AssertionError) as e:
         this('x').should.be_in('foo')
Exemplo n.º 16
0
 def test_failing_empty(self):
     with self.assertRaises(AssertionError):
         this('asdf').should.be_empty()
Exemplo n.º 17
0
 def test_passing_should_be_greater_than(self):
     this(1).should.be_greater_than(0)
Exemplo n.º 18
0
 def test_NOT_inverts_assertion_logic(self):
     this('foo').should_not.equal('bar')
Exemplo n.º 19
0
 def test_passing_should_be_less_than(self):
     this(0).should.be_less_than(1)
Exemplo n.º 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))
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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)
Exemplo n.º 24
0
 def test_passing_should_be_a(self):
     this('foo').should.be_a(str)
Exemplo n.º 25
0
 def test_failing_should_be(self):
     with self.assertRaises(AssertionError) as e:
         this(True).should.be(False)
Exemplo n.º 26
0
 def test_passing_should_contain(self):
     this('foo').should.contain('o')
Exemplo n.º 27
0
 def test_failing_be_between(self):
     with self.assertRaises(AssertionError) as e:
         this(1).should.be_between(2, 3)
Exemplo n.º 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)