Coverage for tests/unit_tests/managers/test_downloader.py: 100%
11 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 05:08 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 05:08 +0000
1# This file is part of the Apio project
2# (C) 2016-present FPGAwars
3# Project authors:
4# * Jesús Arroyo (Jesus89) (2016-2019)
5# * Juan Gonzalez (obijuan) (2019-2024)
6# * The Apio Team (2024-present)
7# License: GPLv2
9"""
10Tests of managers/downloader.py
11"""
13import gc
14import requests
15from pytest import MonkeyPatch, raises
16from apio.managers.downloader import FileDownloader
19def test_failed_construction_safe_finalizer(monkeypatch: MonkeyPatch):
20 """Tests that a FileDownloader whose construction failed, e.g. on a
21 connection timeout, does not raise from its __del__ finalizer. It used
22 to raise an AttributeError at garbage collection time, at an arbitrary
23 point of the program (pytest reports it as an 'unraisable exception'
24 error on an arbitrary test)."""
26 # -- Make requests.get raise a connect timeout, as when the server is
27 # -- unreachable. We mock it to avoid a dependency on real networking.
28 def mock_get(*_args, **_kwargs):
29 raise requests.exceptions.ConnectTimeout("test timeout")
31 monkeypatch.setattr(requests, "get", mock_get)
33 # -- Construct a downloader. The construction should fail before the
34 # -- request field is populated.
35 with raises(requests.exceptions.ConnectTimeout):
36 FileDownloader("http://localhost/no-such-file.tgz")
38 # -- Force the collection of the partially constructed object. With a
39 # -- broken finalizer, pytest flags an 'unraisable exception' error here.
40 gc.collect()