我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用timeit.reindent()。
def __init__(self, stmt, setup='pass', timer=timeit.default_timer, globals=globals()): # copy of timeit.Timer.__init__ # similarity index 95% self.timer = timer stmt = timeit.reindent(stmt, 8) setup = timeit.reindent(setup, 4) src = timeit.template % {'stmt': stmt, 'setup': setup} self.src = src # Save for traceback display code = compile(src, timeit.dummy_src_name, "exec") ns = {} #exec code in globals(), ns -- original timeit code exec_(code, globals, ns) # -- we use caller-provided globals instead self.inner = ns["inner"]
def test_reindent_empty(self): self.assertEqual(timeit.reindent("", 0), "") self.assertEqual(timeit.reindent("", 4), "")
def test_reindent_single(self): self.assertEqual(timeit.reindent("pass", 0), "pass") self.assertEqual(timeit.reindent("pass", 4), "pass")
def test_reindent_multi_empty(self): self.assertEqual(timeit.reindent("\n\n", 0), "\n\n") self.assertEqual(timeit.reindent("\n\n", 4), "\n \n ")
def test_reindent_multi(self): self.assertEqual(timeit.reindent( "print()\npass\nbreak", 0), "print()\npass\nbreak") self.assertEqual(timeit.reindent( "print()\npass\nbreak", 4), "print()\n pass\n break")