Recover from occupied bed race
This commit is contained in:
@@ -366,6 +366,42 @@ class TestSleepWithBed(unittest.TestCase):
|
||||
self.assertEqual(state.state, state.use_bed)
|
||||
self.assertTrue(state.waiting_for_night)
|
||||
|
||||
def test_sleep_attempt_aborts_if_night_was_skipped_while_approaching(self):
|
||||
bed_id = next(iter(blocks.BED_IDS))
|
||||
world = FakeWorld(block=bed_id)
|
||||
state = SleepWithBedStates(Munch(
|
||||
time=13000, dimension='overworld', world=world,
|
||||
game=FakeGame(), path=[], look_at=None))
|
||||
state.init()
|
||||
state.area = (0, 64, 0)
|
||||
state.state = state.use_bed
|
||||
state.g.time = 25
|
||||
|
||||
state.use_bed()
|
||||
|
||||
self.assertEqual(state.state, state.cleanup)
|
||||
|
||||
def test_occupied_bed_is_abandoned_before_waiting_for_night(self):
|
||||
bed_id = next(iter(blocks.BED_IDS))
|
||||
|
||||
class OccupiedWorld(FakeWorld):
|
||||
@staticmethod
|
||||
def check_bed_occupied(_position):
|
||||
return True
|
||||
|
||||
state = SleepWithBedStates(Munch(
|
||||
time=13000, dimension='overworld',
|
||||
world=OccupiedWorld(block=bed_id), game=FakeGame(),
|
||||
path=[], look_at=None))
|
||||
state.init()
|
||||
state.area = (0, 64, 0)
|
||||
state.beds = [(2, 64, 0)]
|
||||
state.state = state.use_bed
|
||||
|
||||
state.use_bed()
|
||||
|
||||
self.assertEqual(state.state, state.choose_bed)
|
||||
|
||||
def test_daytime_sleep_aborts_cleanly(self):
|
||||
state = SleepWithBedStates(Munch(time=1000, dimension='overworld'))
|
||||
state.init()
|
||||
|
||||
Reference in New Issue
Block a user