Skip to content

Commit ebccd14

Browse files
committed
Fix PlotlyTestCase to handle the plot schema.
1 parent 09f8a5e commit ebccd14

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

plotly/tests/utils.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,44 @@
33
from numbers import Number as Num
44
from unittest import TestCase
55

6-
from plotly.files import CREDENTIALS_FILE, CONFIG_FILE, check_file_permissions
7-
from plotly import session
6+
from plotly import files, session, utils
87

98

109
class PlotlyTestCase(TestCase):
1110

1211
# parent test case to assist with clean up of local credentials/config
1312

1413
def __init__(self, *args, **kwargs):
15-
self._file_credentials = None
16-
self._file_config = None
14+
self._credentials = None
15+
self._config = None
16+
self._graph_reference = None
1717
self._session = None
1818
super(PlotlyTestCase, self).__init__(*args, **kwargs)
1919

2020
def setUp(self):
21-
self.stash_file_credentials_and_config()
21+
self.stash_session()
22+
self.stash_files()
2223

2324
def tearDown(self):
24-
self.restore_file_credentials_and_config()
25-
26-
def stash_file_credentials_and_config(self):
27-
if check_file_permissions():
28-
with open(CREDENTIALS_FILE, 'r') as f:
29-
self._file_credentials = json.load(f)
30-
with open(CONFIG_FILE, 'r') as f:
31-
self._file_config = json.load(f)
32-
33-
def restore_file_credentials_and_config(self):
34-
if check_file_permissions():
35-
if self._file_credentials is not None:
36-
with open(CREDENTIALS_FILE, 'w') as f:
37-
json.dump(self._file_credentials, f)
38-
if self._file_config is not None:
39-
with open(CONFIG_FILE, 'w') as f:
40-
json.dump(self._file_config, f)
25+
self.restore_files()
26+
self.restore_session()
27+
28+
def stash_files(self):
29+
if files.check_file_permissions():
30+
self._credentials = utils.load_json_dict(files.CREDENTIALS_FILE)
31+
self._config = utils.load_json_dict(files.CONFIG_FILE)
32+
self._graph_reference = \
33+
utils.load_json_dict(files.GRAPH_REFERENCE_FILE)
34+
35+
def restore_files(self):
36+
if files.check_file_permissions():
37+
if self._credentials is not None:
38+
utils.save_json_dict(files.CREDENTIALS_FILE, self._credentials)
39+
if self._config is not None:
40+
utils.save_json_dict(files.CONFIG_FILE, self._config)
41+
if self._graph_reference is not None:
42+
utils.save_json_dict(files.GRAPH_REFERENCE_FILE,
43+
self._graph_reference)
4144

4245
def stash_session(self):
4346
self._session = copy.deepcopy(session._session)

0 commit comments

Comments
 (0)