Skip to content
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

PR: Add a global filter flag to settings #460

Merged
merged 8 commits into from
Jul 12, 2023
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
28 changes: 27 additions & 1 deletion spyder_kernels/console/tests/test_console_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ def kernel(request):
'False_',
'True_'
],
'minmax': False
'minmax': False,
'filter_on':True
}

# Teardown
Expand Down Expand Up @@ -288,6 +289,31 @@ def test_get_namespace_view(kernel):
assert "'python_type': 'int'" in nsview


@pytest.mark.parametrize("filter_on", [True, False])
def test_get_namespace_view_filter_on(kernel, filter_on):
"""
Test the namespace view of the kernel with filters on and off.
"""
execute = asyncio.run(kernel.do_execute('a = 1', True))
asyncio.run(kernel.do_execute('TestFilterOff = 1', True))
dalthviz marked this conversation as resolved.
Show resolved Hide resolved

settings = kernel.namespace_view_settings
settings['filter_on'] = filter_on
settings['exclude_capitalized'] = True
nsview = kernel.get_namespace_view()

if not filter_on:
assert 'a' in nsview
assert 'TestFilterOff' in nsview
else:
assert 'TestFilterOff' not in nsview
assert 'a' in nsview

# Restore settings for other tests
settings['filter_on'] = True
settings['exclude_capitalized'] = False


def test_get_var_properties(kernel):
"""
Test the properties fo the variables in the namespace.
Expand Down
10 changes: 6 additions & 4 deletions spyder_kernels/utils/nsview.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ def is_callable_or_module(value):
def globalsfilter(input_dict, check_all=False, filters=None,
exclude_private=None, exclude_capitalized=None,
exclude_uppercase=None, exclude_unsupported=None,
excluded_names=None, exclude_callables_and_modules=None):
excluded_names=None, exclude_callables_and_modules=None,
filter_on=True):
"""Keep objects in namespace view according to different criteria."""
output_dict = {}
def _is_string(obj):
Expand All @@ -605,7 +606,7 @@ def _is_string(obj):
(exclude_callables_and_modules and is_callable_or_module(value)) or
(exclude_unsupported and
not is_supported(value, check_all=check_all, filters=filters))
)
) and filter_on
if not excluded:
output_dict[key] = value
return output_dict
Expand All @@ -617,7 +618,8 @@ def _is_string(obj):
REMOTE_SETTINGS = ('check_all', 'exclude_private', 'exclude_uppercase',
'exclude_capitalized', 'exclude_unsupported',
'excluded_names', 'minmax', 'show_callable_attributes',
'show_special_attributes', 'exclude_callables_and_modules')
'show_special_attributes', 'exclude_callables_and_modules',
'filter_on')


def get_supported_types():
Expand Down Expand Up @@ -673,7 +675,7 @@ def get_remote_data(data, settings, mode, more_excluded_names=None):
exclude_capitalized=settings['exclude_capitalized'],
exclude_unsupported=settings['exclude_unsupported'],
exclude_callables_and_modules=settings['exclude_callables_and_modules'],
excluded_names=excluded_names)
excluded_names=excluded_names, filter_on=settings['filter_on'])


def make_remote_view(data, settings, more_excluded_names=None):
Expand Down
Loading