|
| 1 | +import json |
1 | 2 | from numbers import Number as Num
|
| 3 | +from unittest import TestCase |
| 4 | + |
| 5 | +from plotly.tools import CREDENTIALS_FILE, CONFIG_FILE, _file_permissions |
| 6 | + |
| 7 | + |
| 8 | +class PlotlyTestCase(TestCase): |
| 9 | + |
| 10 | + # parent test case to assist with clean up of local credentials/config |
| 11 | + |
| 12 | + def __init__(self, **kwargs): |
| 13 | + self._credentials = None |
| 14 | + self._config = None |
| 15 | + super(PlotlyTestCase, self).__init__(**kwargs) |
| 16 | + |
| 17 | + def setUp(self): |
| 18 | + self.stash_credentials_and_config() |
| 19 | + |
| 20 | + def tearDown(self): |
| 21 | + self.restore_credentials_and_config() |
| 22 | + |
| 23 | + def stash_credentials_and_config(self): |
| 24 | + if _file_permissions: |
| 25 | + with open(CREDENTIALS_FILE, 'r') as f: |
| 26 | + self._credentials = json.load(f) |
| 27 | + with open(CONFIG_FILE, 'r') as f: |
| 28 | + self._config = json.load(f) |
| 29 | + |
| 30 | + def restore_credentials_and_config(self): |
| 31 | + if _file_permissions: |
| 32 | + if self._credentials is not None: |
| 33 | + with open(CREDENTIALS_FILE, 'w') as f: |
| 34 | + json.dump(self._credentials, f) |
| 35 | + if self._config is not None: |
| 36 | + with open(CONFIG_FILE, 'w') as f: |
| 37 | + json.load(self._config, f) |
2 | 38 |
|
3 | 39 |
|
4 | 40 | def compare_dict(dict1, dict2, equivalent=True, msg='', tol=10e-8):
|
|
0 commit comments