`test_get_file_package_diversion` fails on the GitHub CI in the Ubuntu
container, because the first line of `dpkg-divert` is a local diversion:
```
$ dpkg-divert --list
local diversion of /sbin/initctl to /sbin/initctl.distrib
diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash
local diversion of /usr/bin/man to /usr/bin/man.REAL
diversion of /bin/sh to /bin/sh.distrib by dash
```
So iterate over the output of `dpkg-divert --list` until the first
non-local diversion is found.
Signed-off-by: Benjamin Drung <email address hidden>
Running `test.test_python_crashes.T.test_ignoring` during Debian package
build fails, because the home directory does not exist:
```
======================================================================
ERROR: test_ignoring (__main__.T)
the Python crash hook respects the ignore list.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test_python_crashes.py", line 271, in test_ignoring
r.mark_ignore()
File "apport/report.py", line 1190, in mark_ignore
with open(ignore_file_path, 'w') as fd:
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/.apport-ignore.xml'
```
To be able to run the test without an existing home directory, mock the
`.apport-ignore.xml` file.
Signed-off-by: Benjamin Drung <email address hidden>
The variable `apport.fileutils.report_dir` reads the environment
variable `APPORT_REPORT_DIR` which can point to a directory that is
ignored by the Python hook.
So explicitly put the Python test script into `/var/tmp` (similar to
code in `_test_crash`).
Signed-off-by: Benjamin Drung <email address hidden>
The test case `test_debug` changes `sys.stderr`, but does not reset it
after the test finishes. That leaves stderr changed for the following
test cases (which is not desired).
Since only this one test case specifies the `debug` argument, drop this
argument and also the logging setup code (which would influence the
following test cases as well). Use `assertLogs` in `test_debug` to
change the logging level and also check that something is logged on
debug level.
Signed-off-by: Benjamin Drung <email address hidden>
The test case `test_add_gdb_info_exe_missing` will fail on Ubuntu 22.04
with non English locale configured:
```
$ python3 -m unittest test.test_report.T.test_add_gdb_info_exe_missing
Warnung: Memory read failed for corefile section, 4096 bytes at 0xffffffffff600000.
WARNING: Please install gdb-multiarch for processing reports from foreign architectures. Results with "gdb" will be very poor.
WARNING: Please install gdb-multiarch for processing reports from foreign architectures. Results with "gdb" will be very poor.
F
======================================================================
FAIL: test_add_gdb_info_exe_missing (test.test_report.T)
add_gdb_info() with missing executable
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test_report.py", line 693, in test_add_gdb_info_exe_missing
self.assertRaises(FileNotFoundError, pr.add_gdb_info)
AssertionError: FileNotFoundError not raised by add_gdb_info
----------------------------------------------------------------------
Ran 1 test in 0.546s
FAILED (failures=1)
```
Printing the output of the `gdb` call shows that some error messages
from gdb are translated (even with no environment variable set).
Setting an environment variable (like `LC_ALL=C`) when calling gdb will
trigger a warning:
```
/usr/bin/gdb: warning: Couldn't determine a path for the index cache directory.
```
So set the environment variable `HOME` to `/nonexistent` to prevent this
warning and to cause gdb to use C locale.
Signed-off-by: Benjamin Drung <email address hidden>
test: Fix failure if kernel module isofs is not installed
The test case `test_module_license_evaluation` will fail if the kernel
module `isofs` is not installed.
```
======================================================================
FAIL: test_module_license_evaluation (__main__.T)
module licenses can be validated correctly
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test_hookutils.py", line 38, in test_module_license_evaluation
self.assertTrue('GPL' in apport.hookutils._get_module_license('isofs'))
AssertionError: False is not true