def test_computational_variable(self): """Test the computational variables""" variable_name = "test_var" # Un-anchored variable u_var_cell_a = Cell(None, None, 99, cell_indices=self.cell_indices, is_variable=True, variable_name="something", cell_type=CellType.computational) u_var_cell_b = Cell(None, None, 77, cell_indices=self.cell_indices, is_variable=True, variable_name="xyz", cell_type=CellType.computational) u_var_cell_sum = u_var_cell_a + u_var_cell_b # Here the following have to be set directly (not a problem, as it # is not accessed directly in production) u_var_cell_sum.is_variable = True u_var_cell_sum.variable_name = variable_name self.assertEqual(u_var_cell_sum.value, 99 + 77) # Reference to variable u_ref_cell = Cell.variable(u_var_cell_sum) u_ref_cell_word = u_ref_cell.parse self.assertEqual(u_ref_cell_word['python_numpy'], str(variable_name)) self.assertEqual(u_ref_cell_word['excel'], '=' + str(variable_name)) # Check the computation strings self.assertEqual(u_var_cell_sum.parse['excel'], '=99+77') self.assertEqual(u_var_cell_sum.parse['python_numpy'], '99+77')
def test_variable(self): """Test the variables parsing""" with self.assertRaises(ValueError): Cell.variable(self.a_operand) variable_name = "test_var" var_value = 99 # Un-anchored variable u_var_cell = Cell(None, None, 99, cell_indices=self.cell_indices, is_variable=True, variable_name=variable_name, cell_type=CellType.computational) self.assertEqual(u_var_cell.value, var_value) # Reference to variable u_ref_cell = Cell.variable(u_var_cell) u_ref_cell_word = u_ref_cell.parse self.assertEqual(u_ref_cell_word['python_numpy'], str(variable_name)) self.assertEqual(u_ref_cell_word['excel'], '=' + str(variable_name))