self.data = data
def get_text(self):
- return self.TEXT % self.data
+ substitutions = self.data.copy()
+ if 'direction' in self.data:
+ substitutions['rowcol'] = {
+ 'NORTH': 'column',
+ 'SOUTH': 'column',
+ 'EAST': 'row',
+ 'WEST': 'row',
+ }[self.data['direction']]
+ return self.TEXT % substitutions
def check_available(self, player):
return player.bits.check_bits(self.required_bits)
class ShiftLocations(LocationAction):
- TEXT = "Shift board locations %(direction)s."
+ TEXT = "Shift current %(rowcol)s %(direction)s."
def perform_action(self, board, location):
board.shift_locations(self.data['direction'])
check_available(set([BITS.MSB]), [], False)
check_available(set([BITS.MSB]), [BITS.MSB], True)
+ def test_get_text(self):
+ class LocationAction1(actions.LocationAction):
+ TEXT = "foo"
+ action1 = LocationAction1([])
+ self.assertEqual(action1.get_text(), "foo")
+
+ class LocationAction2(actions.LocationAction):
+ TEXT = "foo %(bar)s"
+ action2 = LocationAction2([], bar="baz")
+ self.assertEqual(action2.get_text(), "foo baz")
+
+ def test_get_text_row_column(self):
+ class DirectionAction(actions.LocationAction):
+ TEXT = "foo %(direction)s %(rowcol)s"
+
+ action_north = DirectionAction([], direction='NORTH')
+ self.assertEqual(action_north.get_text(), "foo NORTH column")
+
+ action_south = DirectionAction([], direction='SOUTH')
+ self.assertEqual(action_south.get_text(), "foo SOUTH column")
+
+ action_east = DirectionAction([], direction='EAST')
+ self.assertEqual(action_east.get_text(), "foo EAST row")
+
+ action_west = DirectionAction([], direction='WEST')
+ self.assertEqual(action_west.get_text(), "foo WEST row")
+
def test_bits_translation(self):
action = actions.LocationAction(set([BITS.NORTH, 'MSB']))
self.assertEqual(action.required_bits, set([BITS.NORTH, BITS.MSB]))