From: Jeremy Thurgood Date: Thu, 15 May 2014 19:27:23 +0000 (+0200) Subject: Better location shift action text. X-Git-Tag: 0.1~267 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=87f51eafe4495e6ca13cf1702e0c9dce4862dc49;p=naja.git Better location shift action text. --- diff --git a/naja/actions.py b/naja/actions.py index 99e16bf..ff8a431 100644 --- a/naja/actions.py +++ b/naja/actions.py @@ -18,7 +18,15 @@ class LocationAction(object): 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) @@ -100,7 +108,7 @@ class GainHealthAndClearBitsOrMSB(LocationAction): 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']) diff --git a/naja/tests/test_actions.py b/naja/tests/test_actions.py index 3497ee4..5cf4c76 100644 --- a/naja/tests/test_actions.py +++ b/naja/tests/test_actions.py @@ -50,6 +50,33 @@ class TestActions(TestCase): 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]))