Skip to content

Commit

Permalink
Merge pull request #92 from jitseniesen/unicode
Browse files Browse the repository at this point in the history
PR: Add Unicode character in test script
  • Loading branch information
jitseniesen authored Apr 25, 2024
2 parents d6ce369 + bfd7ed6 commit ce5897d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
10 changes: 7 additions & 3 deletions .github/scripts/generate-without-spyder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
"""Script to generate requirements/without-spyder.txt"""

import re
from pathlib import Path

with open('requirements/conda.txt') as infile:
with open('requirements/without-spyder.txt', 'w') as outfile:
rootdir = Path(__file__).parents[2]
input_filename = rootdir / 'requirements' / 'conda.txt'
output_filename = rootdir / 'requirements' / 'without-spyder.txt'

with open(input_filename) as infile:
with open(output_filename, 'w') as outfile:
for line in infile:
package_name = re.match('[-a-z0-9_]*', line).group(0)
if package_name != 'spyder':
outfile.write(line)

36 changes: 19 additions & 17 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
OS: ['ubuntu', 'macos', 'windows']
PYTHON_VERSION: ['3.8', '3.9', '3.10']
PYTHON_VERSION: ['3.9', '3.10', '3.11']
SPYDER_SOURCE: ['git']
name: ${{ matrix.OS }} py${{ matrix.PYTHON_VERSION }} spyder-from-${{ matrix.SPYDER_SOURCE }}
runs-on: ${{ matrix.OS }}-latest
Expand All @@ -23,21 +23,23 @@ jobs:
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
steps:
- name: Checkout branch
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: 'spyder-line-profiler'
- name: Install System Packages
if: matrix.OS == 'ubuntu'
run: |
sudo apt-get update --fix-missing
sudo apt-get install -qq pyqt5-dev-tools libxcb-xinerama0 xterm --fix-missing
- name: Install Conda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
auto-update-conda: true
python-version: ${{ matrix.PYTHON_VERSION }}
- name: Checkout Spyder from git
if: matrix.SPYDER_SOURCE == 'git'
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: 'spyder-ide/spyder'
path: 'spyder'
Expand All @@ -61,55 +63,55 @@ jobs:
if: matrix.SPYDER_SOURCE == 'git'
shell: bash -l {0}
run: |
python .github/scripts/generate-without-spyder.py
mamba install --file requirements/without-spyder.txt -y
python spyder-line-profiler/.github/scripts/generate-without-spyder.py
mamba install --file spyder-line-profiler/requirements/without-spyder.txt -y
- name: Install plugin dependencies
if: matrix.SPYDER_SOURCE == 'conda'
shell: bash -l {0}
run: mamba install --file requirements/conda.txt -y
run: mamba install --file spyder-line-profiler/requirements/conda.txt -y
- name: Install test dependencies
shell: bash -l {0}
run: |
mamba install nomkl -y -q
mamba install --file requirements/tests.txt -y
mamba install --file spyder-line-profiler/requirements/tests.txt -y
- name: Install plugin
shell: bash -l {0}
run: pip install --no-deps -e .
run: pip install --no-deps -e spyder-line-profiler
- name: Show environment information
shell: bash -l {0}
run: |
mamba info
mamba list
- name: Run tests (Linux)
if: matrix.OS == 'ubuntu'
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
shell: bash
command: |
. ~/.profile
xvfb-run --auto-servernum pytest spyder_line_profiler --cov=spyder_line_profiler --cov-report=xml -vv
xvfb-run --auto-servernum pytest spyder-line-profiler/spyder_line_profiler --cov=spyder_line_profiler --cov-report=xml -vv
- name: Run tests (MacOS)
if: matrix.OS == 'macos'
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
shell: bash
command: |
. ~/.profile
pytest spyder_line_profiler -x -vv
pytest spyder-line-profiler/spyder_line_profiler -x -vv
- name: Run tests (Windows)
if: matrix.OS == 'windows'
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: pytest spyder_line_profiler -x -vv
command: pytest spyder-line-profiler/spyder_line_profiler -x -vv
- name: Upload coverage to Codecov
if: matrix.OS == 'ubuntu' && matrix.PYTHON_VERSION == '3.10'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

7 changes: 5 additions & 2 deletions spyder_line_profiler/spyder/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Spyder Line Profiler Main Widget.
"""
# Standard library imports
import hashlib
import inspect
import linecache
import logging
Expand Down Expand Up @@ -417,7 +416,11 @@ def start(self, wdir=None, args=None):
self.clear_data()
self.error_output = ''

p_args = ['-m', 'kernprof', '-lvb', '-o', self.DATAPATH]
# Use UTF-8 mode so that profiler writes its output to DATAPATH using
# UTF-8 encoding, instead of the ANSI code page on Windows.
# See issue spyder-ide/spyder-line-profiler#90
p_args = ['-X', 'utf8', '-m', 'kernprof', '-lvb', '-o', self.DATAPATH]

if os.name == 'nt':
# On Windows, one has to replace backslashes by slashes to avoid
# confusion with escape characters (otherwise, for example, '\t'
Expand Down
15 changes: 8 additions & 7 deletions spyder_line_profiler/tests/test_lineprofiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# Third party imports
from qtpy.QtCore import Qt
from unittest.mock import Mock, patch
from unittest.mock import patch

# Local imports
from spyder_line_profiler.spyder.widgets import SpyderLineProfilerWidget
Expand All @@ -26,7 +26,7 @@
@profile
def foo():
time.sleep(1)
xs = []
xs = [] # Test non-ascii character: Σ
for k in range(100):
xs = xs + ['x']
foo()"""
Expand All @@ -37,14 +37,15 @@ def test_profile_and_display_results(qtbot, tmpdir):
os.chdir(tmpdir.strpath)
testfilename = tmpdir.join('test_foo.py').strpath

with open(testfilename, 'w') as f:
with open(testfilename, 'w', encoding='utf-8') as f:
f.write(TEST_SCRIPT)

MockQMessageBox = Mock()

widget = SpyderLineProfilerWidget(None)
with patch.object(widget, 'get_conf',
return_value=sys.executable) as mock_get_conf:
return_value=sys.executable) as mock_get_conf, \
patch('spyder_line_profiler.spyder.widgets.TextEditor') \
as MockTextEditor:

widget.setup()
qtbot.addWidget(widget)
with qtbot.waitSignal(widget.sig_finished, timeout=10000,
Expand All @@ -53,7 +54,7 @@ def test_profile_and_display_results(qtbot, tmpdir):

mock_get_conf.assert_called_once_with(
'executable', section='main_interpreter')
MockQMessageBox.assert_not_called()
MockTextEditor.assert_not_called()

dt = widget.datatree
assert dt.topLevelItemCount() == 1 # number of functions profiled
Expand Down

0 comments on commit ce5897d

Please sign in to comment.