Example #1
0
 def test_same(self):
     class A(object):
         pass
     a = A()
     b = A()
     it(a).should.be.same(a)
     it(a).should.be.no.same(b)
Example #2
0
 def test_properties(self):
     class A:
         a = 1
         b = 2
         c = 1
     a = A()
     it(a).should.have.properties('a', 'b', 'c')
     it(a).should.have.properties(['a', 'b', 'c'])
Example #3
0
    def test_properties(self):
        class A:
            a = 1
            b = 2
            c = 1

        a = A()
        it(a).should.have.properties('a', 'b', 'c')
        it(a).should.have.properties(['a', 'b', 'c'])
Example #4
0
    def test_own_properties(self):
        class A:

            def __init__(self):
                self.a = 1
                self.b = 2
                self.c = 1
        a = A()
        it(a).should.have.own_properties('a', 'b', 'c')
        it(a).should.have.own_properties(['a', 'b', 'c'])
Example #5
0
    def test_ok(self):
        it(1).be.ok
        it([1]).be.ok
        it((1,)).be.ok
        it({'key': 'value'}).be.ok
        # 没有 __nozero__(2.*) or __bool__(3.*)

        class A:
            pass
        it(A()).be.ok
Example #6
0
    def test_own_properties(self):
        class A:
            def __init__(self):
                self.a = 1
                self.b = 2
                self.c = 1

        a = A()
        it(a).should.have.own_properties('a', 'b', 'c')
        it(a).should.have.own_properties(['a', 'b', 'c'])
Example #7
0
    def test_throw_msg(self):
        def foo():
            raise ValueError("some msg")

        if not py3:
            it(foo).should.throw(ValueError).also.throw(u"some msg")
        it(foo).should.throw(ValueError).also.throw("some msg")
        it(foo).should.raises(ValueError).also.raises("some msg")

        it(foo).should.no.throw("123")
        it(foo).should.no.raises("123")
Example #8
0
    def test_own_proper(self):
        class A:
            a = 1

            def __init__(self):
                self.b = 1
        a = A()
        it(a).should.have.no.own_proper('a')
        it(a).should.have.own_proper('b').which.should.be.equal(1)
        it(a).should.have.no.own_property('a')
        it(a).should.have.own_property('b').which.should.be.equal(1)
Example #9
0
    def test_instanceof(self):
        class A(object):
            pass

        class B(A):
            pass
        a = A()
        b = B()
        it(a).should.be.instanceof(A)
        it(a).should.be.no.instanceof(B)
        it(b).should.be.instanceof(A)
        it(b).should.be.instanceof(B)
Example #10
0
    def test_subclassof(self):
        class A(object):
            pass
        class B(A):
            pass
        class C(B):
            pass

        it(B).should.be.subclassof(A)
        it(C).should.be.subclassof(A)
        it(C).should.be.subclassof(B)
        it(A).shouldnt.be.subclassof(C)
Example #11
0
    def test_own_proper(self):
        class A:
            a = 1

            def __init__(self):
                self.b = 1

        a = A()
        it(a).should.have.no.own_proper('a')
        it(a).should.have.own_proper('b').which.should.be.equal(1)
        it(a).should.have.no.own_property('a')
        it(a).should.have.own_property('b').which.should.be.equal(1)
Example #12
0
 def test_proper(self):
     class A:
         a = 1
     a = A()
     it(a).should.have.proper('a').which.should.be.equal(1)
     it(a).should.have.property('a').which.should.be.equal(1)
     it(a).should.have.no.property('c').which.should.be.none
Example #13
0
    def test_proper(self):
        class A:
            a = 1

        a = A()
        it(a).should.have.proper('a').which.should.be.equal(1)
        it(a).should.have.property('a').which.should.be.equal(1)
        it(a).should.have.no.property('c').which.should.be.none
Example #14
0
 def test_length(self):
     it([]).have.length(0)
     it([1] * 10).have.length(10)
     it('abc').have.length(3)
     it('abcdefg').have.length(7)
     it({}).have.length(0)
     it({'k1': 'v1', 'k2': 'v2'}).have.length(2)
