Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6f2eb8a

Browse filesBrowse files
author
aneda
committed
Merge pull request plotly#261 from plotly/config-file-safe-tests
Config file safe tests
2 parents 95ee2e4 + 51de393 commit 6f2eb8a
Copy full SHA for 6f2eb8a

File tree

Expand file treeCollapse file tree

2 files changed

+48
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+48
-3
lines changed

‎plotly/tests/test_core/test_tools/test_file_tools.py

Copy file name to clipboardExpand all lines: plotly/tests/test_core/test_tools/test_file_tools.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from unittest import TestCase
2-
31
from plotly import tools
42
from plotly import session
3+
from plotly.tests.utils import PlotlyTestCase
54

65

7-
class FileToolsTest(TestCase):
6+
class FileToolsTest(PlotlyTestCase):
87

98
def test_set_config_file_all_entries(self):
109

‎plotly/tests/utils.py

Copy file name to clipboardExpand all lines: plotly/tests/utils.py
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,50 @@
1+
import copy
2+
import json
13
from numbers import Number as Num
4+
from unittest import TestCase
5+
6+
from plotly import session
7+
from plotly.tools import CREDENTIALS_FILE, CONFIG_FILE, _file_permissions
8+
9+
10+
class PlotlyTestCase(TestCase):
11+
12+
# parent test case to assist with clean up of local credentials/config
13+
14+
def __init__(self, **kwargs):
15+
self._file_credentials = None
16+
self._file_config = None
17+
self._session = None
18+
super(PlotlyTestCase, self).__init__(**kwargs)
19+
20+
def setUp(self):
21+
self.stash_file_credentials_and_config()
22+
23+
def tearDown(self):
24+
self.restore_file_credentials_and_config()
25+
26+
def stash_file_credentials_and_config(self):
27+
if _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 _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.load(self._file_config, f)
41+
42+
def stash_session(self):
43+
self._session = copy.deepcopy(session._session)
44+
45+
def restore_session(self):
46+
session._session.clear() # clear and update to preserve references.
47+
session._session.update(self._session)
248

349

450
def compare_dict(dict1, dict2, equivalent=True, msg='', tol=10e-8):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.