Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/tests/test_hgutil.py
- This file was added.
# Copyright (C) 2020 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
import time | |||||
import traceback | |||||
import pytest | |||||
from mercurial import hg # type: ignore | |||||
from .. import hgutil | |||||
def test_clone_timeout(monkeypatch): | |||||
src = "https://www.mercurial-scm.org/repo/hello" | |||||
dest = "/dev/null" | |||||
timeout = 1 | |||||
def clone(*args): | |||||
time.sleep(5) | |||||
monkeypatch.setattr(hg, "clone", clone) | |||||
marmoute: is this monkey patch cleaned up after the test ? | |||||
Done Inline Actionshttps://docs.pytest.org/en/stable/monkeypatch.html
acezar: https://docs.pytest.org/en/stable/monkeypatch.html
> All modifications will be undone after the… | |||||
with pytest.raises(hgutil.CloneTimeout) as e: | |||||
hgutil.clone(src, dest, timeout) | |||||
assert e.value.args == (src, timeout) | |||||
def test_clone_error(caplog, tmp_path, monkeypatch): | |||||
src = "https://www.mercurial-scm.org/repo/hello" | |||||
dest = "/dev/null" | |||||
expected_traceback = "Some traceback" | |||||
def clone(*args): | |||||
raise ValueError() | |||||
def print_exc(file): | |||||
file.write(expected_traceback) | |||||
monkeypatch.setattr(hg, "clone", clone) | |||||
monkeypatch.setattr(traceback, "print_exc", print_exc) | |||||
with pytest.raises(hgutil.CloneFailure) as e: | |||||
hgutil.clone(src, dest, 1) | |||||
assert e.value.args == (src, dest, expected_traceback) |
is this monkey patch cleaned up after the test ?