From a9371b9c48e1fbbac93ab41cec82f52bb1caa292 Mon Sep 17 00:00:00 2001
From: Tim Storer <timothy.storer@glasgow.ac.uk>
Date: Tue, 8 Mar 2022 21:30:04 +0000
Subject: [PATCH] Makes waiting_for_tick private for better encapsulation

---
 tests/test_clock.py |  3 +--
 theatre_ag/actor.py | 13 ++++++++-----
 theatre_ag/clock.py |  2 +-
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/tests/test_clock.py b/tests/test_clock.py
index 91850f3..9749eb8 100755
--- a/tests/test_clock.py
+++ b/tests/test_clock.py
@@ -13,13 +13,12 @@ class ClockTestCase(unittest.TestCase):
         self.clock = SynchronizingClock(max_ticks=2)
 
         self.tick_listener = Mock()
-        self.tick_listener.waiting_for_tick = Mock(spec=Event)
 
         self.clock.add_tick_listener(self.tick_listener)
 
         self.clock.tick()
 
-        self.tick_listener.waiting_for_tick.wait.assert_called_once_with()
+        self.tick_listener.wait_for_tick.assert_called_once_with()
         self.tick_listener.notify_new_tick.assert_called_once_with()
 
     def test_ticks_until_stopped(self):
diff --git a/theatre_ag/actor.py b/theatre_ag/actor.py
index e1a7878..b792071 100755
--- a/theatre_ag/actor.py
+++ b/theatre_ag/actor.py
@@ -32,8 +32,8 @@ class Actor(object):
 
         self.tick_received = Event()
         self.tick_received.clear()
-        self.waiting_for_tick = Event()
-        self.waiting_for_tick.clear()
+        self._waiting_for_tick = Event()
+        self._waiting_for_tick.clear()
 
         self.busy = RLock()
         self.wait_for_directions = True
@@ -150,7 +150,7 @@ class Actor(object):
 
         # Ensure that clock can proceed for other listeners.
         self.clock.remove_tick_listener(self)
-        self.waiting_for_tick.set()
+        self._waiting_for_tick.set()
 
     def start(self):
         if not self.thread.is_alive():
@@ -201,14 +201,17 @@ class Actor(object):
 
         while self.clock.current_tick < self.next_turn:
             if self.clock.will_tick_again:
-                self.waiting_for_tick.set()
+                self._waiting_for_tick.set()
                 self.tick_received.wait()
                 self.tick_received.clear()
             else:
                 raise OutOfTurnsException(self)
 
+    def wait_for_tick(self):
+        self._waiting_for_tick.wait()
+
     def notify_new_tick(self):
-        self.waiting_for_tick.clear()
+        self._waiting_for_tick.clear()
         self.tick_received.set()
 
     def __str__(self):
diff --git a/theatre_ag/clock.py b/theatre_ag/clock.py
index 44b046d..7682a67 100755
--- a/theatre_ag/clock.py
+++ b/theatre_ag/clock.py
@@ -64,7 +64,7 @@ class SynchronizingClock(object):
         cached_tick_listeners = self.get_cache_of_tick_listeners()
 
         for tick_listener in cached_tick_listeners:
-            tick_listener.waiting_for_tick.wait()
+            tick_listener.wait_for_tick()
 
         self._ticks += 1
 
-- 
GitLab