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


Python worksheet.Worksheet类代码示例

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


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

示例1: test_recalc_cell_catches_cell_errors_and_adds_them_to_console

    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,代码行数:30,代码来源:test_calculate.py

示例2: test_calculate_catches_and_reports_exceptions_to_console

    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,代码行数:27,代码来源:test_calculate.py

示例3: test_mystdout_pushes_print_commands_to_worksheet

 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,代码行数:7,代码来源:test_calculate.py

示例4: test_two_tuple_parameters

 def test_two_tuple_parameters(self):
     ws = Worksheet()
     cell_range = ws.cell_range((2, 3), (5, 4))
     self.assertEquals(cell_range.left, 2)
     self.assertEquals(cell_range.top, 3)
     self.assertEquals(cell_range.right, 5)
     self.assertEquals(cell_range.bottom, 4)
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:7,代码来源:test_worksheet.py

示例5: test_constant

 def test_constant(self):
     worksheet = Worksheet()
     worksheet[1, 2].formula = '3'
     calculate(worksheet, SANITY_CHECK_USERCODE % ('', ''), sentinel.private_key)
     self.assertEquals(worksheet.keys(), [(1, 2)])
     self.assertEquals(worksheet[(1, 2)].formula, '3')
     self.assertEquals(worksheet[(1, 2)].value, 3)
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:7,代码来源:test_calculate.py

示例6: test_clear_values_deletes_cells_with_empty_formula

 def test_clear_values_deletes_cells_with_empty_formula(self):
     ws = Worksheet()
     ws[1, 2].formula = ''
     ws[1, 2].value = "hello!"
     ws[1, 2].formatted_value = "Guten Tag!"
     ws.clear_values()
     self.assertFalse((1, 2) in ws)
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:7,代码来源:test_worksheet.py

示例7: test_iteration_yields_cells

    def test_iteration_yields_cells(self):
        ws = Worksheet()
        ws[1, 1].formula = 'A1'
        ws[2, 4].formula = 'B4'
        ws.name = 'any old name'

        self.assertEquals(ws.items(), [((1, 1), ws[1, 1]), ((2, 4), ws[2, 4])])
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:7,代码来源:test_worksheet.py

示例8: test_api_view_should_return_errors_and_no_values_if_unjsonify_worksheet_result_has_errors

    def test_api_view_should_return_errors_and_no_values_if_unjsonify_worksheet_result_has_errors(self, mock_get_object):
        mock_sheet = mock_get_object.return_value
        mock_sheet.owner = self.user

        worksheet = Worksheet()
        worksheet[1, 3].formula = '=string'
        worksheet[1, 3].value = 'test value'
        worksheet._usercode_error = {
            "message": "I am an error message",
            "line": 2
        }
        mock_sheet.unjsonify_worksheet.side_effect = lambda: worksheet
        mock_sheet.allow_json_api_access = True
        self.request.method = 'POST'
        self.request.POST['api_key'] = mock_sheet.api_key = 'key'

        expected_json = {
            "usercode_error" : {
                "message": "I am an error message",
                "line": "2"
            }
        }

        actual = calculate_and_get_json_for_api(self.request, self.user.username, self.sheet.id)

        self.assertFalse(mock_sheet.save.called)
        self.assertTrue(isinstance(actual, HttpResponse))
        self.assertEquals(actual.content, json.dumps(expected_json))
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:28,代码来源:test_views_api_0_1.py

示例9: test_setattr_should_not_delegate_to_setitem_if_attr_name_is_not_valid_cell_name

    def test_setattr_should_not_delegate_to_setitem_if_attr_name_is_not_valid_cell_name(self):
        ws = Worksheet()
        ws.__setitem__ = Mock()

        ws.A1 = 23

        self.assertEquals( ws.__setitem__.call_args_list, [] )
        self.assertEquals( ws.A1, 23 )
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:8,代码来源:test_worksheet.py

