From 2a2d9d3456a6b15de18aa54de3db624514684478 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 12 Nov 2019 14:59:43 +0300 Subject: [PATCH] Fix circular import issues for tests --- config.py | 1 + gui/bitmap_loader.py | 13 +++++++++---- service/jargon/loader.py | 14 ++++++++------ service/port/efs.py | 3 ++- tests/test_modules/test_service/test_fit.py | 3 ++- tests/test_unread_desc.py | 8 +++----- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/config.py b/config.py index b515ae909a..2991c3c070 100644 --- a/config.py +++ b/config.py @@ -40,6 +40,7 @@ cipher = None clientHash = None experimentalFeatures = None +version = None ESI_CACHE = 'esi_cache' diff --git a/gui/bitmap_loader.py b/gui/bitmap_loader.py index f6257ecbaa..928dfb15e1 100644 --- a/gui/bitmap_loader.py +++ b/gui/bitmap_loader.py @@ -33,12 +33,17 @@ class BitmapLoader: - try: - archive = zipfile.ZipFile(config.imgsZIP, 'r') - pyfalog.info("Using zipped image files.") - except (IOError, TypeError): + # Can be None if we're running from tests + if config.imgsZIP is None: pyfalog.info("Using local image files.") archive = None + else: + try: + archive = zipfile.ZipFile(config.imgsZIP, 'r') + pyfalog.info("Using zipped image files.") + except (IOError, TypeError): + pyfalog.info("Using local image files.") + archive = None cached_bitmaps = OrderedDict() dont_use_cached_bitmaps = False diff --git a/service/jargon/loader.py b/service/jargon/loader.py index 5374a59140..9e75443adc 100644 --- a/service/jargon/loader.py +++ b/service/jargon/loader.py @@ -24,7 +24,7 @@ from .jargon import Jargon from .resources import DEFAULT_DATA, DEFAULT_HEADER -JARGON_PATH = os.path.join(config.savePath, 'jargon.yaml') +JARGON_PATH = os.path.join(config.savePath, 'jargon.yaml') if config.savePath is not None else None class JargonLoader: @@ -44,14 +44,15 @@ def _is_stale(self): def _load_jargon(self): jargondata = yaml.load(DEFAULT_DATA, Loader=yaml.SafeLoader) - with open(JARGON_PATH) as f: - userdata = yaml.load(f, Loader=yaml.SafeLoader) - jargondata.update(userdata) + if JARGON_PATH is not None: + with open(JARGON_PATH) as f: + userdata = yaml.load(f, Loader=yaml.SafeLoader) + jargondata.update(userdata) self.jargon_mtime = self._get_jargon_file_mtime() self._jargon = Jargon(jargondata) def _get_jargon_file_mtime(self) -> int: - if not os.path.exists(self.jargon_path): + if self.jargon_path is None or not os.path.exists(self.jargon_path): return 0 return os.stat(self.jargon_path).st_mtime @@ -82,4 +83,5 @@ def instance(jargon_path=None): return JargonLoader._instance -JargonLoader.init_user_jargon(JARGON_PATH) +if JARGON_PATH is not None: + JargonLoader.init_user_jargon(JARGON_PATH) diff --git a/service/port/efs.py b/service/port/efs.py index 47975a6298..9ed5ef8feb 100755 --- a/service/port/efs.py +++ b/service/port/efs.py @@ -5,7 +5,7 @@ from logbook import Logger import eos.db -from config import version as pyfaVersion +from config import getVersion from service.fit import Fit from service.market import Market from eos.const import FittingModuleState, FittingHardpoint, FittingSlot @@ -23,6 +23,7 @@ pyfalog = Logger(__name__) +pyfaVersion = getVersion() class EfsPort: diff --git a/tests/test_modules/test_service/test_fit.py b/tests/test_modules/test_service/test_fit.py index 18f5a9e52e..7f000e0bd6 100644 --- a/tests/test_modules/test_service/test_fit.py +++ b/tests/test_modules/test_service/test_fit.py @@ -5,7 +5,8 @@ script_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.realpath(os.path.join(script_dir, '..', '..', '..'))) -# noinspection PyPackageRequirements +# This import is here to hack around circular import issues +import gui.mainFrame # noinspection PyPackageRequirements from service.fit import Fit diff --git a/tests/test_unread_desc.py b/tests/test_unread_desc.py index 824475d4fa..beb08001a5 100644 --- a/tests/test_unread_desc.py +++ b/tests/test_unread_desc.py @@ -9,17 +9,15 @@ import sys # nopep8 import re -# from utils.strfunctions import sequential_rep, replace_ltgt -#from utils.stopwatch import Stopwatch script_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.realpath(os.path.join(script_dir, '..'))) sys._called_from_test = True # need db open for tests. (see eos/config.py#17 + +# This import is here to hack around circular import issues +import gui.mainFrame # noinspection PyPep8 from service.port import Port, IPortUser -# -# noinspection PyPackageRequirements -# from _development.helpers import DBInMemory as DB """ NOTE: