|
3 | 3 | from numbers import Number as Num
|
4 | 4 | from unittest import TestCase
|
5 | 5 |
|
6 |
| -from plotly.files import CREDENTIALS_FILE, CONFIG_FILE, check_file_permissions |
7 |
| -from plotly import session |
| 6 | +from plotly import files, session, utils |
8 | 7 |
|
9 | 8 |
|
10 | 9 | class PlotlyTestCase(TestCase):
|
11 | 10 |
|
12 | 11 | # parent test case to assist with clean up of local credentials/config
|
13 | 12 |
|
14 | 13 | 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 |
17 | 17 | self._session = None
|
18 | 18 | super(PlotlyTestCase, self).__init__(*args, **kwargs)
|
19 | 19 |
|
20 | 20 | def setUp(self):
|
21 |
| - self.stash_file_credentials_and_config() |
| 21 | + self.stash_session() |
| 22 | + self.stash_files() |
22 | 23 |
|
23 | 24 | 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) |
41 | 44 |
|
42 | 45 | def stash_session(self):
|
43 | 46 | self._session = copy.deepcopy(session._session)
|
|
0 commit comments