← 返回首页
test(unit): increase V4 CLI coverage · python-gitlab/python-gitlab@5748d37 · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Commit 5748d37

Browse files
committed
test(unit): increase V4 CLI coverage
1 parent 8bf53c8 commit 5748d37

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎tests/unit/conftest.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ def fake_object(fake_manager):
2121
return helpers.FakeObject(fake_manager, {"attr1": "foo", "alist": [1, 2, 3]})
2222

2323

24+
@pytest.fixture
25+
def fake_object_no_id(fake_manager):
26+
return helpers.FakeObjectWithoutId(fake_manager, {})
27+
28+
29+
@pytest.fixture
30+
def fake_object_long_repr(fake_manager):
31+
return helpers.FakeObjectWithLongRepr(fake_manager, {"test": "a" * 100})
32+
33+
2434
@pytest.fixture
2535
def fake_object_with_parent(fake_manager_with_parent):
2636
return helpers.FakeObject(

‎tests/unit/helpers.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ class FakeObject(base.RESTObject):
1515
pass
1616

1717

18+
class FakeObjectWithoutId(base.RESTObject):
19+
_id_attr = None
20+
21+
22+
class FakeObjectWithLongRepr(base.RESTObject):
23+
_id_attr = None
24+
_repr_attr = "test"
25+
26+
1827
class OtherFakeObject(FakeObject):
1928
_id_attr = "foo"
2029

‎tests/unit/test_cli.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import argparse
22
import io
33
import os
4+
import sys
45
import tempfile
56
from contextlib import redirect_stderr # noqa: H302
7+
from unittest import mock
68

79
import pytest
810

911
import gitlab.base
1012
from gitlab import cli
1113
from gitlab.exceptions import GitlabError
14+
from gitlab.v4 import cli as v4_cli
1215

1316

1417
@pytest.mark.parametrize(
@@ -146,3 +149,23 @@ def test_v4_parser():
146149
)
147150
actions = user_subparsers.choices["create"]._option_string_actions
148151
assert actions["--name"].required
152+
153+
154+
@pytest.mark.skipif(sys.version_info < (3, 8), reason="added in 3.8")
155+
def test_legacy_display_without_fields_warns(fake_object_no_id):
156+
printer = v4_cli.LegacyPrinter()
157+
158+
with mock.patch("builtins.print") as mocked:
159+
printer.display(fake_object_no_id, obj=fake_object_no_id)
160+
161+
assert "No default fields to show" in mocked.call_args.args[0]
162+
163+
164+
@pytest.mark.skipif(sys.version_info < (3, 8), reason="added in 3.8")
165+
def test_legacy_display_with_long_repr_truncates(fake_object_long_repr):
166+
printer = v4_cli.LegacyPrinter()
167+
168+
with mock.patch("builtins.print") as mocked:
169+
printer.display(fake_object_long_repr, obj=fake_object_long_repr)
170+
171+
assert len(mocked.call_args.args[0]) < 80

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.