Skip to content

Commit

Permalink
PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclary committed Feb 29, 2024
1 parent 73a455d commit 37e15d2
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions spyder_kernels/console/tests/test_console_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ def setup_kernel(cmd):
)
# wait for connection file to exist, timeout after 5s
tic = time.time()
while not os.path.exists(connection_file) \
and kernel.poll() is None \
and time.time() < tic + SETUP_TIMEOUT:
while (
not os.path.exists(connection_file)
and kernel.poll() is None
and time.time() < tic + SETUP_TIMEOUT
):
time.sleep(0.1)

if kernel.poll() is not None:
o,e = kernel.communicate()
o, e = kernel.communicate()
raise IOError("Kernel failed to start:\n%s" % e)

if not os.path.exists(connection_file):
Expand Down Expand Up @@ -227,7 +229,7 @@ def kernel(request):
'True_'
],
'minmax': False,
'filter_on':True
'filter_on': True
}

# Teardown
Expand Down Expand Up @@ -277,7 +279,7 @@ def test_get_namespace_view(kernel):
"""
Test the namespace view of the kernel.
"""
execute = asyncio.run(kernel.do_execute('a = 1', True))
asyncio.run(kernel.do_execute('a = 1', True))

nsview = repr(kernel.get_namespace_view())
assert "'a':" in nsview
Expand All @@ -293,7 +295,7 @@ 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('a = 1', True))
asyncio.run(kernel.do_execute('TestFilterOff = 1', True))

settings = kernel.namespace_view_settings
Expand Down Expand Up @@ -469,6 +471,7 @@ def test_get_doc(kernel):
assert ("Define the builtin 'help'" in kernel.get_doc(objtxt)['docstring'] or
"Define the built-in 'help'" in kernel.get_doc(objtxt)['docstring'])


def test_get_source(kernel):
"""Test to get object source."""
objtxt = 'help'
Expand Down Expand Up @@ -505,7 +508,7 @@ def test_cwd_in_sys_path():
with setup_kernel(cmd) as client:
reply = client.execute_interactive(
"import sys; sys_path = sys.path",
user_expressions={'output':'sys_path'}, timeout=TIMEOUT)
user_expressions={'output': 'sys_path'}, timeout=TIMEOUT)

# Transform value obtained through user_expressions
user_expressions = reply['content']['user_expressions']
Expand Down Expand Up @@ -714,8 +717,10 @@ def test_runfile(tmpdir):
assert content['found']

# Run code file `u` with current namespace
msg = client.execute_interactive("%runfile {} --current-namespace"
.format(repr(str(u))), timeout=TIMEOUT)
msg = client.execute_interactive(
"%runfile {} --current-namespace".format(repr(str(u))),
timeout=TIMEOUT
)
content = msg['content']

# Verify that the variable `result3` is defined
Expand Down Expand Up @@ -965,11 +970,12 @@ def test_comprehensions_with_locals_in_pdb(kernel):

# Check that the variable is not reported as being part of globals.
kernel.shell.pdb_session.default("in_globals = 'zz' in globals()")
assert kernel.get_value('in_globals') == False
assert kernel.get_value('in_globals') is False

pdb_obj.curframe = None
pdb_obj.curframe_locals = None


def test_comprehensions_with_locals_in_pdb_2(kernel):
"""
Test that evaluating comprehensions with locals works in Pdb.
Expand Down Expand Up @@ -1000,7 +1006,7 @@ def test_namespaces_in_pdb(kernel):
Test namespaces in pdb
"""
# Define get_ipython for timeit
get_ipython = lambda: kernel.shell
get_ipython = lambda: kernel.shell # noqa
kernel.shell.user_ns["test"] = 0
pdb_obj = SpyderPdb()
pdb_obj.curframe = inspect.currentframe()
Expand All @@ -1014,6 +1020,7 @@ def test_namespaces_in_pdb(kernel):
# Create wrapper to check for errors
old_error = pdb_obj.error
pdb_obj._error_occured = False

