Ejemplo n.º 1
0
    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'
            }),
        )
 def test_to_ui_json_meta_data_includes_worksheet_console_text(self):
     sheet = Sheet(width=10, height=5)
     worksheet = Worksheet()
     worksheet._console_text = ['error1', 'error2']
     expected = dict(
         width=sheet.width,
         height=sheet.height,
         name='Untitled',
         console_text=worksheet._console_text)
     self.assertEquals(json.loads(sheet_to_ui_json_meta_data(sheet, worksheet)), expected)
Ejemplo n.º 3
0
 def test_to_ui_json_meta_data_includes_worksheet_console_text(self):
     sheet = Sheet(width=10, height=5)
     worksheet = Worksheet()
     worksheet._console_text = ['error1', 'error2']
     expected = dict(width=sheet.width,
                     height=sheet.height,
                     name='Untitled',
                     console_text=worksheet._console_text)
     self.assertEquals(
         json.loads(sheet_to_ui_json_meta_data(sheet, worksheet)), expected)
    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'})
        )
Ejemplo n.º 5
0
    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'
                          }))
    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'}),
        )
Ejemplo n.º 7
0
    def test_dependencies_get_put_in_json_as_array_of_arrays(self):
        self.maxDiff = None

        worksheet = Worksheet()
        worksheet.A1.dependencies = [(1, 2)]
        worksheet._console_text = ""

        worksheet_json = worksheet_to_json(worksheet)

        self.assertEquals(
            json.loads(worksheet_json),
            {
                u"1,1" : {
                    u"formula" : None,
                    u"formatted_value" : u"",
                    u"dependencies" : [[1, 2]],
                },

                u"_console_text": u"",
                u"_usercode_error": None,
            }
        )
Ejemplo n.º 8
0
    def test_worksheet_with_data_to_json(self):
        self.maxDiff = None

        worksheet = Worksheet()

        worksheet.B29.formula = "a constant"
        worksheet.B29.value = 56
        worksheet.B29.formatted_value = "fifty-six"
        worksheet.B29.error = "b0rken"

        worksheet.C29.formula = "another constant"
        worksheet.C29.value = ["value", "is", "a", "list"]
        worksheet.C29.formatted_value = "[the same list]"

        class UnJSONableObject(object):
            def __str__(self):
                return "The result of str-ing the object"
        worksheet.D29.formula = None
        worksheet.D29.value = UnJSONableObject()
        worksheet.D29.formatted_value = "The formatted object"

        worksheet.E29.formula = '=1 + 2'
        worksheet.E29.value = 3
        worksheet.E29.formatted_value = "Three"

        worksheet._console_text = "The console text"
        worksheet._usercode_error = { "message": "The usercode error", "line": 23 }

        worksheet_json = worksheet_to_json(worksheet)

        self.assertEquals(
            json.loads(worksheet_json),
            {
                u"2,29" : {
                    u"formula" : u"a constant",
                    u"value" : 56,
                    u"formatted_value": u"fifty-six",
                    u"error": u"b0rken"
                },

                u"3,29" : {
                    u"formula" : u"another constant",
                    u"value" : [u"value", u"is", u"a", u"list"],
                    u"formatted_value": u"[the same list]"
                },

                u"4,29" : {
                    u"formula" : None,
                    u"formatted_value": u"The formatted object",
                },

                u"5,29" : {
                    u"formula" : u"=1 + 2",
                    u"python_formula" : u"1 + 2",
                    u"value": 3,
                    u"formatted_value": u"Three",
                },

                u"_console_text": u"The console text",
                u"_usercode_error": { u"message": u"The usercode error", u"line": 23 },
            }
        )