Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Provide feedback

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

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5748d37

Browse files
committed
test(unit): increase V4 CLI coverage
1 parent8bf53c8 commit5748d37

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

‎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
returnhelpers.FakeObject(fake_manager, {"attr1":"foo","alist": [1,2,3]})
2222

2323

24+
@pytest.fixture
25+
deffake_object_no_id(fake_manager):
26+
returnhelpers.FakeObjectWithoutId(fake_manager, {})
27+
28+
29+
@pytest.fixture
30+
deffake_object_long_repr(fake_manager):
31+
returnhelpers.FakeObjectWithLongRepr(fake_manager, {"test":"a"*100})
32+
33+
2434
@pytest.fixture
2535
deffake_object_with_parent(fake_manager_with_parent):
2636
returnhelpers.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+
classFakeObjectWithoutId(base.RESTObject):
19+
_id_attr=None
20+
21+
22+
classFakeObjectWithLongRepr(base.RESTObject):
23+
_id_attr=None
24+
_repr_attr="test"
25+
26+
1827
classOtherFakeObject(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
importargparse
22
importio
33
importos
4+
importsys
45
importtempfile
56
fromcontextlibimportredirect_stderr# noqa: H302
7+
fromunittestimportmock
68

79
importpytest
810

911
importgitlab.base
1012
fromgitlabimportcli
1113
fromgitlab.exceptionsimportGitlabError
14+
fromgitlab.v4importcliasv4_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
assertactions["--name"].required
152+
153+
154+
@pytest.mark.skipif(sys.version_info< (3,8),reason="added in 3.8")
155+
deftest_legacy_display_without_fields_warns(fake_object_no_id):
156+
printer=v4_cli.LegacyPrinter()
157+
158+
withmock.patch("builtins.print")asmocked:
159+
printer.display(fake_object_no_id,obj=fake_object_no_id)
160+
161+
assert"No default fields to show"inmocked.call_args.args[0]
162+
163+
164+
@pytest.mark.skipif(sys.version_info< (3,8),reason="added in 3.8")
165+
deftest_legacy_display_with_long_repr_truncates(fake_object_long_repr):
166+
printer=v4_cli.LegacyPrinter()
167+
168+
withmock.patch("builtins.print")asmocked:
169+
printer.display(fake_object_long_repr,obj=fake_object_long_repr)
170+
171+
assertlen(mocked.call_args.args[0])<80

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp