当前位置: 首页>>代码示例>>Python>>正文


Python Worksheet.add_console_text方法代码示例

本文整理汇总了Python中dirigible.sheet.worksheet.Worksheet.add_console_text方法的典型用法代码示例。如果您正苦于以下问题:Python Worksheet.add_console_text方法的具体用法?Python Worksheet.add_console_text怎么用?Python Worksheet.add_console_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dirigible.sheet.worksheet.Worksheet的用法示例。


在下文中一共展示了Worksheet.add_console_text方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_mystdout_pushes_print_commands_to_worksheet

# 需要导入模块: from dirigible.sheet.worksheet import Worksheet [as 别名]
# 或者: from dirigible.sheet.worksheet.Worksheet import add_console_text [as 别名]
 def test_mystdout_pushes_print_commands_to_worksheet(self):
     ws = Worksheet()
     mso = MyStdout(ws)
     mso.write('weeeeeee!')
     ws2 = Worksheet()
     ws2.add_console_text('weeeeeee!', log_type='output')
     self.assertEquals(ws._console_text, ws2._console_text)
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:9,代码来源:test_calculate.py

示例2: test_calculate_catches_and_reports_exceptions_to_console

# 需要导入模块: from dirigible.sheet.worksheet import Worksheet [as 别名]
# 或者: from dirigible.sheet.worksheet.Worksheet import add_console_text [as 别名]
    def test_calculate_catches_and_reports_exceptions_to_console(self):

        def patched_execute_usercode(_, context):
            exec(
                'import sys\n'
                'def func():\n'
                '    x = my_value\n'
                'func()\n',
                context
            )
        worksheet = Worksheet()
        worksheet.add_console_text = Mock()
        original_execute_usercode = calculate_module.execute_usercode
        calculate_module.execute_usercode = patched_execute_usercode
        try:
            calculate(worksheet, sentinel.usercode, sentinel.private_key)
        finally:
            calculate_module.execute_usercode = original_execute_usercode

        expected_error_text = dedent("""
                    NameError: global name \'my_value\' is not defined
                        User code line 4
                        User code line 3, in func\n""")[1:]
        self.assertIn(
            call(expected_error_text),
            worksheet.add_console_text.call_args_list
        )
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:29,代码来源:test_calculate.py

示例3: test_recalc_cell_catches_cell_errors_and_adds_them_to_console

# 需要导入模块: from dirigible.sheet.worksheet import Worksheet [as 别名]
# 或者: from dirigible.sheet.worksheet.Worksheet import add_console_text [as 别名]
    def test_recalc_cell_catches_cell_errors_and_adds_them_to_console(self):
        cell = Cell()
        cell.formula = "=123"
        cell.python_formula = '_raise(Exception("OMGWTFBBQ"))'
        cell.error = 'old error, just hanging around...'
        worksheet = Worksheet()
        location = (1, 11)
        worksheet[location] = cell

        # Mocked out to avoid explosion -- tested in another unit test.
        node = Mock()
        node.parents = []
        graph = {location: node }

        context = { 'worksheet': worksheet, "_raise": _raise }
        worksheet.add_console_text = Mock()

        recalculate_cell(location, Mock(), graph, context)

        self.assertEqual(
            worksheet[location].error,
            'Exception: OMGWTFBBQ'
        )

        expected_error_text = "Exception: OMGWTFBBQ\n    Formula '%s' in A11\n" % (
                cell.formula)

        self.assertCalledOnce(worksheet.add_console_text, expected_error_text)

        self.assertEquals(worksheet[location].value, undefined)
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:32,代码来源:test_calculate.py

示例4: test_append_console_text

# 需要导入模块: from dirigible.sheet.worksheet import Worksheet [as 别名]
# 或者: from dirigible.sheet.worksheet.Worksheet import add_console_text [as 别名]
    def test_append_console_text(self):
        ws = Worksheet()
        ws.add_console_text('a first error')
        self.assertEquals(
            ws._console_text,
            '<span class="console_error_text">a first error</span>')

        ws.add_console_text('a second error\noh noez!')
        self.assertEquals(
            ws._console_text,
            '<span class="console_error_text">a first error</span>'
            '<span class="console_error_text">a second error\n'
            'oh noez!</span>')

        ws.add_console_text('not an error', log_type='output')
        self.assertEquals(
            ws._console_text,
            '<span class="console_error_text">a first error</span>'
            '<span class="console_error_text">a second error\n'
            'oh noez!</span>'
            '<span class="console_output_text">not an error</span>')

        ws.add_console_text('A system timing report, for example :-)', log_type='system')
        self.assertEquals(
            ws._console_text,
            '<span class="console_error_text">a first error</span>'
            '<span class="console_error_text">a second error\n'
            'oh noez!</span>'
            '<span class="console_output_text">not an error</span>'
            '<span class="console_system_text">A system timing report, for example :-)</span>')

        ws.add_console_text('<b></b>', log_type='output')
        self.assertEquals(
            ws._console_text,
            '<span class="console_error_text">a first error</span>'
            '<span class="console_error_text">a second error\n'
            'oh noez!</span>'
            '<span class="console_output_text">not an error</span>'
            '<span class="console_system_text">A system timing report, for example :-)</span>'
            '<span class="console_output_text">&lt;b&gt;&lt;/b&gt;</span>')
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:42,代码来源:test_worksheet.py

