Skip to content

Commit 0d7d1dd

Browse files
author
aneda
committed
Merge pull request plotly#272 from plotly/add-defaults-check
check differences between config defaults and user config
2 parents e2f2329 + db5fba7 commit 0d7d1dd

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import absolute_import
2+
3+
from unittest import TestCase
4+
5+
from plotly.tools import get_config_defaults, _FILE_CONTENT, CONFIG_FILE
6+
7+
8+
class TestGetConfigDefaults(TestCase):
9+
10+
def test_config_dict_is_equivalent_copy(self):
11+
12+
original = _FILE_CONTENT[CONFIG_FILE]
13+
copy = get_config_defaults()
14+
self.assertIsNot(copy, original)
15+
self.assertEqual(copy, original)

plotly/tools.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def warning_on_one_line(message, category, filename, lineno,
6262
'api_key': '',
6363
'proxy_username': '',
6464
'proxy_password': '',
65-
'api_key': '',
6665
'stream_ids': []},
6766
CONFIG_FILE: {'plotly_domain': 'https://plot.ly',
6867
'plotly_streaming_domain': 'stream.plot.ly',
@@ -86,6 +85,19 @@ def warning_on_one_line(message, category, filename, lineno,
8685
_file_permissions = False
8786

8887

88+
def get_config_defaults():
89+
"""
90+
Convenience function to check current settings against defaults.
91+
92+
Example:
93+
94+
if plotly_domain != get_config_defaults()['plotly_domain']:
95+
# do something
96+
97+
"""
98+
return dict(_FILE_CONTENT[CONFIG_FILE]) # performs a shallow copy
99+
100+
89101
def check_file_permissions():
90102
return _file_permissions
91103

0 commit comments

Comments
 (0)