import unittest from unittest.mock import patch from munch import Munch from mosfet.bot import start_automation class IdleJob: def idle(self): pass def __init__(self): self.state = self.idle class IdlePhysicsTests(unittest.TestCase): def test_movement_worker_ticks_physics_without_active_work(self): connection = Munch(connected=True) job = IdleJob() monitor = Munch(tick=lambda: None, suppress_job=False) game = Munch(_advance_world_time=lambda: None) state = Munch( running=True, connection=connection, pos=(0, 64, 0), game=game, job=job, path=[], breaking=None, threat_monitor=monitor, movement_status='idle', ) ticks = [] def tick_when_idle(global_state): ticks.append(True) global_state.running = False worker = None try: with patch('mosfet.bot.missing_movement_chunks', return_value=[]), \ patch('mosfet.bot.tick', side_effect=tick_when_idle): worker = start_automation(state, initialize=False) worker.join(timeout=2.0) finally: state.running = False if state.get('movement_stop_event'): state.movement_stop_event.set() if worker is not None: worker.join(timeout=1.0) self.assertFalse(worker.is_alive()) self.assertTrue(ticks) if __name__ == '__main__': unittest.main()