def test_set_config_file_all_entries(self): # Check set_config and get_config return the same values domain, streaming_domain, api, sharing = ('this', 'thing', 'that', 'private') ssl_verify, proxy_auth, world_readable, auto_open = (True, True, False, False) tools.set_config_file(plotly_domain=domain, plotly_streaming_domain=streaming_domain, plotly_api_domain=api, plotly_ssl_verification=ssl_verify, plotly_proxy_authorization=proxy_auth, world_readable=world_readable, auto_open=auto_open) config = tools.get_config_file() self.assertEqual(config['plotly_domain'], domain) self.assertEqual(config['plotly_streaming_domain'], streaming_domain) self.assertEqual(config['plotly_api_domain'], api) self.assertEqual(config['plotly_ssl_verification'], ssl_verify) self.assertEqual(config['plotly_proxy_authorization'], proxy_auth) self.assertEqual(config['world_readable'], world_readable) self.assertEqual(config['sharing'], sharing) self.assertEqual(config['auto_open'], auto_open) tools.reset_config_file()
def test_set_config_file(): pd, ps = 'this', 'thing' tls.set_config_file(plotly_domain=pd, plotly_streaming_domain=ps) config = tls.get_config_file() assert config['plotly_domain'] == pd assert config['plotly_streaming_domain'] == ps tls.reset_config_file() # else every would hate me :)
def test_set_config_no_warning_msg_if_plotly_domain_is_https(self): # Check that no UserWarning is being called with https plotly_domain with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") kwargs = {'plotly_domain': 'https://www.foo-bar.com'} tools.set_config_file(**kwargs) assert len(w) == 0
def test_session_plot_option(self): # Check if the session_plot_option and config_plot_optin return the # same value readable = False tools.set_config_file(world_readable=readable) session_plot_option = session.get_session_plot_options() self.assertEqual(session_plot_option['world_readable'], readable) tools.reset_config_file()
def test_get_graph_reference_bad_request_local_copy(self): # if the request fails (mocked by using a bad url here) and a local # copy of the graph reference exists, we can just use that. tools.set_config_file(plotly_api_domain='api.am.not.here.ly') local_graph_reference = {'real': 'local'} self.set_graph_reference(local_graph_reference) graph_reference = gr.get_graph_reference() self.assertEqual(graph_reference, local_graph_reference)
def test_set_config_expected_warning_msg(self): # Check that UserWarning is being called with http plotly_domain with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") kwargs = {'plotly_domain': 'http://www.foo-bar.com'} tools.set_config_file(**kwargs) assert len(w) == 1 assert issubclass(w[-1].category, UserWarning) assert "plotly_domain" in str(w[-1].message)
def test_set_config_updates_plot_options(self): original_config = tls.get_config_file() new_options = { 'world_readable': not original_config['world_readable'], 'auto_open': not original_config['auto_open'], 'sharing': ('public' if original_config['world_readable'] is False else 'secret') } tls.set_config_file(**new_options) options = py._plot_option_logic({}) for key in new_options: self.assertEqual(new_options[key], options[key])
def test_get_graph_reference_bad_request_no_copy(self): # if we don't have a graph reference we load an outdated default tools.set_config_file(plotly_api_domain='api.am.not.here.ly') empty_graph_reference = {} # set it to a false-y value. self.set_graph_reference(empty_graph_reference) path = os.path.join('graph_reference', 'default-schema.json') s = resource_string('plotly', path).decode('utf-8') default_graph_reference = json.loads(s) graph_reference = gr.get_graph_reference() self.assertEqual(graph_reference, default_graph_reference)
def test_set_config_file(): pd, ps = 'this', 'thing' ssl_verify, proxy_auth = True, True tls.set_config_file(plotly_domain=pd, plotly_streaming_domain=ps, plotly_ssl_verification=ssl_verify, plotly_proxy_authorization=proxy_auth) config = tls.get_config_file() assert config['plotly_domain'] == pd assert config['plotly_streaming_domain'] == ps assert config['plotly_ssl_verification'] == ssl_verify assert config['plotly_proxy_authorization'] == proxy_auth tls.reset_config_file() # else every would hate me :)
def test_set_config_file_two_entries(self): # Check set_config and get_config given only two entries return the # same values domain, streaming_domain = 'this', 'thing' tools.set_config_file(plotly_domain=domain, plotly_streaming_domain=streaming_domain) config = tools.get_config_file() self.assertEqual(config['plotly_domain'], domain) self.assertEqual(config['plotly_streaming_domain'], streaming_domain) tools.reset_config_file()
def test_set_config_file_all_entries(self): # Check set_config and get_config return the same values domain, streaming_domain, api = 'this', 'thing', 'that' ssl_verify, proxy_auth, readable = True, True, True tools.set_config_file(plotly_domain=domain, plotly_streaming_domain=streaming_domain, plotly_api_domain=api, plotly_ssl_verification=ssl_verify, plotly_proxy_authorization=proxy_auth, world_readable=readable) config = tools.get_config_file() self.assertEqual(config['plotly_domain'], domain) self.assertEqual(config['plotly_streaming_domain'], streaming_domain) self.assertEqual(config['plotly_api_domain'], api) self.assertEqual(config['plotly_ssl_verification'], ssl_verify) self.assertEqual(config['plotly_proxy_authorization'], proxy_auth) self.assertEqual(config['world_readable'], readable) tools.reset_config_file()
import plotly.plotly as py import plotly.tools as tls import plotly.graph_objs as go import configparser import sys import time import ast import requests import json from datetime import datetime tls.set_credentials_file(username='******', api_key='5m6VBRHj52c314Qy8hTc', stream_ids=['j3mkjkmnp9']) tls.set_config_file(world_readable=False, sharing='private') class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' def organize_traces(tlist): traceArray = []
import plotly.plotly as py import plotly.graph_objs as go from plotly import tools tools.set_credentials_file(username='******', api_key='75DaXDV6HV7GZRxVo8eZ') tools.set_config_file(world_readable=True, sharing='public') # tools.set_config_file(world_readable=False, # sharing='private') # tools.set_config_file(plotly_domain='https://plotly.your-company.com', # plotly_streaming_domain='stream-plotly.your-company.com') trace0 = go.Scatter(x=[1, 2, 3, 4], y=[10, 15, 13, 17]) trace1 = go.Scatter(x=[1, 2, 3, 4], y=[16, 5, 11, 9]) data = go.Data([trace0, trace1]) py.iplot(data)