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 test with non-ascii directory for consoles stderr file #5013

Merged
merged 7 commits into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 5 additions & 4 deletions spyder/plugins/ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,9 @@ def __init__(self, parent, testing=False):

# Create temp dir on testing to save kernel errors
if self.testing:
if not osp.isdir(programs.TEMPDIR):
os.mkdir(programs.TEMPDIR)
if not osp.isdir(osp.join(programs.TEMPDIR, u'測試', u'اختبار')):
os.makedirs(osp.join(programs.TEMPDIR, u'測試', u'اختبار'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dalthviz, I don't like this test directory to be part of our sourcecode.

Please add a new parameter to __init__ called test_dir=TEMPDIR. With that this should look like:

if self.testing:
    if not osp.isdir(test_dir):
        os.makedirs(test_dir)

Then in our tests you can change that parameter by this directory containing Chinese and Arabic characters.



layout = QVBoxLayout()
self.tabwidget = Tabs(self, self.menu_actions, rename_tabs=True,
Expand Down Expand Up @@ -932,7 +933,7 @@ def write_to_stdin(self, line):
@Slot(bool)
@Slot(str)
@Slot(bool, str)
def create_new_client(self, give_focus=True, filename=''):
def create_new_client(self, give_focus=True, filename='', testing=False):
"""Create a new client"""
self.master_clients += 1
client_id = dict(int_id=to_text_string(self.master_clients),
Expand All @@ -944,7 +945,7 @@ def create_new_client(self, give_focus=True, filename=''):
additional_options=self.additional_options(),
interpreter_versions=self.interpreter_versions(),
connection_file=cf,
menu_actions=self.menu_actions)
menu_actions=self.menu_actions, testing=testing)
self.add_tab(client, name=client.get_name(), filename=filename)

if cf is None:
Expand Down
19 changes: 19 additions & 0 deletions spyder/plugins/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ def close_console():
#==============================================================================
# Tests
#==============================================================================
def test_console_stderr_file(ipyconsole, qtbot):
"""Test a the creation of a console with a stderr file in ascii dir."""
# Wait until the window is fully up
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

# Create a new client with s stderr file in a non-ascii dir
ipyconsole.create_new_client(testing=True)
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)
with qtbot.waitSignal(shell.executed):
shell.execute('a = 1')

# Assert we get the a value correctly
assert shell.get_value('a') == 1


@flaky(max_runs=3)
def test_console_import_namespace(ipyconsole, qtbot):
"""Test an import of the form 'from foo import *'."""
Expand Down
9 changes: 7 additions & 2 deletions spyder/widgets/ipythonconsole/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def __init__(self, plugin, id_,
additional_options, interpreter_versions,
connection_file=None, hostname=None,
menu_actions=None, slave=False,
external_kernel=False, given_name=None):
external_kernel=False, given_name=None,
testing=False):
super(ClientWidget, self).__init__(plugin)
SaveHistoryMixin.__init__(self, history_filename)

Expand All @@ -113,6 +114,7 @@ def __init__(self, plugin, id_,
self.stop_icon = ima.icon('stop')
self.history = []
self.allow_rename = True
self.testing = testing

# --- Widgets
self.shellwidget = ShellWidget(config=config_options,
Expand Down Expand Up @@ -163,7 +165,10 @@ def stderr_file(self):
"""Filename to save kernel stderr output."""
if self.connection_file is not None:
stderr_file = self.kernel_id + '.stderr'
stderr_file = osp.join(TEMPDIR, stderr_file)
if not self.testing:
stderr_file = osp.join(TEMPDIR, stderr_file)
else:
stderr_file = osp.join(TEMPDIR, u'測試', u'اختبار', stderr_file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also find a solution similar to the one I posted above to avoid putting this temp directory as part of our source code.

return stderr_file

def configure_shellwidget(self, give_focus=True):
Expand Down