Improve labeled chest caching interactions
This commit is contained in:
@@ -27,8 +27,8 @@ class ChestDetectionTests(unittest.TestCase):
|
||||
self.manager = ChestOpenManager(self.g)
|
||||
self.position = (12, 64, -7)
|
||||
|
||||
def event(self, block_id=2, action=1, viewers=1):
|
||||
x, y, z = self.position
|
||||
def event(self, block_id=2, action=1, viewers=1, position=None):
|
||||
x, y, z = position or self.position
|
||||
return Munch(
|
||||
location=Munch(x=x, y=y, z=z),
|
||||
block_id=block_id, action=action, parameter=viewers,
|
||||
@@ -54,12 +54,27 @@ class ChestDetectionTests(unittest.TestCase):
|
||||
self.manager.handle_block_event(self.event(viewers=1))
|
||||
|
||||
self.assertIsNone(self.g.last_chest_opened_by_other)
|
||||
self.assertIsNone(self.g.pending_chest_open)
|
||||
self.assertIsNotNone(self.g.pending_chest_open)
|
||||
|
||||
self.manager.handle_block_event(self.event(viewers=2))
|
||||
self.assertEqual(self.g.last_chest_opened_by_other['viewers'], 2)
|
||||
self.assertEqual(self.g.last_chest_opened_by_other['previous_viewers'], 1)
|
||||
|
||||
def test_bot_open_of_either_double_chest_half_is_not_misreported(self):
|
||||
other_half = (13, 64, -7)
|
||||
self.g.pending_chest_open = {
|
||||
'position': self.position,
|
||||
'positions': (self.position, other_half),
|
||||
'requested_at': time.monotonic(),
|
||||
}
|
||||
|
||||
self.manager.handle_block_event(
|
||||
self.event(position=other_half, viewers=1))
|
||||
|
||||
self.assertIsNone(self.g.last_chest_opened_by_other)
|
||||
self.assertIsNotNone(self.g.pending_chest_open)
|
||||
self.assertEqual(self.g.chest_viewers[other_half], 1)
|
||||
|
||||
def test_ignores_non_chests_and_tracks_close(self):
|
||||
self.manager.handle_block_event(self.event(block_id=1, viewers=1))
|
||||
self.assertIsNone(self.g.last_chest_opened_by_other)
|
||||
@@ -71,11 +86,13 @@ class ChestDetectionTests(unittest.TestCase):
|
||||
self.assertEqual(len(self.g.chest_open_events), 1)
|
||||
|
||||
def test_open_container_marks_bot_initiated_chest_open(self):
|
||||
chest_state = 5552
|
||||
sent = []
|
||||
game = Game.__new__(Game)
|
||||
game.g = Munch(chunks=Munch(
|
||||
get_block_at=lambda *_position: chest_state))
|
||||
other_half = (12, 64, -8)
|
||||
game.g = Munch(
|
||||
chunks=Munch(get_block_at=lambda *_position: None),
|
||||
world=Munch(_double_chest_positions=lambda _position:
|
||||
(self.position,)))
|
||||
game.place_block = lambda location, face: sent.append(
|
||||
(location, face))
|
||||
|
||||
@@ -83,6 +100,8 @@ class ChestDetectionTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(sent[0][0], self.position)
|
||||
self.assertEqual(game.g.pending_chest_open['position'], self.position)
|
||||
self.assertIn(self.position, game.g.pending_chest_open['positions'])
|
||||
self.assertIn(other_half, game.g.pending_chest_open['positions'])
|
||||
self.assertIsInstance(game.g.pending_chest_open['requested_at'], float)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user