示例5: test_calculate_catches_and_reports_syntax_errors_to_console

# 需要导入模块: from dirigible.sheet.worksheet import Worksheet [as 别名]
# 或者: from dirigible.sheet.worksheet.Worksheet import add_console_text [as 别名]
    def test_calculate_catches_and_reports_syntax_errors_to_console(self, mock_evaluate_formulae_in_context, mock_execute_usercode):
        worksheet = Worksheet()
        worksheet.add_console_text = Mock()

        def execute_usercode(_, __):
            exec('import sys:\nx == my_value')
        mock_execute_usercode.side_effect = execute_usercode
        calculate(worksheet, sentinel.usercode, sentinel.private_key)

        expected_error_text = 'Syntax error at character 11 (line 1)\n'
        self.assertIn(
            ((expected_error_text,), {}),
            worksheet.add_console_text.call_args_list
        )
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:16,代码来源:test_calculate.py

示例6: test_calculate_clears_previous_worksheet_console_text_and_reports_time

# 需要导入模块: from dirigible.sheet.worksheet import Worksheet [as 别名]
# 或者: from dirigible.sheet.worksheet.Worksheet import add_console_text [as 别名]
    def test_calculate_clears_previous_worksheet_console_text_and_reports_time(self, mock_time):
        recalc_times = [1.3245, 0]
        def mock_time_fn():
            return recalc_times.pop()
        mock_time.side_effect = mock_time_fn
        worksheet = Worksheet()
        worksheet._console_text = 'previous errors'
        worksheet.add_console_text = Mock()

        calculate(worksheet, sentinel.usercode, sentinel.private_key)
        expected_text = 'Took 1.32s'
        self.assertEquals(worksheet.add_console_text.call_args_list[0],
                          ((expected_text,),{'log_type':'system'})
        )
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:16,代码来源:test_calculate.py

示例7: test_calculate_clears_previous_worksheet_console_text_and_reports_time_when_theres_an_error

# 需要导入模块: from dirigible.sheet.worksheet import Worksheet [as 别名]
# 或者: from dirigible.sheet.worksheet.Worksheet import add_console_text [as 别名]
    def test_calculate_clears_previous_worksheet_console_text_and_reports_time_when_theres_an_error(self, mock_time, mock_execute_usercode):
        recalc_times = [1.3245, 0]
        def mock_time_fn():
            return recalc_times.pop()
        mock_time.side_effect = mock_time_fn
        def throw_error(_, __):
            raise Exception('argh')
        mock_execute_usercode.side_effect = throw_error
        worksheet = Worksheet()
        worksheet._console_text = 'previous errors\n'
        worksheet.add_console_text = Mock()

        calculate(worksheet, sentinel.usercode, sentinel.private_key)

        self.assertNotIn('previous errors', worksheet._console_text)
        self.assertEquals(
            worksheet.add_console_text.call_args_list[-1],
            (('Took 1.32s',),{'log_type':'system'}),
        )
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:21,代码来源:test_calculate.py

示例8: test_report_cell_error

# 需要导入模块: from dirigible.sheet.worksheet import Worksheet [as 别名]
# 或者: from dirigible.sheet.worksheet.Worksheet import add_console_text [as 别名]
    def test_report_cell_error(self):
        worksheet = Worksheet()
        worksheet.add_console_text = Mock()
        worksheet[1, 2].formula = '=A1'

        report_cell_error(worksheet, (1, 2), ZeroDivisionError('hello'))

        self.assertEqual(
            worksheet[(1, 2)].error,
            'ZeroDivisionError: hello'
            )
        self.assertEqual(
            worksheet[(1, 2)].value,
            undefined
            )
        expected_error_text = dedent('''
            ZeroDivisionError: hello
                Formula '=A1' in A2
            ''')[1:]
        self.assertEqual(
            worksheet.add_console_text.call_args_list,
            [((expected_error_text,), {})],
            )
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:25,代码来源:test_errors.py


注:本文中的dirigible.sheet.worksheet.Worksheet.add_console_text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。