示例10: test_getattr_should_delegate_to_getitem

    def test_getattr_should_delegate_to_getitem(self):
        ws = Worksheet()
        ws.__getitem__ = Mock()

        retval = ws.A1

        self.assertEquals( retval, ws.__getitem__.return_value )
        self.assertEquals( ws.__getitem__.call_args_list, [(('A1',), {})] )
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:8,代码来源:test_worksheet.py

示例11: test_setitem_on_locations_should_reject_non_cell_instances

    def test_setitem_on_locations_should_reject_non_cell_instances(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(1, 2))

        expected_message_re = "^Worksheet locations must be Cell objects"
        with self.assertRaisesRegexp(TypeError, expected_message_re):
            ws[3, 4] = 123
        self.assertEquals(ws.to_location.call_args_list, [(((3, 4),), {})])
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:8,代码来源:test_worksheet.py

示例12: test_getitem_should_use_original_key_if_to_location_gives_none

    def test_getitem_should_use_original_key_if_to_location_gives_none(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(3, 4))

        ws[3, 4].formula = "hello"

        self.assertEquals(ws.to_location.call_args_list, [(((3, 4),), {})])
        self.assertEquals(ws.keys(), [(3, 4)])
        self.assertEquals(ws.values()[0].formula, "hello")
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:9,代码来源:test_worksheet.py

示例13: test_getitem_should_use_to_location_result_if_it_is_not_none

    def test_getitem_should_use_to_location_result_if_it_is_not_none(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(1, 2))

        ws[3, 4].formula = "hello"

        self.assertEquals(ws.to_location.call_args_list, [(((3, 4),), {})])
        self.assertEquals(ws.keys(), [(1, 2)])
        self.assertEquals(ws.values()[0].formula, "hello")
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:9,代码来源:test_worksheet.py

示例14: test_setitem_on_locations_should_accept_cell_instances

    def test_setitem_on_locations_should_accept_cell_instances(self):
        ws = Worksheet()
        ws.to_location = Mock(return_value=(1, 2))
        cell = Cell()

        ws[3, 4] = cell

        self.assertEquals(ws.to_location.call_args_list, [(((3, 4),), {})])
        self.assertEquals(ws.keys(), [(1, 2)])
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:9,代码来源:test_worksheet.py

示例15: test_run_worksheet_with_overrides

    def test_run_worksheet_with_overrides(self, mock_urllib2):
        self.maxDiff = None

        cellA2 = Cell()
        cellA2.formula = '1'
        cellA2.value = 1

        cellC3 = Cell()
        cellC3.formula = '5'
        cellC3.value = 5

        cellE4 = Cell()
        cellE4.formula = '=A2 + C3'
        cellE4.value = 6

        overrides = {
            (1, 2): '11',
            (3, 3): 55,
            (4, 1): '="abc"',
            'dirigible_l337_private_key': sentinel.private_key
        }

        result_of_calculation_json = '''{
            "name": "Untitled",
            "1": {
                "2": 11
            },
            "3": {
                "3": 55
            },
            "4": {
                "1": "abc"
            },
            "5": {
                "4": 66
            }
        }'''

        mock_opener = mock_urllib2.build_opener.return_value
        mock_urlopen_file = mock_opener.open.return_value
        mock_urlopen_file.read.return_value = result_of_calculation_json

        worksheet_url = 'ws_url/'
        result = run_worksheet(worksheet_url, overrides, sentinel.private_key)

        target_url = '%sv%s/json/' % (worksheet_url, CURRENT_API_VERSION)
        self.assertCalledOnce(mock_opener.open, target_url, data=urlencode(overrides))
        self.assertEquals(type(result), Worksheet)
        expected_sheet = Worksheet()
        expected_sheet.name = 'Untitled'
        expected_sheet[1, 2].value = 11
        expected_sheet[3, 3].value = 55
        expected_sheet[4, 1].value = 'abc'
        expected_sheet[5, 4].value = 66

        self.assertEquals(result, expected_sheet)
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:56,代码来源:test_calculate.py


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