Skip to content

Commit cb8a637

Browse files
committed
Add more tests and fix bad log call
1 parent bf0b851 commit cb8a637

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/manage/install_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def _merge_existing_index(versions, index_json):
543543
pass
544544
except (json.JSONDecodeError, KeyError, ValueError):
545545
LOGGER.warn("Existing index file appeared invalid and was overwritten.")
546-
LOGGER.debug(exc_info=True)
546+
LOGGER.debug("TRACEBACK", exc_info=True)
547547
else:
548548
LOGGER.debug("Merging into existing %s", index_json)
549549
current = {i["url"].casefold() for i in versions}

tests/test_install_command.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,29 @@ def test_merge_existing_index(tmp_path):
163163
{"id": "test-1", "url": "test-file-1.zip"},
164164
{"id": "test-3", "url": "test-file-3.zip"},
165165
]
166+
167+
168+
def test_merge_existing_index_not_found(tmp_path):
169+
existing = tmp_path / "index.json"
170+
try:
171+
existing.unlink()
172+
except FileNotFoundError:
173+
pass
174+
175+
# Expect no failure and no change
176+
new = [1, 2, 3]
177+
IC._merge_existing_index(new, existing)
178+
assert new == [1, 2, 3]
179+
180+
181+
def test_merge_existing_index_not_valid(tmp_path):
182+
existing = tmp_path / "index.json"
183+
with open(existing, "w", encoding="utf-8") as f:
184+
print("It's not a list of installs", file=f)
185+
print("But more importantly,", file=f)
186+
print("it's not valid JSON!", file=f)
187+
188+
# Expect no failure and no change
189+
new = [1, 2, 3]
190+
IC._merge_existing_index(new, existing)
191+
assert new == [1, 2, 3]

0 commit comments

Comments
 (0)