本文整理匯總了Python中report_builder.ReportBuilder類的典型用法代碼示例。如果您正苦於以下問題:Python ReportBuilder類的具體用法?Python ReportBuilder怎麽用?Python ReportBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ReportBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_report
def test_report(self):
source = """\
import example_printing
__live_coding_context__ = globals()['report_builder'] # variable name is important!
example_printing.custom_print('42', 'xyz')
"""
expected_report_python2 = """\
print '42xyz'
"""
expected_report_python3 = """\
print('42xyz')
"""
expected_report = (expected_report_python3
if version_info.major >= 3
else expected_report_python2)
report_builder = ReportBuilder()
environment = dict(report_builder=report_builder)
swallower = FileSwallower(sys.stdout)
with patch('sys.stdout', swallower):
exec(source, environment, environment)
report = report_builder.report()
self.assertReportEqual(expected_report, report)
示例2: test_assign_function
def test_assign_function(self):
# SETUP
expected_report = ''
f = lambda n: n + 1
# EXEC
builder = ReportBuilder()
builder.assign(name='f', value=f, line_number=2)
report = builder.report()
# VERIFY
self.assertEqual(expected_report.splitlines(), report.splitlines())
示例3: test_multiple_messages
def test_multiple_messages(self):
# SETUP
expected_report = """\
x = 1 y = 2 """
# EXEC
builder = ReportBuilder()
builder.assign(name='x', value=1, line_number=1)
builder.assign(name='y', value=2, line_number=1)
report = builder.report()
# VERIFY
self.assertEqual(expected_report.splitlines(), report.splitlines())
示例4: test_assign_object_without_repr
def test_assign_object_without_repr(self):
# SETUP
expected_report = ''
class class_without_repr(object):
pass
# EXEC
builder = ReportBuilder()
builder.assign(name='x', value=class_without_repr(), line_number=2)
report = builder.report()
# VERIFY
self.assertEqual(expected_report.splitlines(), report.splitlines())
示例5: test_delete_item
def test_delete_item(self):
# SETUP
expected_report = "d = {'a': 1}"
d = {'a': 1, 'b': 2}
expected_d = {'a': 1}
# EXEC
builder = ReportBuilder()
del builder.record_delete(name='d', target=d, line_number=1)['b']
report = builder.report()
# VERIFY
self.assertReportEqual(expected_report, report)
self.assertEqual(expected_d, d)
示例6: test_assign_function
def test_assign_function(self):
# SETUP
expected_report = ''
def f(n):
return n+1
# EXEC
builder = ReportBuilder()
builder.assign(name='f', value=f, line_number=2)
report = builder.report()
# VERIFY
self.assertReportEqual(expected_report, report)
示例7: test_assign_object_with_repr_exception
def test_assign_object_with_repr_exception(self):
# SETUP
expected_report = ''
class BadReprClass(object):
def __repr__(self):
raise NotImplementedError()
# EXEC
builder = ReportBuilder()
builder.assign(name='m', value=BadReprClass(), line_number=1)
report = builder.report()
# VERIFY
self.assertReportEqual(expected_report, report)
示例8: test_return
def test_return(self):
# SETUP
expected_value = 'bob'
expected_report = """\
return 'bob'
"""
# EXEC
builder = ReportBuilder()
value = builder.return_value(value=expected_value, line_number=2)
report = builder.report()
# VERIFY
self.assertEqual(expected_report.splitlines(), report.splitlines())
self.assertEqual(expected_value, value)
示例9: test_assign
def test_assign(self):
# SETUP
expected_value = 5
expected_report = """\
x = 5
"""
# EXEC
builder = ReportBuilder()
value = builder.assign(name='x', value=expected_value, line_number=2)
report = builder.report()
# VERIFY
self.assertEqual(expected_report.splitlines(), report.splitlines())
self.assertEqual(expected_value, value)
示例10: test_call_no_change
def test_call_no_change(self):
# SETUP
expected_report = ""
expected_result = 23
# EXEC
builder = ReportBuilder()
result = builder.record_call(names=['a'],
displays_before=['[1, 2]'],
result=expected_result,
displays_after=['[1, 2]'],
line_number=2)
report = builder.report()
# VERIFY
self.assertReportEqual(expected_report, report)
self.assertEqual(expected_result, result)
示例11: trace_code
def trace_code(self, source):
builder = ReportBuilder(self.message_limit)
try:
tree = parse(source)
visitor = TraceAssignments()
new_tree = visitor.visit(tree)
fix_missing_locations(new_tree)
code = compile(new_tree, PSEUDO_FILENAME, 'exec')
self.environment[CONTEXT_NAME] = builder
exec code in self.environment
except SyntaxError, ex:
messages = traceback.format_exception_only(type(ex), ex)
builder.add_message(messages[-1].strip() + ' ', ex.lineno)
示例12: test_call_no_change
def test_call_no_change(self):
# SETUP
expected_report = ""
expected_result = 23
# EXEC
builder = ReportBuilder()
result = builder.record_call(name='a',
display_before='[1, 2]',
result=expected_result,
display_after='[1, 2]',
line_number=2)
report = builder.report()
# VERIFY
self.assertEqual(expected_report.splitlines(), report.splitlines())
self.assertEqual(expected_result, result)
示例13: test_assign_object_with_multiline_repr
def test_assign_object_with_multiline_repr(self):
# SETUP
expected_report = 'm = multiline_class(1, 2) '
class multiline_class(object):
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return "multiline_class(%r,\n%r)" % (self.x, self.y)
# EXEC
builder = ReportBuilder()
builder.assign(name='m', value=multiline_class(1, 2), line_number=1)
report = builder.report()
# VERIFY
self.assertEqual(expected_report.splitlines(), report.splitlines())
示例14: test_frames
def test_frames(self):
# SETUP
expected_report = """\
i = 1 | i = 2
n = 2 | """
# EXEC
builder = ReportBuilder()
frame1 = builder.start_frame(1, 2)
frame1.assign(name='i', value=1, line_number=1)
frame2 = builder.start_frame(1, 2)
frame2.assign(name='i', value=2, line_number=1)
frame1.assign(name='n', value=2, line_number=2)
report = builder.report()
# VERIFY
self.assertEqual(expected_report.splitlines(), report.splitlines())
示例15: test_return_multiline
def test_return_multiline(self):
# SETUP
class Multiline(object):
def __repr__(self):
return 'Multiline(\n)'
expected_value = Multiline()
expected_report = """\
return Multiline( )
"""
# EXEC
builder = ReportBuilder()
value = builder.return_value(value=expected_value, line_number=2)
report = builder.report()
# VERIFY
self.assertReportEqual(expected_report, report)
self.assertEqual(expected_value, value)