rndusr / stig

TUI and CLI for the BitTorrent client Transmission
GNU General Public License v3.0
554 stars 24 forks source link

unit test error when trying to package with pypi-install #228

Open beren12 opened 1 year ago

beren12 commented 1 year ago

Was trying to make things more simple and package this with an auto-packager on debian but it tells me a unit test is failing. I believe all deps are installed. The error is as follows:

stig.tui.views (unittest.loader._FailedTest) ... ERROR

======================================================================
ERROR: stig.tui.views (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: stig.tui.views
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 470, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/tmp/tmpmhndrrmw/deb_dist/stig-0.12.3a0/.pybuild/cpython3_3.9_stig/build/stig/tui/views/__init__.py", line 14, in <module>
    from . import hooks
  File "/tmp/tmpmhndrrmw/deb_dist/stig-0.12.3a0/.pybuild/cpython3_3.9_stig/build/stig/tui/views/hooks.py", line 13, in <module>
    from .file import TUICOLUMNS as FCOLUMNS
  File "/tmp/tmpmhndrrmw/deb_dist/stig-0.12.3a0/.pybuild/cpython3_3.9_stig/build/stig/tui/views/file.py", line 19, in <module>
    from .base import CellWidgetBase, Style
  File "/tmp/tmpmhndrrmw/deb_dist/stig-0.12.3a0/.pybuild/cpython3_3.9_stig/build/stig/tui/views/base.py", line 18, in <module>
    from ..tuiobjects import bottombar
  File "/tmp/tmpmhndrrmw/deb_dist/stig-0.12.3a0/.pybuild/cpython3_3.9_stig/build/stig/tui/tuiobjects.py", line 107, in <module>
    logwidget = LogWidget(height=int(objects.localcfg['tui.log.height']),
  File "/tmp/tmpmhndrrmw/deb_dist/stig-0.12.3a0/.pybuild/cpython3_3.9_stig/build/stig/tui/logger.py", line 57, in __init__
    self._handler.setFormatter(handlers[0].formatter)
IndexError: list index out of range

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)
E: pybuild pybuild:353: test: plugin distutils failed with: exit code=1: cd /tmp/tmpmhndrrmw/deb_dist/stig-0.12.3a0/.pybuild/cpython3_3.9_stig/build; python3.9 -m unittest discover -v
dh_auto_test: error: pybuild --test -i python{version} -p 3.9 returned exit code 13
make: *** [debian/rules:7: build] Error 255
dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2
Traceback (most recent call last):
  File "/tmp/tmpmhndrrmw/deb_dist/tmp_py2dsc/stig-0.12.3a0/setup.py", line 27, in <module>
    setup(
  File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.9/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.9/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.9/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/lib/python3/dist-packages/stdeb/command/bdist_deb.py", line 67, in run
    util.process_command(syscmd, cwd=target_dirs[0])
  File "/usr/lib/python3/dist-packages/stdeb/util.py", line 226, in process_command
    check_call(args, cwd=cwd)
  File "/usr/lib/python3/dist-packages/stdeb/util.py", line 59, in check_call
    raise CalledProcessError(retcode)
stdeb.util.CalledProcessError: 2
ERROR running: /usr/bin/python3 setup.py --command-packages stdeb.command sdist_dsc --dist-dir=/tmp/tmpmhndrrmw/deb_dist --use-premade-distfile=/tmp/tmpmhndrrmw/stig-0.12.3a0.tar.gz bdist_deb
ERROR in deb_dist/tmp_py2dsc/stig-0.12.3a0
Traceback (most recent call last):
  File "/usr/bin/pypi-install", line 79, in <module>
    main()
  File "/usr/bin/pypi-install", line 64, in main
    subprocess.check_call(cmd, shell=True)
  File "/usr/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'py2dsc-deb stig-0.12.3a0.tar.gz' returned non-zero exit status 1.
beren12 commented 1 year ago

I'm not sure if it's an error on the pypi-install side or a unit test needs updating

rndusr commented 1 year ago

It's a bug in stig:

File "/tmp/tmpmhndrrmw/deb_dist/stig-0.12.3a0/.pybuild/cpython3_3.9_stig/build/stig/tui/logger.py", line 57, in init self._handler.setFormatter(handlers[0].formatter) IndexError: list index out of range

stig redirects logging to its TUI console in TUI mode, but it tries to preserve the existing log message formatter. This fails because there is no existing handler to get a formatter from.

If you want to fix this, it should be relatively simple:

try:
    self._handler.setFormatter(handlers[0].formatter)
except IndexError:
    self._handler.setFormatter(<create formatter from scratch>)

It's probably safe (maybe even preferable) to never use the existing formatter and always create one from scratch. It's been years since I worked on this code, so... I dunno.

If you are not familiar with the logging module: https://docs.python.org/3/library/logging.html