don't try to load the state file if it does not exist

This commit is contained in:
Richard Jones 2015-01-06 16:11:00 +11:00
parent 28d7dce042
commit 919554ce63
2 changed files with 6 additions and 2 deletions

View File

@ -73,8 +73,11 @@ class GlobalSelfCheckState(object):
# Attempt to write out our version check file
with lockfile.LockFile(self.statefile_path):
with open(self.statefile_path) as statefile:
state = json.load(statefile)
if os.path.exists(self.statefile_path):
with open(self.statefile_path) as statefile:
state = json.load(statefile)
else:
state = {}
state[sys.prefix] = {
"last_check": current_time.strftime(SELFCHECK_DATE_FMT),

View File

@ -131,6 +131,7 @@ def test_global_state(monkeypatch):
monkeypatch.setattr(outdated, "check_path_owner", lambda p: True)
monkeypatch.setattr(lockfile, 'LockFile', fake_lock)
monkeypatch.setattr(os.path, "exists", lambda p: True)
monkeypatch.setattr(outdated, 'running_under_virtualenv',
pretend.call_recorder(lambda: False))