PageRenderTime 99ms CodeModel.GetById 90ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/functional_tests/test_generator_fixtures.py

https://bitbucket.org/jpellerin/nose/
Python | 58 lines | 41 code | 13 blank | 4 comment | 6 complexity | aec368a5de80f0a0a072c16e8e502651 MD5 | raw file
 1from nose.tools import eq_
 2called = []
 3
 4def outer_setup():
 5    called.append('outer_setup')
 6
 7def outer_teardown():
 8    called.append('outer_teardown')
 9
10def inner_setup():
11    called.append('inner_setup')
12
13def inner_teardown():
14    called.append('inner_teardown')
15
16def test_gen():
17    called[:] = []
18    for i in range(0, 5):
19        yield check, i
20        
21def check(i):
22    expect = ['outer_setup']
23    for x in range(0, i):
24        expect.append('inner_setup')
25        expect.append('inner_teardown')
26    expect.append('inner_setup')
27    eq_(called, expect)
28
29    
30test_gen.setup = outer_setup
31test_gen.teardown = outer_teardown
32check.setup = inner_setup
33check.teardown = inner_teardown
34
35
36class TestClass(object):
37    def setup(self):
38        print "setup called in", self
39        self.called = ['setup']
40
41    def teardown(self):
42        print "teardown called in", self
43        eq_(self.called, ['setup'])
44        self.called.append('teardown')
45
46    def test(self):
47        print "test called in", self
48        for i in range(0, 5):
49            yield self.check, i
50
51    def check(self, i):
52        print "check called in", self
53        expect = ['setup']
54        #for x in range(0, i):
55        #    expect.append('setup')
56        #    expect.append('teardown')
57        #expect.append('setup')
58        eq_(self.called, expect)