def error_wrapper(*args, **kwargs):
print(args, kwargs)
pdb_obj._error_occured = True
Expand Down Expand Up @@ -1065,7 +1072,6 @@ def test_functions_with_locals_in_pdb(kernel):
'zz = fun_a()')
assert kernel.get_value('zz') == 1


pdb_obj.curframe = None
pdb_obj.curframe_locals = None

Expand All @@ -1076,7 +1082,7 @@ def test_functions_with_locals_in_pdb_2(kernel):
This is another regression test for spyder-ide/spyder-kernels#345
"""
baba = 1
baba = 1 # noqa
pdb_obj = SpyderPdb()
pdb_obj.curframe = inspect.currentframe()
pdb_obj.curframe_locals = pdb_obj.curframe.f_locals
Expand Down Expand Up @@ -1113,7 +1119,7 @@ def test_locals_globals_in_pdb(kernel):
"""
Test thal locals and globals work properly in Pdb.
"""
a = 1
a = 1 # noqa
pdb_obj = SpyderPdb()
pdb_obj.curframe = inspect.currentframe()
pdb_obj.curframe_locals = pdb_obj.curframe.f_locals
Expand All @@ -1123,11 +1129,11 @@ def test_locals_globals_in_pdb(kernel):

kernel.shell.pdb_session.default(
'test = "a" in globals()')
assert kernel.get_value('test') == False
assert kernel.get_value('test') is False

kernel.shell.pdb_session.default(
'test = "a" in locals()')
assert kernel.get_value('test') == True
assert kernel.get_value('test') is True

kernel.shell.pdb_session.default(
'def f(): return a')
Expand All @@ -1141,11 +1147,11 @@ def test_locals_globals_in_pdb(kernel):

kernel.shell.pdb_session.default(
'test = "a" in globals()')
assert kernel.get_value('test') == False
assert kernel.get_value('test') is False

kernel.shell.pdb_session.default(
'test = "a" in locals()')
assert kernel.get_value('test') == True
assert kernel.get_value('test') is True

pdb_obj.curframe = None
pdb_obj.curframe_locals = None
Expand Down Expand Up @@ -1220,7 +1226,7 @@ def test_global_message(tmpdir):

def check_found(msg):
if "text" in msg["content"]:
if ("WARNING: This file contains a global statement" in
if ("WARNING: This file contains a global statement" in
msg["content"]["text"]):
global found
found = True
Expand Down Expand Up @@ -1252,7 +1258,7 @@ def test_debug_namespace(tmpdir):
d.write('def func():\n bb = "hello"\n breakpoint()\nfunc()')

# Run code file `d`
msg_id = client.execute("%runfile {}".format(repr(str(d))))
client.execute("%runfile {}".format(repr(str(d))))

# make sure that 'bb' returns 'hello'
client.get_stdin_msg(timeout=TIMEOUT)
Expand All @@ -1266,7 +1272,7 @@ def test_debug_namespace(tmpdir):
if 'hello' in msg["content"].get("text"):
break

# make sure that get_value('bb') returns 'hello'
# make sure that get_value('bb') returns 'hello'
client.get_stdin_msg(timeout=TIMEOUT)
client.input("get_ipython().kernel.get_value('bb')")

Expand Down Expand Up @@ -1385,7 +1391,7 @@ def test_non_strings_in_locals(kernel):
This is a regression test for issue spyder-ide/spyder#19145
"""
execute = asyncio.run(kernel.do_execute('locals().update({1:2})', True))
asyncio.run(kernel.do_execute('locals().update({1:2})', True))

nsview = repr(kernel.get_namespace_view())
assert "1:" in nsview
Expand All @@ -1397,8 +1403,7 @@ def test_django_settings(kernel):
This is a regression test for issue spyder-ide/spyder#19516
"""
execute = asyncio.run(kernel.do_execute(
'from django.conf import settings', True))
asyncio.run(kernel.do_execute('from django.conf import settings', True))

nsview = repr(kernel.get_namespace_view())
assert "'settings':" in nsview
Expand Down

0 comments on commit 37e15d2

Please sign in to comment.