Example #15
0
 def test_count(self):
     it([1, 2, 3]).should.count(3, 1)
     it([1, 2, 2]).should.count(2, 2)
     it((1, 2)).should.count(2, 1)
     it((1, 2)).should.no.count(3, 1)
     it({'k1': 1, 'k2': 1}).should.count(1, 2)
Example #16
0
 def test_keys(self):
     it({'l1': 'v1', 'l2': 'v2'}).have.keys('l1', 'l2')
     it({'l1': 'v1', 'l2': 'v2'}).have.keys(['l1', 'l2'])
Example #17
0
 def test_length(self):
     it([]).have.length(0)
     it([1] * 10).have.length(10)
     it('abc').have.length(3)
     it('abcdefg').have.length(7)
     it({}).have.length(0)
     it({'k1': 'v1', 'k2': 'v2'}).have.length(2)
Example #18
0
 def test_count(self):
     it([1, 2, 3]).should.count(3, 1)
     it([1, 2, 2]).should.count(2, 2)
     it((1, 2)).should.count(2, 1)
     it((1, 2)).should.no.count(3, 1)
     it({'k1': 1, 'k2': 1}).should.count(1, 2)
Example #19
0
 def test_match(self):
     it('abcdefg').should.match(r'.')
     it(u'*****@*****.**').should.match(r'(\w|_)+@(\w|_)+?\.(\w|_)+')
     it('aaa').should.no.match(r'bbb')
     it('abc\ndef').should.match(r'def')
Example #20
0
    def test_no(self):
        it(0).be.no.equal(5)
        it(0).be.no.dict
        it(0).be.no.ok

        it(0).shouldnt.be.equal(5)
        it(0).shouldnt.be.dict
        it(0).shouldnt.be.ok
Example #21
0
 def test_within(self):
     it(0).should.be.within(-1, 1)
     it(10).should.be.within(8, 10)
     it(20).should.be.no.within(8, 10)
Example #22
0
    def test_greater(self):
        it(0).be.greater(-1)
        it(0).be.no.greater(0)
        it(0).be.no.greater(5)

        # above
        it(0).be.above(-1)
        it(0).be.no.above(0)
        it(0).be.no.above(5)
Example #23
0
    def test_simple_conversions(self):
        converted = timeunit.microseconds.to_nanos(1)
        it(converted).should.be.equal(1000)

        converted = timeunit.nanoseconds.to_micros(1000)
        it(converted).should.be.equal(1)

        converted = timeunit.seconds.to_millis(5)
        it(converted).should.be.equal(5000)

        converted = timeunit.milliseconds.to_seconds(5000)
        it(converted).should.be.equal(5)

        converted = timeunit.hours.to_minutes(1)
        it(converted).should.be.equal(60)

        converted = timeunit.minutes.to_hours(60)
        it(converted).should.be.equal(1)

        converted = timeunit.days.to_hours(1)
        it(converted).should.be.equal(24)

        converted = timeunit.hours.to_days(24)
        it(converted).should.be.equal(1)
Example #24
0
 def test_sleep_minus_sceonds(self):
     start = time.time()
     timeunit.seconds.sleep(-1)
     slept = time.time() - start
     it(slept).should.be.within(0, 0.2)
Example #25
0
 def test_sleep_1_seconds(self):
     start = time.time()
     timeunit.seconds.sleep(1)
     slept = time.time() - start
     it(slept).should.be.within(0.8, 1.2)
Example #26
0
 def test_within(self):
     it(0).should.be.within(-1, 1)
     it(10).should.be.within(8, 10)
     it(20).should.be.no.within(8, 10)
Example #27
0
 def test_chain(self):
     v = it(0)
     it(v).should.be.same(v.should)
     it(v).should.be.same(v.have)
     it(v).should.be.same(v.an)
     it(v).should.be.same(v.of)
     it(v).should.be.same(v.a)
     it(v).should.be.same(v.be)
     it(v).should.be.same(v.also)
     it(v).should.be.same(v.which)
Example #28
0
    def test_less(self):
        it(0).be.less(5)
        it(5).be.no.less(5)
        it(5).be.no.less(4)

        # below
        it(0).be.below(5)
        it(5).be.no.below(5)
        it(5).be.no.below(4)
