Skip to content

Commit

Permalink
Fix circular import issues for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFenX committed Nov 12, 2019
1 parent a91efb6 commit 2a2d9d3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
cipher = None
clientHash = None
experimentalFeatures = None
version = None

ESI_CACHE = 'esi_cache'

Expand Down
13 changes: 9 additions & 4 deletions gui/bitmap_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions service/jargon/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion service/port/efs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,6 +23,7 @@


pyfalog = Logger(__name__)
pyfaVersion = getVersion()


class EfsPort:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_modules/test_service/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions tests/test_unread_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2a2d9d3

Please sign in to comment.