def test_none_values_are_supported(): """Tests that None values are displayed by default""" supported_types = get_supported_types() mode = 'editable' none_var = None none_list = [2, None, 3, None] none_dict = {'a': None, 'b': 4} none_tuple = (None, [3, None, 4], 'eggs') assert is_supported(none_var, filters=tuple(supported_types[mode])) assert is_supported(none_list, filters=tuple(supported_types[mode])) assert is_supported(none_dict, filters=tuple(supported_types[mode])) assert is_supported(none_tuple, filters=tuple(supported_types[mode]))
def test_dict_display(): """Tests for display of dicts.""" long_list = list(range(100)) long_dict = dict(zip(list(range(100)), list(range(100)))) # Simple dict assert value_to_display({0:0, 'a':'b'}) == "{0:0, 'a':'b'}" # Long dict assert (value_to_display(long_dict) == '{0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, ...}') # Short list of lists assert (value_to_display({1:long_dict, 2:long_dict}) == '{1:{0:0, 1:1, 2:2, 3:3, 4:4, ...}, 2:{0:0, 1:1, 2:2, 3:3, 4:4, ...}}') # Long dict of dicts result = ('{(0, 0, 0, 0, 0, ...):[0, 1, 2, 3, 4, ...], ' '(1, 1, 1, 1, 1, ...):[0, 1, 2, 3, 4, ...]}') assert value_to_display({(0,)*100:long_list, (1,)*100:long_list}) == result[:70] + ' ...' # Multiple level dicts assert (value_to_display({0: {1:1, 2:2, 3:3, 4:{0:0}, 5:5}, 1:1}) == '{0:{1:1, 2:2, 3:3, 4:{...}, 5:5}, 1:1}') assert value_to_display({0:0, 1:1, 2:2, 3:DF}) == '{0:0, 1:1, 2:2, 3:Dataframe}' assert value_to_display({0:0, 1:1, 2:[[DF], PANEL]}) == '{0:0, 1:1, 2:[[...], Panel]}' # Dict of complex object assert value_to_display({0:COMPLEX_OBJECT}) == '{0:defaultdict}' # Dict of composed objects li = {0:COMPLEX_OBJECT, 1:PANEL, 2:2, 3:{0:0, 1:1}, 4:DF} result = '{0:defaultdict, 1:Panel, 2:2, 3:{0:0, 1:1}, 4:Dataframe}' assert value_to_display(li) == result # Dict starting with a non-supported object (#5313) supported_types = tuple(get_supported_types()['editable']) di = {max: len, 1: 1} assert value_to_display(di) in ( '{builtin_function_or_method:builtin_function_or_method, 1:1}', '{1:1, builtin_function_or_method:builtin_function_or_method}') assert is_supported(di, filters=supported_types)
def get_remote_data(data, settings, mode, more_excluded_names=None): """ Return globals according to filter described in *settings*: * data: data to be filtered (dictionary) * settings: variable explorer settings (dictionary) * mode (string): 'editable' or 'picklable' * more_excluded_names: additional excluded names (list) """ supported_types = get_supported_types() assert mode in list(supported_types.keys()) excluded_names = settings['excluded_names'] if more_excluded_names is not None: excluded_names += more_excluded_names return globalsfilter(data, check_all=settings['check_all'], filters=tuple(supported_types[mode]), exclude_private=settings['exclude_private'], exclude_uppercase=settings['exclude_uppercase'], exclude_capitalized=settings['exclude_capitalized'], exclude_unsupported=settings['exclude_unsupported'], excluded_names=excluded_names)
def test_list_display(): """Tests for display of lists.""" long_list = list(range(100)) # Simple list assert value_to_display([1, 2, 3]) == '[1, 2, 3]' # Long list assert ( value_to_display(long_list) == '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...]') # Short list of lists assert (value_to_display( [long_list] * 3 ) == '[[0, 1, 2, 3, 4, ...], [0, 1, 2, 3, 4, ...], [0, 1, 2, 3, 4, ...]]') # Long list of lists result = '[' + ''.join('[0, 1, 2, 3, 4, ...], ' * 10)[:-2] + ']' assert value_to_display([long_list] * 10) == result[:70] + ' ...' # Multiple level lists assert (value_to_display([[1, 2, 3, [4], 5]] + long_list) == '[[1, 2, 3, [...], 5], 0, 1, 2, 3, 4, 5, 6, 7, 8, ...]') assert value_to_display([1, 2, [DF]]) == '[1, 2, [Dataframe]]' assert value_to_display([1, 2, [[DF], PANEL]]) == '[1, 2, [[...], Panel]]' # List of complex object assert value_to_display([COMPLEX_OBJECT]) == '[defaultdict]' # List of composed objects li = [COMPLEX_OBJECT, PANEL, 1, {1: 2, 3: 4}, DF] result = '[defaultdict, Panel, 1, {1:2, 3:4}, Dataframe]' assert value_to_display(li) == result # List starting with a non-supported object (#5313) supported_types = tuple(get_supported_types()['editable']) li = [len, 1] assert value_to_display(li) == '[builtin_function_or_method, 1]' assert is_supported(li, filters=supported_types)
def test_list_display(): """Tests for display of lists.""" long_list = list(range(100)) # Simple list assert value_to_display([1, 2, 3]) == '[1, 2, 3]' # Long list assert (value_to_display(long_list) == '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...]') # Short list of lists assert (value_to_display([long_list] * 3) == '[[0, 1, 2, 3, 4, ...], [0, 1, 2, 3, 4, ...], [0, 1, 2, 3, 4, ...]]') # Long list of lists result = '[' + ''.join('[0, 1, 2, 3, 4, ...], '*10)[:-2] + ']' assert value_to_display([long_list] * 10) == result[:70] + ' ...' # Multiple level lists assert (value_to_display([[1, 2, 3, [4], 5]] + long_list) == '[[1, 2, 3, [...], 5], 0, 1, 2, 3, 4, 5, 6, 7, 8, ...]') assert value_to_display([1, 2, [DF]]) == '[1, 2, [Dataframe]]' assert value_to_display([1, 2, [[DF], PANEL]]) == '[1, 2, [[...], Panel]]' # List of complex object assert value_to_display([COMPLEX_OBJECT]) == '[defaultdict]' # List of composed objects li = [COMPLEX_OBJECT, PANEL, 1, {1:2, 3:4}, DF] result = '[defaultdict, Panel, 1, {1:2, 3:4}, Dataframe]' assert value_to_display(li) == result # List starting with a non-supported object (#5313) supported_types = tuple(get_supported_types()['editable']) li = [len, 1] assert value_to_display(li) == '[builtin_function_or_method, 1]' assert is_supported(li, filters=supported_types)
def savetoMATLAB(savename, data): 'data should be globals()' import sys import scipy.io as sio from spyder.config.base import get_conf_path, get_supported_types from spyder.widgets.variableexplorer import utils as U try: del (mydict) except: pass mydict = U.globalsfilter(data, check_all=True, filters=tuple(get_supported_types()['picklable']), exclude_private=True, exclude_capitalized=False, exclude_uppercase=True, exclude_unsupported=True, excluded_names={'os', 'sys', 'In', 'Out'}) sio.savemat(savename, mydict) return mydict
# Local imports from spyder.config.base import _, get_supported_types from spyder.py3compat import is_text_string, getcwd, to_text_string from spyder.utils import encoding from spyder.utils import icon_manager as ima from spyder.utils.iofuncs import iofunctions from spyder.utils.misc import fix_reference_name from spyder.utils.programs import is_module_installed from spyder.utils.qthelpers import (add_actions, create_action, create_toolbutton) from spyder.widgets.variableexplorer.collectionseditor import ( RemoteCollectionsEditorTableView) from spyder.widgets.variableexplorer.importwizard import ImportWizard from spyder.widgets.variableexplorer.utils import REMOTE_SETTINGS SUPPORTED_TYPES = get_supported_types() class NamespaceBrowser(QWidget): """Namespace browser (global variables explorer widget)""" sig_option_changed = Signal(str, object) sig_collapse = Signal() def __init__(self, parent): QWidget.__init__(self, parent) self.shellwidget = None self.is_visible = True self.setup_in_progress = None # Remote dict editor settings
from spyder.utils.iofuncs import iofunctions from spyder.utils.misc import fix_reference_name from spyder.utils.programs import is_module_installed from spyder.utils.qthelpers import (add_actions, create_action, create_toolbutton) from spyder.widgets.externalshell.monitor import ( communicate, monitor_copy_global, monitor_del_global, monitor_get_global, monitor_load_globals, monitor_save_globals, monitor_set_global, REMOTE_SETTINGS) from spyder.widgets.variableexplorer.collectionseditor import ( CollectionsEditorTableView, RemoteCollectionsEditorTableView) from spyder.widgets.variableexplorer.importwizard import ImportWizard from spyder.widgets.variableexplorer.utils import globalsfilter SUPPORTED_TYPES = get_supported_types() class NamespaceBrowser(QWidget): """Namespace browser (global variables explorer widget)""" sig_option_changed = Signal(str, object) sig_collapse = Signal() def __init__(self, parent): QWidget.__init__(self, parent) self.shellwidget = None self.is_internal_shell = None self.ipyclient = None self.is_ipykernel = None self.is_visible = True