Skip to content

Commit b4a709b

Browse files
committed
Fix unit tests, handle missing git version details when running make
1 parent b64e63f commit b4a709b

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

docker/helpers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,22 @@ def get_git_info(tag_only: bool=False) -> str:
181181
git_info : str
182182
"""
183183
logger = logging.getLogger('pgosm-flex')
184-
repo = git.Repo()
184+
185+
try:
186+
repo = git.Repo()
187+
except git.exc.InvalidGitRepositoryError:
188+
# This error happens when running via make for some reason...
189+
# This appears to fix it.
190+
repo = git.Repo('../')
191+
185192
try:
186193
sha = repo.head.object.hexsha
187194
short_sha = repo.git.rev_parse(sha, short=True)
188195
latest_tag = repo.git.describe('--abbrev=0', tags=True)
189196
except ValueError:
190197
git_info = 'Git info unavailable'
191198
logger.error('Unable to get git information.')
199+
return '-- (version unknown) --'
192200

193201
if tag_only:
194202
git_info = latest_tag

docker/import_mode.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ def okay_to_run(self, prior_import: dict) -> bool:
9090
# If current version is lower than prior version from latest import, stop.
9191
prior_import_version = prior_import['pgosm_flex_version_no_hash']
9292
git_tag = helpers.get_git_info(tag_only=True)
93-
if parse_version(git_tag) < parse_version(prior_import_version):
93+
94+
if git_tag == '-- (version unknown) --':
95+
msg = 'Unable to detect PgOSM Flex version from Git.'
96+
msg += ' Not enforcing version check against prior version.'
97+
self.logger.warning(msg)
98+
elif parse_version(git_tag) < parse_version(prior_import_version):
9499
msg = f'PgOSM Flex version ({git_tag}) is lower than latest import'
95100
msg += f' tracked in the pgosm_flex table ({prior_import_version}).'
96101
msg += f' Use PgOSM Flex version {prior_import_version} or newer'

docker/tests/test_import_mode.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ def test_import_mode_okay_to_run_returns_false_when_prior_record_not_replication
146146
This should return False to avoid overwriting data.
147147
"""
148148
replication = True
149-
prior_import = {'replication': False}
149+
prior_import = {'replication': False,
150+
'pgosm_flex_version_no_hash': '99.99.99'
151+
}
150152
replication_update = False
151153
update = None
152154
force = False
@@ -170,7 +172,9 @@ def test_import_mode_okay_to_run_returns_true_when_replication_prior_record_repl
170172
This should return True to allow replication to updated
171173
"""
172174
replication = True
173-
prior_import = {'replication': True}
175+
prior_import = {'replication': True,
176+
'pgosm_flex_version_no_hash': '99.99.99'
177+
}
174178
replication_update = False
175179
update = None
176180
force = False
@@ -193,7 +197,9 @@ def test_import_mode_okay_to_run_returns_false_when_prior_import(self):
193197
This should return False to protect the data.
194198
"""
195199
replication = False
196-
prior_import = {'replication': False}
200+
prior_import = {'replication': False,
201+
'pgosm_flex_version_no_hash': '99.99.99'
202+
}
197203
replication_update = False
198204
update = None
199205
force = False

0 commit comments

Comments
 (0)