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

Commitbbefb99

Browse files
author
Gauvain Pocentek
authored
Merge pull request#519 from jouve/silence
silence logs/warnings in unittests
2 parents92ca5c4 +3fa24ea commitbbefb99

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

‎gitlab/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def _parse_value(v):
120120
# If the user-provided value starts with @, we try to read the file
121121
# path provided after @ as the real value. Exit on any error.
122122
try:
123-
returnopen(v[1:]).read()
123+
withopen(v[1:])asfl:
124+
returnfl.read()
124125
exceptExceptionase:
125126
sys.stderr.write("%s\n"%e)
126127
sys.exit(1)

‎gitlab/tests/test_cli.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,25 @@
2222
importargparse
2323
importos
2424
importtempfile
25+
try:
26+
fromcontextlibimportredirect_stderr# noqa: H302
27+
exceptImportError:
28+
fromcontextlibimportcontextmanager# noqa: H302
29+
importsys
30+
31+
@contextmanager
32+
defredirect_stderr(new_target):
33+
old_target,sys.stderr=sys.stderr,new_target
34+
yield
35+
sys.stderr=old_target
2536

2637
try:
2738
importunittest
2839
exceptImportError:
2940
importunittest2asunittest
3041

42+
importsix
43+
3144
fromgitlabimportcli
3245
importgitlab.v4.cli
3346

@@ -48,9 +61,11 @@ class TestClass(object):
4861
self.assertEqual("class",cli.cls_to_what(Class))
4962

5063
deftest_die(self):
51-
withself.assertRaises(SystemExit)astest:
52-
cli.die("foobar")
53-
64+
fl=six.StringIO()
65+
withredirect_stderr(fl):
66+
withself.assertRaises(SystemExit)astest:
67+
cli.die("foobar")
68+
self.assertEqual(fl.getvalue(),"foobar\n")
5469
self.assertEqual(test.exception.code,1)
5570

5671
deftest_parse_value(self):
@@ -73,8 +88,14 @@ def test_parse_value(self):
7388
self.assertEqual(ret,'content')
7489
os.unlink(temp_path)
7590

76-
withself.assertRaises(SystemExit):
77-
cli._parse_value('@/thisfileprobablydoesntexist')
91+
fl=six.StringIO()
92+
withredirect_stderr(fl):
93+
withself.assertRaises(SystemExit)asexc:
94+
cli._parse_value('@/thisfileprobablydoesntexist')
95+
self.assertEqual(fl.getvalue(),
96+
"[Errno 2] No such file or directory:"
97+
" '/thisfileprobablydoesntexist'\n")
98+
self.assertEqual(exc.exception.code,1)
7899

79100
deftest_base_parser(self):
80101
parser=cli._get_base_parser()

‎gitlab/tests/test_gitlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def resp_cont(url, request):
439439
withHTTMock(resp_cont):
440440
callback()
441441
self.assertEqual(self.gl.private_token,token)
442-
self.assertDictContainsSubset(expected,self.gl.headers)
442+
self.assertDictEqual(expected,self.gl.headers)
443443
self.assertEqual(self.gl.user.id,id_)
444444

445445
deftest_token_auth(self,callback=None):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp