Skip to content

Commit 2a2d9d3

Browse files
committed
Fix circular import issues for tests
1 parent a91efb6 commit 2a2d9d3

File tree

6 files changed

+25
-17
lines changed

6 files changed

+25
-17
lines changed

config.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
cipher = None
4141
clientHash = None
4242
experimentalFeatures = None
43+
version = None
4344

4445
ESI_CACHE = 'esi_cache'
4546

gui/bitmap_loader.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@
3333

3434

3535
class BitmapLoader:
36-
try:
37-
archive = zipfile.ZipFile(config.imgsZIP, 'r')
38-
pyfalog.info("Using zipped image files.")
39-
except (IOError, TypeError):
36+
# Can be None if we're running from tests
37+
if config.imgsZIP is None:
4038
pyfalog.info("Using local image files.")
4139
archive = None
40+
else:
41+
try:
42+
archive = zipfile.ZipFile(config.imgsZIP, 'r')
43+
pyfalog.info("Using zipped image files.")
44+
except (IOError, TypeError):
45+
pyfalog.info("Using local image files.")
46+
archive = None
4247

4348
cached_bitmaps = OrderedDict()
4449
dont_use_cached_bitmaps = False

service/jargon/loader.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from .jargon import Jargon
2525
from .resources import DEFAULT_DATA, DEFAULT_HEADER
2626

27-
JARGON_PATH = os.path.join(config.savePath, 'jargon.yaml')
27+
JARGON_PATH = os.path.join(config.savePath, 'jargon.yaml') if config.savePath is not None else None
2828

2929

3030
class JargonLoader:
@@ -44,14 +44,15 @@ def _is_stale(self):
4444

4545
def _load_jargon(self):
4646
jargondata = yaml.load(DEFAULT_DATA, Loader=yaml.SafeLoader)
47-
with open(JARGON_PATH) as f:
48-
userdata = yaml.load(f, Loader=yaml.SafeLoader)
49-
jargondata.update(userdata)
47+
if JARGON_PATH is not None:
48+
with open(JARGON_PATH) as f:
49+
userdata = yaml.load(f, Loader=yaml.SafeLoader)
50+
jargondata.update(userdata)
5051
self.jargon_mtime = self._get_jargon_file_mtime()
5152
self._jargon = Jargon(jargondata)
5253

5354
def _get_jargon_file_mtime(self) -> int:
54-
if not os.path.exists(self.jargon_path):
55+
if self.jargon_path is None or not os.path.exists(self.jargon_path):
5556
return 0
5657
return os.stat(self.jargon_path).st_mtime
5758

@@ -82,4 +83,5 @@ def instance(jargon_path=None):
8283
return JargonLoader._instance
8384

8485

85-
JargonLoader.init_user_jargon(JARGON_PATH)
86+
if JARGON_PATH is not None:
87+
JargonLoader.init_user_jargon(JARGON_PATH)

service/port/efs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from logbook import Logger
66

77
import eos.db
8-
from config import version as pyfaVersion
8+
from config import getVersion
99
from service.fit import Fit
1010
from service.market import Market
1111
from eos.const import FittingModuleState, FittingHardpoint, FittingSlot
@@ -23,6 +23,7 @@
2323

2424

2525
pyfalog = Logger(__name__)
26+
pyfaVersion = getVersion()
2627

2728

2829
class EfsPort:

tests/test_modules/test_service/test_fit.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
script_dir = os.path.dirname(os.path.abspath(__file__))
66
sys.path.append(os.path.realpath(os.path.join(script_dir, '..', '..', '..')))
77

8-
# noinspection PyPackageRequirements
8+
# This import is here to hack around circular import issues
9+
import gui.mainFrame
910
# noinspection PyPackageRequirements
1011
from service.fit import Fit
1112

tests/test_unread_desc.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99
import sys
1010
# nopep8
1111
import re
12-
# from utils.strfunctions import sequential_rep, replace_ltgt
13-
#from utils.stopwatch import Stopwatch
1412

1513
script_dir = os.path.dirname(os.path.abspath(__file__))
1614
sys.path.append(os.path.realpath(os.path.join(script_dir, '..')))
1715
sys._called_from_test = True # need db open for tests. (see eos/config.py#17
16+
17+
# This import is here to hack around circular import issues
18+
import gui.mainFrame
1819
# noinspection PyPep8
1920
from service.port import Port, IPortUser
20-
#
21-
# noinspection PyPackageRequirements
22-
# from _development.helpers import DBInMemory as DB
2321

2422
"""
2523
NOTE:

0 commit comments

Comments
 (0)