Skip to content

Commit

Permalink
fixed file reads
Browse files Browse the repository at this point in the history
  • Loading branch information
aiordache committed Feb 5, 2020
1 parent 6ce8d73 commit 8770cd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 6 additions & 4 deletions docker/context/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def get_current_context_name():
docker_cfg_path = find_config_file()
if docker_cfg_path:
try:
cfg = open(docker_cfg_path, "r")
name = json.load(cfg).get("currentContext", "default")
with open(docker_cfg_path, "r") as f:
name = json.load(f).get("currentContext", "default")
except Exception:
return "default"
return name
Expand All @@ -29,7 +29,8 @@ def write_context_name_to_docker_config(name=None):
config = {}
if docker_cfg_path:
try:
config = json.load(open(docker_cfg_path, "r"))
with open(docker_cfg_path, "r") as f:
config = json.load(f)
except Exception as e:
return e
current_context = config.get("currentContext", None)
Expand All @@ -40,7 +41,8 @@ def write_context_name_to_docker_config(name=None):
else:
return
try:
json.dump(config, open(docker_cfg_path, "w"), indent=4)
with open(docker_cfg_path, "w") as f:
json.dump(config, f, indent=4)
except Exception as e:
return e

Expand Down
1 change: 0 additions & 1 deletion tests/integration/context_api_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import os
import tempfile
import pytest
Expand Down

0 comments on commit 8770cd0

Please sign in to comment.