tests: Fix race with progress window in GTK UI tests
Some GTK UI tests want to check if a information collection progress
window is shown. `ui_start_info_collection_progress` might show the
window and `ui_stop_info_collection_progress` will hide the window
again. If the information collection finishes too fast,
`test_crash_nodetails` will fail:
```
FAIL: test_crash_nodetails (__main__.T)
Crash report without showing details
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.10/unittest/mock.py", line 1369, in patched
return func(*newargs, **newkeywargs)
File "tests/system/test_ui_gtk.py", line 746, in test_crash_nodetails
self.assertEqual(self.visible_progress, True)
AssertionError: None != True
```
Wrap the `show()` method with a `MagicMock` object to record if the
windows was shown. This will fix the race condition.
Signed-off-by: Benjamin Drung <email address hidden>
Since commit 9959a0addf76 ("Replace ProblemReport.get_date by
.get_timestamp"), `in_session_of_problem` requires a `Report` object and
not a `dict`. Otherwise it will fail:
```
ERROR: test_in_session_of_problem (tests.integration.test_hookutils.T)
in_session_of_problem()
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests/integration/test_hookutils.py", line 407, in test_in_session_of_problem
self.assertFalse(apport.hookutils.in_session_of_problem(report))
File "apport/hookutils.py", line 1139, in in_session_of_problem
report_time = report.get_timestamp()
AttributeError: 'dict' object has no attribute 'get_timestamp'
```
Do not fail if a `dict` is passed to `in_session_of_problem` and replace
`dict` by `Report` in `test_in_session_of_problem` (except for one case
to test that `in_session_of_problem` can handle an empty dictionary).
Bug: https://launchpad.net/bugs/1978487
Fixes: 9959a0addf76 ("Replace ProblemReport.get_date by .get_timestamp")
Signed-off-by: Benjamin Drung <email address hidden>
Fix AttributeError: module 'importlib' has no attribute 'util'
On Ubuntu 22.10 (kinetic) some test cases fail during package build
with:
```
Traceback (most recent call last):
File "data/recoverable_problem", line 84, in <module>
main()
File "data/recoverable_problem", line 44, in main
report.add_proc_info(report.pid)
File "apport/report.py", line 701, in add_proc_info
self._check_interpreted()
File "apport/report.py", line 541, in _check_interpreted
path = self._python_module_path(cmdargs[2])
File "report.py", line 618, in _python_module_path
spec = importlib.util.find_spec(module)
AttributeError: module 'importlib' has no attribute 'util'
```
Having modified bash conffiles in the system can let following UI test
cases fail:
```
======================================================================
FAIL: test_run_crash_argv_file (tests.integration.test_ui.T)
run_crash() through a file specified on the command line
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.10/unittest/mock.py", line 1369, in patched
return func(*newargs, **newkeywargs)
File "tests/integration/test_ui.py", line 1075, in test_run_crash_argv_file
self.assertEqual(self.ui.msg_text, None)
AssertionError: 'It seems you have modified the contents [81 chars]ort?' != None
======================================================================
FAIL: test_run_symptom (tests.integration.test_ui.T)
run_symptom()
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.10/unittest/mock.py", line 1369, in patched
return func(*newargs, **newkeywargs)
File "tests/integration/test_ui.py", line 2294, in test_run_symptom
self.assertEqual(self.ui.msg_text, None)
AssertionError: 'It seems you have modified the contents [81 chars]ort?' != None
----------------------------------------------------------------------
```
So mock the `apport.hookutils.attach_conffiles()` call.
Signed-off-by: Benjamin Drung <email address hidden>
whoopsie-upload-all: Fix 'EOFError' object has no attribute 'errno'
```
Traceback (most recent call last):
File "data/whoopsie-upload-all", line 106, in process_report
r.add_gdb_info()
File "apport/report.py", line 883, in add_gdb_info
gdb_cmd, environ = self.gdb_command(rootdir, gdb_sandbox)
File "apport/report.py", line 1935, in gdb_command
self["CoreDump"].write(f)
File "problem_report.py", line 75, in write
block = gz.read(1048576)
File "/usr/lib/python3.10/gzip.py", line 301, in read
return self._buffer.read(size)
File "/usr/lib/python3.10/_compression.py", line 68, in readinto
data = self.read(len(byte_view))
File "/usr/lib/python3.10/gzip.py", line 507, in read
raise EOFError("Compressed file ended before the "
EOFError: Compressed file ended before the end-of-stream marker was reached
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "data/whoopsie-upload-all", line 248, in <module>
main()
File "data/whoopsie-upload-all", line 230, in main
stamps = collect_info()
File "data/whoopsie-upload-all", line 161, in collect_info
res = process_report(r)
File "data/whoopsie-upload-all", line 131, in process_report
if getattr(e, "errno") != errno.ENOENT:
AttributeError: 'EOFError' object has no attribute 'errno'
```
Bug: https://launchpad.net/bugs/1979681
Fixes: 655cea618502 ("whoopsie-upload-all: Do not upload after EOFError/zlib.error")
Signed-off-by: Benjamin Drung <email address hidden>
Use `--install-layout=deb` when installing Apport to correctly install
Apport into `/usr/lib/python3/dist-packages` to overwrite the version
provided by the Debian package.
Signed-off-by: Benjamin Drung <email address hidden>