def setUp(self): self.model = mock.Mock( cells={ 'Sh1!' + addr: xltypes.XLCell('Sh1!' + addr, value=idx) for idx, addr in enumerate(('A1', 'A2', 'B1', 'B2')) }, ranges={'Sh1!A1:B2': xltypes.XLRange('Sh1!A1:B2')}, defined_names={}, ) self.model.defined_names['first'] = self.model.ranges['Sh1!A1:B2']
def test_float(self): cell = xltypes.XLCell('Sheet1!A1', 5, 'SUM(A1:B1)') self.assertEqual(float(cell), 5.0)
def test_hash(self): cell = xltypes.XLCell('Sheet1!A1', 5, 'SUM(A1:B1)') self.assertEqual(hash(cell), hash(('Sheet1', 1, 1)))
def test_formula(self): cell = xltypes.XLCell('Sheet1!A1', 5, 'SUM(A1:B1)') self.assertEqual(cell.formula, 'SUM(A1:B1)')
def test_value(self): cell = xltypes.XLCell('Sheet1!A1', 5) self.assertEqual(cell.value, 5)
def test_address_with_bad_sheet(self): # While the sheet name should be quoted, internally, the code often # just puts the sheet name in to produce unique keys, so the utility # supports unquoted sheets as well. self.assertEqual( xltypes.XLCell('Bad Sheet!A1').address, 'Bad Sheet!A1')
def test_address_with_range(self): with self.assertRaises(Exception) as context: xltypes.XLCell('Sheet1!A1:B1') self.assertTrue('This is a Range' in context.exception)
def test_address(self): xlcell = xltypes.XLCell('Sheet1!A1') address = 'Sheet1!A1' self.assertEqual(address, xlcell.address)