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

Config file safe tests #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions 5 plotly/tests/test_core/test_tools/test_file_tools.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from unittest import TestCase

from plotly import tools
from plotly import session
from plotly.tests.utils import PlotlyTestCase


class FileToolsTest(TestCase):
class FileToolsTest(PlotlyTestCase):

def test_set_config_file_all_entries(self):

Expand Down
46 changes: 46 additions & 0 deletions 46 plotly/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
import copy
import json
from numbers import Number as Num
from unittest import TestCase

from plotly import session
from plotly.tools import CREDENTIALS_FILE, CONFIG_FILE, _file_permissions


class PlotlyTestCase(TestCase):

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

def __init__(self, **kwargs):
self._file_credentials = None
self._file_config = None
self._session = None
super(PlotlyTestCase, self).__init__(**kwargs)

def setUp(self):
self.stash_file_credentials_and_config()

def tearDown(self):
self.restore_file_credentials_and_config()

def stash_file_credentials_and_config(self):
if _file_permissions:
with open(CREDENTIALS_FILE, 'r') as f:
self._file_credentials = json.load(f)
with open(CONFIG_FILE, 'r') as f:
self._file_config = json.load(f)

def restore_file_credentials_and_config(self):
if _file_permissions:
if self._file_credentials is not None:
with open(CREDENTIALS_FILE, 'w') as f:
json.dump(self._file_credentials, f)
if self._file_config is not None:
with open(CONFIG_FILE, 'w') as f:
json.load(self._file_config, f)

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

def restore_session(self):
session._session.clear() # clear and update to preserve references.
session._session.update(self._session)


def compare_dict(dict1, dict2, equivalent=True, msg='', tol=10e-8):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.