80 lines
2.3 KiB
Python
80 lines
2.3 KiB
Python
import unittest
|
|
from munch import Munch
|
|
|
|
from minecraft.networking.types import BlockFace
|
|
|
|
from mosfet.info import items
|
|
from mosfet.jobs.cache_items import CacheItemsStates
|
|
|
|
|
|
class CacheItemsTests(unittest.TestCase):
|
|
def test_successful_labeled_transfer_skips_placing_another_cache_chest(self):
|
|
item_id = items.get_id('stone')
|
|
stack = Munch(present=True, item_id=item_id, item_count=16)
|
|
window = Munch(container_slots=27, contents={
|
|
**dict.fromkeys(range(27)), 27: stack,
|
|
})
|
|
clicks = []
|
|
|
|
class FakeGame:
|
|
@staticmethod
|
|
def count_window_slots():
|
|
return 0
|
|
|
|
@staticmethod
|
|
def click_window(*args):
|
|
clicks.append(args)
|
|
|
|
class FakeWorld:
|
|
@staticmethod
|
|
def find_blocks_indexed(*_args):
|
|
return []
|
|
|
|
@staticmethod
|
|
def find_labeled_chests(*_args):
|
|
return []
|
|
|
|
g = Munch(
|
|
game=FakeGame(), world=FakeWorld(), pos=(0, 64, 0),
|
|
inv={}, window=window, item_lock=False)
|
|
state = CacheItemsStates(g)
|
|
state.is_labeled_container = True
|
|
state.container_item_ids = {item_id}
|
|
|
|
state.move_items()
|
|
self.assertEqual(len(clicks), 1)
|
|
self.assertFalse(state.transferred_to_labeled_chest)
|
|
|
|
window.contents[27] = Munch(present=False, item_id=0, item_count=0)
|
|
g.item_lock = False
|
|
state.pending_transfer['confirm_after'] = 0
|
|
state.move_items()
|
|
self.assertTrue(state.transferred_to_labeled_chest)
|
|
|
|
state.labeled_chests = []
|
|
state.trapped_chests = []
|
|
state.choose_trapped_chest()
|
|
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
|
|
|
def test_cache_chest_placement_sneaks_to_avoid_opening_support_container(self):
|
|
calls = []
|
|
|
|
class FakeGame:
|
|
@staticmethod
|
|
def place_block(*args, **kwargs):
|
|
calls.append((args, kwargs))
|
|
|
|
state = CacheItemsStates(Munch(game=FakeGame()))
|
|
state.area = (3, 65, 7)
|
|
|
|
state.place_chest()
|
|
|
|
self.assertEqual(calls, [(
|
|
((3, 64, 7), BlockFace.TOP), {'sneaking': True},
|
|
)])
|
|
self.assertIs(state.state.__func__, state.open_chest.__func__)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|