Skip to content

Commit

Permalink
Merge 26e1294 into a187c1b
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed May 29, 2022
2 parents a187c1b + 26e1294 commit 23b8b8d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/linux-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
exclude:
- INSTALL_TYPE: 'conda'
QT_LIB: 'pyqt6'
timeout-minutes: 15
steps:
- name: Checkout branch
uses: actions/checkout@v3
Expand All @@ -42,11 +43,12 @@ jobs:
auto-activate-base: false
channels: conda-forge
channel-priority: strict
miniforge-variant: Mambaforge
python-version: ${{ matrix.PYTHON_VERSION }}
- name: Install dependencies with conda
if: matrix.INSTALL_TYPE == 'conda'
shell: bash -l {0}
run: conda env update --file requirements/environment.yml
run: mamba env update --file requirements/environment.yml
- name: Install dependencies with pip
if: matrix.INSTALL_TYPE == 'pip'
shell: bash -l {0}
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/macos-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.7', '3.8', '3.9', '3.10']
timeout-minutes: 15
steps:
- name: Checkout branch
uses: actions/checkout@v3
Expand All @@ -30,9 +31,13 @@ jobs:
auto-update-conda: false
auto-activate-base: false
python-version: ${{ matrix.PYTHON_VERSION }}
miniforge-variant: Mambaforge
channels: conda-forge
- name: Install package dependencies
shell: bash -l {0}
run: conda env update --file requirements/environment.yml
run: |
mamba env update --file requirements/environment.yml
mamba install tk=8.6.11=h7bc2e8c_0
- name: Show environment information
shell: bash -l {0}
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/windows-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.7', '3.8', '3.9', '3.10']
timeout-minutes: 15
steps:
- name: Checkout branch
uses: actions/checkout@v3
Expand All @@ -30,9 +31,12 @@ jobs:
auto-update-conda: false
auto-activate-base: false
python-version: ${{ matrix.PYTHON_VERSION }}
miniforge-variant: Mambaforge
channels: conda-forge
channel-priority: strict
- name: Install package dependencies
shell: bash -l {0}
run: conda env update --file requirements/environment.yml
run: mamba env update --file requirements/environment.yml
- name: Show environment information
shell: bash -l {0}
run: |
Expand Down
8 changes: 7 additions & 1 deletion qtconsole/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,6 @@ def _readline(self, prompt='', callback=None, password=False):
while self._reading:
QtCore.QCoreApplication.processEvents()
return self._get_input_buffer(force=True).rstrip('\n')

else:
self._reading_callback = lambda: \
callback(self._get_input_buffer(force=True).rstrip('\n'))
Expand Down Expand Up @@ -2480,6 +2479,12 @@ def _show_prompt(self, prompt=None, html=False, newline=True,
If set, a separator will be written before the prompt.
"""
self._flush_pending_stream()

# This is necessary to solve out-of-order insertion of mixed stdin and
# stdout stream texts.
# Fixes spyder-ide/spyder#17710
QtCore.QCoreApplication.processEvents()

cursor = self._get_end_cursor()

# Save the current position to support _append*(before_prompt=True).
Expand All @@ -2504,6 +2509,7 @@ def _show_prompt(self, prompt=None, html=False, newline=True,
# Write the prompt.
if separator:
self._append_plain_text(self._prompt_sep)

if prompt is None:
if self._prompt_html is None:
self._append_plain_text(self._prompt)
Expand Down
52 changes: 52 additions & 0 deletions qtconsole/tests/test_00_console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,58 @@ def test_debug(qtconsole, qtbot):
assert control.toPlainText().strip().split()[-1] == "abcd"


@flaky(max_runs=3)
def test_input_and_print(qtconsole, qtbot):
"""
Test that we print correctly mixed input and print statements.
This is a regression test for spyder-ide/spyder#17710.
"""
window = qtconsole.window
shell = window.active_frontend
control = shell._control

def wait_for_input():
qtbot.waitUntil(
lambda: control.toPlainText().splitlines()[-1] == 'Write input: '
)

# Wait until the console is fully up
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

# Run a for loop with mixed input and print statements
code = """
user_input = None
while user_input != '':
user_input = input('Write input: ')
print('Input was entered!')
"""
shell.execute(code)
wait_for_input()

# Interact with the 'for' loop for a certain number of repetitions
repetitions = 3
for _ in range(repetitions):
qtbot.keyClicks(control, '1')
qtbot.keyClick(control, QtCore.Qt.Key_Enter)
wait_for_input()

# Get out of the for loop
qtbot.keyClick(control, QtCore.Qt.Key_Enter)
qtbot.waitUntil(lambda: not shell._reading)
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

# Assert that printed correctly the expected output in the console.
output = (
" ...: \n" +
"Write input: 1\nInput was entered!\n" * repetitions +
"Write input: \nInput was entered!\n"
)
assert output in control.toPlainText()


@pytest.mark.skipif(no_display, reason="Doesn't work without a display")
class TestConsoleWidget(unittest.TestCase):

Expand Down

0 comments on commit 23b8b8d

Please sign in to comment.