summaryrefslogtreecommitdiff
path: root/gitlab/tests/test_cli.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2018-06-07 21:11:56 +0200
committerGitHub <noreply@github.com>2018-06-07 21:11:56 +0200
commitbbefb9936a18909d28d0f81b6ce99d4981ab8148 (patch)
tree50a2a05c4a99a5c18b6f6f0d99bdf40b05f17d98 /gitlab/tests/test_cli.py
parent92ca5c4f9e2c3a8651761c9b13a290df669d62a4 (diff)
parent3fa24ea8f5af361f39f1fb56ec911d381b680943 (diff)
downloadgitlab-bbefb9936a18909d28d0f81b6ce99d4981ab8148.tar.gz
Merge pull request #519 from jouve/silence
silence logs/warnings in unittests
Diffstat (limited to 'gitlab/tests/test_cli.py')
-rw-r--r--gitlab/tests/test_cli.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/gitlab/tests/test_cli.py b/gitlab/tests/test_cli.py
index 3c148f8..3fe4a4e 100644
--- a/gitlab/tests/test_cli.py
+++ b/gitlab/tests/test_cli.py
@@ -22,12 +22,25 @@ from __future__ import absolute_import
import argparse
import os
import tempfile
+try:
+ from contextlib import redirect_stderr # noqa: H302
+except ImportError:
+ from contextlib import contextmanager # noqa: H302
+ import sys
+
+ @contextmanager
+ def redirect_stderr(new_target):
+ old_target, sys.stderr = sys.stderr, new_target
+ yield
+ sys.stderr = old_target
try:
import unittest
except ImportError:
import unittest2 as unittest
+import six
+
from gitlab import cli
import gitlab.v4.cli
@@ -48,9 +61,11 @@ class TestCLI(unittest.TestCase):
self.assertEqual("class", cli.cls_to_what(Class))
def test_die(self):
- with self.assertRaises(SystemExit) as test:
- cli.die("foobar")
-
+ fl = six.StringIO()
+ with redirect_stderr(fl):
+ with self.assertRaises(SystemExit) as test:
+ cli.die("foobar")
+ self.assertEqual(fl.getvalue(), "foobar\n")
self.assertEqual(test.exception.code, 1)
def test_parse_value(self):
@@ -73,8 +88,14 @@ class TestCLI(unittest.TestCase):
self.assertEqual(ret, 'content')
os.unlink(temp_path)
- with self.assertRaises(SystemExit):
- cli._parse_value('@/thisfileprobablydoesntexist')
+ fl = six.StringIO()
+ with redirect_stderr(fl):
+ with self.assertRaises(SystemExit) as exc:
+ cli._parse_value('@/thisfileprobablydoesntexist')
+ self.assertEqual(fl.getvalue(),
+ "[Errno 2] No such file or directory:"
+ " '/thisfileprobablydoesntexist'\n")
+ self.assertEqual(exc.exception.code, 1)
def test_base_parser(self):
parser = cli._get_base_parser()