Skip to content

Commit

Permalink
Fixes for CI tests (#271)
Browse files Browse the repository at this point in the history
* Fixes for Pylint possibly-used-before-assignment

* GH Actions workaround for Python 3.5
  • Loading branch information
avylove authored Jun 18, 2024
1 parent b165502 commit dc03e5c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,22 @@ jobs:
TOXPYTHON: python${{ matrix.toxpython || matrix.python-version }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
if: ${{ matrix.python-version != '2.7' }}
if: ${{ matrix.python-version != '2.7' && matrix.python-version != '3.5' }}

# Workaround for https://github.com/actions/setup-python/issues/866
- name: Set up Python 3.5 (Workaround)
uses: actions/setup-python@v5
with:
python-version: 3.5
env:
PIP_TRUSTED_HOST: "pypi.python.org pypi.org files.pythonhosted.org"
if: ${{ matrix.python-version == '3.5' }}

- name: Install tox
run: pip install tox
Expand Down
4 changes: 3 additions & 1 deletion blessed/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def __init__keycodes(self):
# set input encoding and initialize incremental decoder

if IS_WINDOWS:
# pylint: disable-next=possibly-used-before-assignment
self._encoding = get_console_input_encoding() \
or locale.getpreferredencoding() or 'UTF-8'
else:
Expand Down Expand Up @@ -459,7 +460,7 @@ def _winsize(fd):
- ``ws_ypixel``: height of terminal by pixels (not accurate).
"""
if HAS_TTY:
# pylint: disable=protected-access
# pylint: disable=protected-access,possibly-used-before-assignment
data = fcntl.ioctl(fd, termios.TIOCGWINSZ, WINSZ._BUF)
return WINSZ(*struct.unpack(WINSZ._FMT, data))
return WINSZ(ws_row=25, ws_col=80, ws_xpixel=0, ws_ypixel=0)
Expand Down Expand Up @@ -1350,6 +1351,7 @@ def cbreak(self):
# Save current terminal mode:
save_mode = termios.tcgetattr(self._keyboard_fd)
save_line_buffered = self._line_buffered
# pylint: disable-next=possibly-used-before-assignment
tty.setcbreak(self._keyboard_fd, termios.TCSANOW)
try:
self._line_buffered = False
Expand Down
6 changes: 3 additions & 3 deletions tests/accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import sys
import codecs
import platform
import functools
import traceback
import contextlib
Expand Down Expand Up @@ -67,7 +66,7 @@ def __call__(self, *args, **kwargs): # pylint: disable=too-many-locals,too-comp
return

pid_testrunner = os.getpid()
pid, master_fd = pty.fork()
pid, master_fd = pty.fork() # pylint: disable=possibly-used-before-assignment
if pid == self._CHILD_PID:
# child process executes function, raises exception
# if failed, causing a non-zero exit code, using the
Expand Down Expand Up @@ -185,7 +184,8 @@ def read_until_eof(fd, encoding='utf8'):
@contextlib.contextmanager
def echo_off(fd):
"""Ensure any bytes written to pty fd are not duplicated as output."""
if platform.system() != 'Windows':
if not IS_WINDOWS:
# pylint: disable=possibly-used-before-assignment
try:
attrs = termios.tcgetattr(fd)
attrs[3] = attrs[3] & ~termios.ECHO
Expand Down
17 changes: 7 additions & 10 deletions tests/test_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"""Tests for keyboard support."""
# std imports
import os
import sys
import platform
import tempfile
import functools

# 3rd party
import pytest
import six

# local
from .accessories import TestTerminal, as_subprocess
Expand All @@ -25,9 +25,6 @@
else:
import jinxed as curses

if sys.version_info[0] == 3:
unichr = chr


@pytest.mark.skipif(IS_WINDOWS, reason="?")
def test_break_input_no_kb():
Expand Down Expand Up @@ -311,12 +308,12 @@ def child(kind): # pylint: disable=too-many-statements
mapper=term._keymap,
codes=term._keycodes)

assert resolve(unichr(10)).name == "KEY_ENTER"
assert resolve(unichr(13)).name == "KEY_ENTER"
assert resolve(unichr(8)).name == "KEY_BACKSPACE"
assert resolve(unichr(9)).name == "KEY_TAB"
assert resolve(unichr(27)).name == "KEY_ESCAPE"
assert resolve(unichr(127)).name == "KEY_BACKSPACE"
assert resolve(six.unichr(10)).name == "KEY_ENTER"
assert resolve(six.unichr(13)).name == "KEY_ENTER"
assert resolve(six.unichr(8)).name == "KEY_BACKSPACE"
assert resolve(six.unichr(9)).name == "KEY_TAB"
assert resolve(six.unichr(27)).name == "KEY_ESCAPE"
assert resolve(six.unichr(127)).name == "KEY_BACKSPACE"
assert resolve(u"\x1b[A").name == "KEY_UP"
assert resolve(u"\x1b[B").name == "KEY_DOWN"
assert resolve(u"\x1b[C").name == "KEY_RIGHT"
Expand Down
1 change: 1 addition & 0 deletions tests/test_length_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ def test_winsize(many_lines, many_columns):
def child(lines=25, cols=80):
# set the pty's virtual window size
val = struct.pack('HHHH', lines, cols, pixel_width, pixel_height)
# pylint: disable-next=possibly-used-before-assignment
fcntl.ioctl(sys.__stdout__.fileno(), termios.TIOCSWINSZ, val)
term = TestTerminal()
winsize = term._height_and_width()
Expand Down

0 comments on commit dc03e5c

Please sign in to comment.