Example #29
0
 def test_endswith(self):
     it('abcdefg').be.endswith('efg')
     it('abc').be.no.endswith('.git')
Example #30
0
    def test_throw(self):
        it(lambda: int('abc')).throw(ValueError)
        it(lambda: int('123')).no.throw(ValueError)

        it(lambda: int('abc')).raises(ValueError)
        it(lambda: int('123')).no.raises(ValueError)
Example #31
0
 def test_startswith(self):
     it('abcdefg').be.startswith('abc')
     it('abc').be.no.startswith('.git')
Example #32
0
 def test_keys(self):
     it({'l1': 'v1', 'l2': 'v2'}).have.keys('l1', 'l2')
     it({'l1': 'v1', 'l2': 'v2'}).have.keys(['l1', 'l2'])
Example #33
0
    def test_contain(self):
        it([1, 2, 3]).should.contain(1)
        it(set([1, 2, 3])).should.contain(3)
        it({'a': 1, 'b': 2}).should.contain('a')

        it([1, 2, 3]).contain(1, 2)
        it(set([1, 2, 3])).contain(2, 3)
        it({'a': 1, 'b': 2}).should.contain('a', 'b')
Example #34
0
    def test_greater(self):
        it(0).be.greater(-1)
        it(0).be.no.greater(0)
        it(0).be.no.greater(5)

        # above
        it(0).be.above(-1)
        it(0).be.no.above(0)
        it(0).be.no.above(5)
Example #35
0
 def test_key(self):
     it({'l1': 'v1'}).have.key('l1').which.should.be.equal('v1')
     it({'l1': 'v1'}).have.no.key('l2').which.be.none
Example #36
0
 def test_type(self):
     it(0).be.int
     it(True).be.bool
     it('string').be.str
     it([]).be.list
     it(()).be.tuple
     it({}).be.dict
Example #37
0
    def test_empty(self):
        it([]).should.be.empty
        it({}).should.be.empty
        it(()).should.be.empty

        it((
            1,
            2,
            3,
        )).shouldnt.be.empty
        it([
            1,
            2,
            3,
        ]).shouldnt.be.empty
        it({1: 2, 3: 4}).shouldnt.be.empty
Example #38
0
 def test_uniq_values(self):
     it(None).be.none
     it(True).be.true
     it(False).be.false
     it(1).be.no.none
     it(1).be.no.true
     it(1).be.no.false
Example #39
0
    def test_contain(self):
        it([1, 2, 3]).should.contain(1)
        it(set([1, 2, 3])).should.contain(3)
        it({'a': 1, 'b': 2}).should.contain('a')

        it([1, 2, 3]).contain(1, 2)
        it(set([1, 2, 3])).contain(2, 3)
        it({'a': 1, 'b': 2}).should.contain('a', 'b')
Example #40
0
    def test_equal(self):
        it(0).be.equal(0)
        it('string').be.equal('string')
        if not py3:
            it(u'string').be.equal(u'string')
            it(u'中文').be.equal(u'中文')
        it({}).be.equal({})
        it([]).be.equal([])
        it(()).be.equal(())

        # 自定义的等于
        class A(object):

            def __init__(self, val):
                self.val = val

            def __eq__(self, other):
                return self.val != other.val
        it(A(1)).be.equal(A(3))
Example #41
0
 def test_key(self):
     it({'l1': 'v1'}).have.key('l1').which.should.be.equal('v1')
     it({'l1': 'v1'}).have.no.key('l2').which.be.none
Example #42
0
    def test_less(self):
        it(0).be.less(5)
        it(5).be.no.less(5)
        it(5).be.no.less(4)

        # below
        it(0).be.below(5)
        it(5).be.no.below(5)
        it(5).be.no.below(4)
Example #43
0
    def test_empty(self):
        it([]).should.be.empty
        it({}).should.be.empty
        it(()).should.be.empty


        it((1,2,3,)).shouldnt.be.empty
        it([1,2,3,]).shouldnt.be.empty
        it({1:2,3:4}).shouldnt.be.empty
Example #44
0
 def test_embeded(self):
     it(lambda: it(1).should.equal(2)).throw(AssertionError)