From 1f64088bdf6dd8a99b40cf2d5298a61c80ba091a Mon Sep 17 00:00:00 2001 From: Thomas Kluyver <thomas@kluyver.me.uk> Date: Wed, 24 Feb 2021 12:23:12 +0000 Subject: [PATCH] Add unit test for wait_on_transfer --- .gitlab-ci.yml | 2 +- tests/test_webservice.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 687b779fc..cc359a71f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,5 +8,5 @@ pytest: stage: test script: - python3 -m pip install --user -r requirements.txt - - python3 -m pip install --user pytest + - python3 -m pip install --user pytest pytest-asyncio testpath - pytest -vv tests/test_* diff --git a/tests/test_webservice.py b/tests/test_webservice.py index bd482d4e8..78b94192d 100644 --- a/tests/test_webservice.py +++ b/tests/test_webservice.py @@ -1,10 +1,14 @@ import sys from pathlib import Path +from testpath import MockCommand +from unittest import mock import pytest sys.path.insert(0, Path(__file__).parent / 'webservice') -from webservice.webservice import check_files, merge, parse_config # noqa +from webservice.webservice import ( + check_files, merge, parse_config, wait_on_transfer, +) def test_check_files(): @@ -63,3 +67,14 @@ def test_parse_config(): with pytest.raises(ValueError): config = {'somekey': 'a value'} config = parse_config(cmd, config) + + +@pytest.mark.asyncio +async def test_wait_on_transfer(tmp_path): + mock_getfattr = MockCommand( + 'getfattr', + content="""#!{}\nprint('user.status="dCache"')""".format(sys.executable) + ) + with mock.patch('asyncio.sleep'), mock_getfattr: + res = await wait_on_transfer(tmp_path, max_tries=1) + assert res is True -- GitLab