From 5c0ce9ea389f0cc33660c691b286a1778cc4c34f Mon Sep 17 00:00:00 2001 From: beauxq Date: Sun, 3 Sep 2023 00:05:44 -0700 Subject: [PATCH] zillion webhost config fix --- worlds/zillion/__init__.py | 4 ++-- worlds/zillion/config.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/worlds/zillion/__init__.py b/worlds/zillion/__init__.py index 2ea7ffdea5cd..7c927c10eb92 100644 --- a/worlds/zillion/__init__.py +++ b/worlds/zillion/__init__.py @@ -10,6 +10,7 @@ from BaseClasses import ItemClassification, LocationProgressType, \ MultiWorld, Item, CollectionState, Entrance, Tutorial +from .config import detect_test from .logic import cs_to_zz_locs from .region import ZillionLocation, ZillionRegion from .options import ZillionStartChar, zillion_options, validate @@ -145,8 +146,7 @@ def generate_early(self) -> None: self._item_counts = item_counts - import __main__ - rom_dir_name = "" if "test" in __main__.__file__ else os.path.dirname(get_base_rom_path()) + rom_dir_name = "" if detect_test() else os.path.dirname(get_base_rom_path()) with redirect_stdout(self.lsi): # type: ignore self.zz_system.make_patcher(rom_dir_name) self.zz_system.make_randomizer(zz_op) diff --git a/worlds/zillion/config.py b/worlds/zillion/config.py index ca02f9a99f41..db61d0c45347 100644 --- a/worlds/zillion/config.py +++ b/worlds/zillion/config.py @@ -2,3 +2,20 @@ base_id = 8675309 zillion_map = os.path.join(os.path.dirname(__file__), "empty-zillion-map-row-col-labels-281.png") + + +def detect_test() -> bool: + """ + Parts of generation that are in unit tests need the rom. + This is to detect whether we are running unit tests + so we can work around the need for the rom. + """ + import __main__ + try: + if "test" in __main__.__file__: + return True + except AttributeError: + # In some environments, __main__ doesn't have __file__ + # We'll assume that's not unit tests. + pass + return False