Better location shift action text.
authorJeremy Thurgood <firxen@gmail.com>
Thu, 15 May 2014 19:27:23 +0000 (21:27 +0200)
committerJeremy Thurgood <firxen@gmail.com>
Thu, 15 May 2014 19:27:34 +0000 (21:27 +0200)
naja/actions.py
naja/tests/test_actions.py

index 99e16bf9c9de53a5ac8fb26a63e79ed328aed75b..ff8a431d0369fe0fa6f1ed1a52cbda87126fd538 100644 (file)
@@ -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'])
index 3497ee49c6a47d7971e5e67f3b1ca03ebbf1be42..5cf4c76011958267a324087a7a5eae9706fe6b19 100644 (file)
@@ -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]))