diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/conftest.py | 5 | ||||
-rw-r--r-- | tests/unit/fixtures/todo.json (renamed from tests/unit/data/todo.json) | 0 | ||||
-rw-r--r-- | tests/unit/objects/test_todos.py | 12 | ||||
-rw-r--r-- | tests/unit/test_cli.py | 14 | ||||
-rw-r--r-- | tests/unit/test_config.py | 2 |
5 files changed, 24 insertions, 9 deletions
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index f58c77a..929be1a 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -3,6 +3,11 @@ import pytest import gitlab +@pytest.fixture(scope="session") +def fixture_dir(test_dir): + return test_dir / "unit" / "fixtures" + + @pytest.fixture def gl(): return gitlab.Gitlab( diff --git a/tests/unit/data/todo.json b/tests/unit/fixtures/todo.json index 93b2151..93b2151 100644 --- a/tests/unit/data/todo.json +++ b/tests/unit/fixtures/todo.json diff --git a/tests/unit/objects/test_todos.py b/tests/unit/objects/test_todos.py index 9d6b6b4..ded6cf9 100644 --- a/tests/unit/objects/test_todos.py +++ b/tests/unit/objects/test_todos.py @@ -3,20 +3,22 @@ GitLab API: https://docs.gitlab.com/ce/api/todos.html """ import json -import os import pytest import responses from gitlab.v4.objects import Todo -with open(f"{os.path.dirname(__file__)}/../data/todo.json", "r") as json_file: - todo_content = json_file.read() - json_content = json.loads(todo_content) + +@pytest.fixture() +def json_content(fixture_dir): + with open(fixture_dir / "todo.json", "r") as json_file: + todo_content = json_file.read() + return json.loads(todo_content) @pytest.fixture -def resp_todo(): +def resp_todo(json_content): with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: rsps.add( method=responses.GET, diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index d5afe69..2ada1c3 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -25,6 +25,7 @@ from contextlib import redirect_stderr # noqa: H302 import pytest from gitlab import cli +from gitlab.exceptions import GitlabError @pytest.mark.parametrize( @@ -66,12 +67,19 @@ def test_cls_to_what(class_name, expected_what): assert cli.cls_to_what(TestClass) == expected_what -def test_die(): +@pytest.mark.parametrize( + "message,error,expected", + [ + ("foobar", None, "foobar\n"), + ("foo", GitlabError("bar"), "foo (bar)\n"), + ], +) +def test_die(message, error, expected): fl = io.StringIO() with redirect_stderr(fl): with pytest.raises(SystemExit) as test: - cli.die("foobar") - assert fl.getvalue() == "foobar\n" + cli.die(message, error) + assert fl.getvalue() == expected assert test.value.code == 1 diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index f7fffb2..82b9714 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -18,8 +18,8 @@ import io import os from textwrap import dedent +from unittest import mock -import mock import pytest from gitlab import config, USER_AGENT |