def test_recalc_cell_should_clear_cell_error_and_not_add_to_console_text_on_eval_succeeding(self): cell = Cell() cell.formula = '=123' cell.error = 'old error, just hanging around...' worksheet = Worksheet() location = (1, 11) worksheet[location] = cell node = Mock() node.parents = [] graph = {location: node } context = { 'worksheet': { location: cell, } } recalculate_cell(location, Mock(), graph, context) self.assertEqual( worksheet[location].error, None ) self.assertEqual( worksheet[location].value, 123 ) self.assertEqual( worksheet._console_text, '' )
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)
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)
def test_recalculate_cell_should_perform_true_division(self): location = (1, 2) cell = Cell() cell.python_formula = '1/4' context = { "worksheet": { location: cell } } # Mocked out to avoid explosion -- tested in another unit test. node = Mock() node.parents = [] recalculate_cell(location, None, { location: node }, context) self.assertEquals(cell.value, 0.25)
def test_recalculate_cell_evals_python_formula_in_context_and_puts_results_in_worksheet(self): location = (1, 2) cell = Cell() cell.python_formula = '100 + fred' context = { 'fred': 23, "worksheet": { location: cell } } # Mocked out to avoid explosion -- tested in another unit test. node = Mock() node.parents = [] recalculate_cell(location, None, { location: node }, context) self.assertEquals(cell.value, 123)
def test_recalculate_cell_should_perform_true_division(self): location = (1, 2) cell = Cell() cell.python_formula = '1/4' context = {"worksheet": {location: cell}} # Mocked out to avoid explosion -- tested in another unit test. node = Mock() node.parents = [] recalculate_cell(location, None, {location: node}, context) self.assertEquals(cell.value, 0.25)
def test_recalculate_cell_evals_python_formula_in_context_and_puts_results_in_worksheet( self): location = (1, 2) cell = Cell() cell.python_formula = '100 + fred' context = {'fred': 23, "worksheet": {location: cell}} # Mocked out to avoid explosion -- tested in another unit test. node = Mock() node.parents = [] recalculate_cell(location, None, {location: node}, context) self.assertEquals(cell.value, 123)
def test_recalculate_cell_should_remove_nodes_from_dependency_graph(self): location = (1, 2) cell = Cell() cell.formula = '=123' leaf_queue = Queue() parent = Mock() parent_loc = (2, 3) node = Mock() node.parents = set([(parent_loc)]) graph = { location: node, parent_loc: parent } context = { 'worksheet': { location: cell, } } recalculate_cell(location, leaf_queue, graph, context) self.assertEquals( node.remove_from_parents.call_args, (([parent], leaf_queue,), {}) )
def test_recalculate_cell_should_remove_nodes_from_dependency_graph(self): location = (1, 2) cell = Cell() cell.formula = '=123' leaf_queue = Queue() parent = Mock() parent_loc = (2, 3) node = Mock() node.parents = set([(parent_loc)]) graph = {location: node, parent_loc: parent} context = { 'worksheet': { location: cell, } } recalculate_cell(location, leaf_queue, graph, context) self.assertEquals(node.remove_from_parents.call_args, (( [parent], leaf_queue, ), {}))
def test_recalc_cell_should_clear_cell_error_and_not_add_to_console_text_on_eval_succeeding( self): cell = Cell() cell.formula = '=123' cell.error = 'old error, just hanging around...' worksheet = Worksheet() location = (1, 11) worksheet[location] = cell node = Mock() node.parents = [] graph = {location: node} context = { 'worksheet': { location: cell, } } recalculate_cell(location, Mock(), graph, context) self.assertEqual(worksheet[location].error, None) self.assertEqual(worksheet[location].value, 123) self.assertEqual(worksheet._console_text, '')