def test_execution_context_save(self): with Profiler(db=None, collectors=['sql']) as p: for letter in ('a', 'b'): stack_level = profiler.stack_size() with ExecutionContext(letter=letter): self.env.cr.execute('SELECT 1') stack_level = profiler.stack_size() entries = p.collectors[0].entries self.assertEqual(entries[0]['exec_context'][stack_level], {'letter': 'a'}) self.assertEqual(entries[1]['exec_context'][stack_level], {'letter': 'b'})
def test_execution_context_nested(self): """ This test checks that an execution can be nested at the same level of the stack. """ with Profiler(db=None, collectors=['sql']) as p: stack_level = profiler.stack_size() with ExecutionContext(letter='a'): self.env.cr.execute('SELECT 1') with ExecutionContext(letter='b'): self.env.cr.execute('SELECT 1') with ExecutionContext(letter='c'): self.env.cr.execute('SELECT 1') self.env.cr.execute('SELECT 1') entries = p.collectors[0].entries self.assertEqual( entries.pop(0)['exec_context'], ((stack_level, { 'letter': 'a' }), )) self.assertEqual( entries.pop(0)['exec_context'], ((stack_level, { 'letter': 'a' }), (stack_level, { 'letter': 'b' }))) self.assertEqual( entries.pop(0)['exec_context'], ((stack_level, { 'letter': 'a' }), (stack_level, { 'letter': 'c' }))) self.assertEqual( entries.pop(0)['exec_context'], ((stack_level, { 'letter': 'a' }), ))