示例#1
0
 def test_returns_valid_template_if_teardown_is_code(self):
     teardown = identity
     timer = Timer(teardown=teardown)
     output = template_output(teardown='_teardown()',
                              init=', _teardown=_teardown')
     self.assertEqual(timer.src, output)
     self.assertDictEqual({'_teardown': teardown}, timer.local_ns)
示例#2
0
 def test_returns_valid_template_with_all_callable_params(self):
     setup, stmt, teardown = identity, identity, identity
     timer = Timer(setup=setup, stmt=stmt, teardown=teardown)
     output = template_output(setup='_setup()', stmt='_stmt()',
                              teardown='_teardown()',
                              init=', _setup=_setup, _stmt=_stmt, '
                                   '_teardown=_teardown')
     self.assertEqual(timer.src, output)
     self.assertDictEqual({'_setup': setup, '_stmt': stmt,
                           '_teardown': teardown}, timer.local_ns)
示例#3
0
    def test_raises_if_stmt_and_teardown_contain_invalid_syntax(self):
        with self.assertRaises(SyntaxError) as cm:
            Timer(stmt="foo = 'bar', \\ ", teardown="bar = 'baz'")

        err = cm.exception

        if PYPY:
            self.assertTrue("Unknown character" in str(err))
        else:
            self.assertTrue('unexpected character after line' in str(err))
示例#4
0
 def test_returns_valid_template_if_stmt_is_code(self):
     stmt = identity
     timer = Timer(stmt=stmt)
     output = template_output(stmt='_stmt()', init=', _stmt=_stmt')
     self.assertEqual(timer.src, output)
     self.assertDictEqual({'_stmt': stmt}, timer.local_ns)
示例#5
0
 def test_returns_valid_template_if_setup_is_code(self):
     setup = identity
     timer = Timer(setup=setup)
     output = template_output(setup='_setup()', init=', _setup=_setup')
     self.assertEqual(timer.src, output)
     self.assertDictEqual({'_setup': setup}, timer.local_ns)
示例#6
0
 def test_returns_valid_template_with_all_str_params(self):
     setup, stmt, teardown = "a = 1 + 2", "b = 2 + 3", "c = 3 + 4"
     timer = Timer(setup=setup, stmt=stmt, teardown=teardown)
     self.assertEqual(timer.src, template_output(stmt, setup, teardown))
示例#7
0
 def test_returns_valid_template_if_teardown_is_str(self):
     teardown = "foo = 'bar'\nbar = 'baz'"
     timer = Timer(teardown=teardown)
     self.assertEqual(timer.src, template_output(teardown=teardown))
示例#8
0
 def test_returns_valid_template_if_stmt_is_str(self):
     stmt = "foo = 'bar'\nbar = 'baz'"
     timer = Timer(stmt=stmt)
     self.assertEqual(timer.src, template_output(stmt=stmt))
示例#9
0
    def test_raises_if_teardown_contains_invalid_syntax(self):
        with self.assertRaises(SyntaxError) as cm:
            Timer(teardown='foo = 1, 2, *')

        err = cm.exception
        self.assertTrue('invalid syntax' in str(err))
示例#10
0
    def test_raises_if_teardown_is_missing(self):
        with self.assertRaises(ValueError) as cm:
            Timer(teardown=None)

        err = cm.exception
        self.assertEqual(str(err), 'teardown is neither a string nor callable')