def test_to_location(self): ws = Worksheet() self.assertEquals( ws.to_location((1, 2)), (1, 2) ) self.assertEquals( ws.to_location((1L, 2L)), (1L, 2L) ) self.assertEquals( ws.to_location(('a', 2)), (1, 2) ) self.assertEquals( ws.to_location(('A', 2)), (1, 2) ) self.assertEquals( ws.to_location('a2'), (1, 2) ) self.assertEquals( ws.to_location('A2'), (1, 2) ) self.assertEquals( ws.to_location('A'), None ) self.assertEquals( ws.to_location('1A'), None ) self.assertEquals( ws.to_location((1, 'A')), None ) self.assertEquals( ws.to_location(123), None ) self.assertEquals( ws.to_location(object()), None )
def test_setitem_on_non_locations_raises_keyerror(self): ws = Worksheet() ws.to_location = Mock(return_value=None) with self.assertRaisesRegexp( InvalidKeyError, "^'random key' is not a valid cell location$"): ws['random key'] = 'sausages'
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), ), {})])
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),), {})])
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")
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")
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)])
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")
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")
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)])
def test_to_location(self): ws = Worksheet() self.assertEquals(ws.to_location((1, 2)), (1, 2)) self.assertEquals(ws.to_location((1L, 2L)), (1L, 2L)) self.assertEquals(ws.to_location(('a', 2)), (1, 2)) self.assertEquals(ws.to_location(('A', 2)), (1, 2)) self.assertEquals(ws.to_location('a2'), (1, 2)) self.assertEquals(ws.to_location('A2'), (1, 2)) self.assertEquals(ws.to_location('A'), None) self.assertEquals(ws.to_location('1A'), None) self.assertEquals(ws.to_location((1, 'A')), None) self.assertEquals(ws.to_location(123), None) self.assertEquals(ws.to_location(object()), None)
def test_setitem_on_non_locations_raises_keyerror(self): ws = Worksheet() ws.to_location = Mock(return_value=None) with self.assertRaisesRegexp(InvalidKeyError, "^'random key' is not a valid cell location$"): ws['random key'] = 'sausages'