2024-01-26 07:38:32 +00:00
|
|
|
try:
|
|
|
|
from unittest import mock
|
|
|
|
except ImportError:
|
|
|
|
import mock
|
2020-01-22 10:02:22 +00:00
|
|
|
|
2018-03-29 14:34:52 +00:00
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
2017-09-11 06:15:34 +00:00
|
|
|
import six
|
|
|
|
|
2019-12-06 02:54:11 +00:00
|
|
|
from pungi.scripts.pungi_koji import cli_main
|
2017-09-11 06:15:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PungiKojiTestCase(unittest.TestCase):
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("sys.argv", new=["prog", "--version"])
|
|
|
|
@mock.patch("sys.stderr", new_callable=six.StringIO)
|
|
|
|
@mock.patch("sys.stdout", new_callable=six.StringIO)
|
|
|
|
@mock.patch("pungi.scripts.pungi_koji.get_full_version", return_value="a-b-c.111")
|
2017-09-05 08:01:21 +00:00
|
|
|
def test_version(self, get_full_version, stdout, stderr):
|
2019-12-06 02:54:11 +00:00
|
|
|
with self.assertRaises(SystemExit) as cm:
|
|
|
|
cli_main()
|
|
|
|
self.assertEqual(cm.exception.code, 0)
|
2017-09-05 08:01:21 +00:00
|
|
|
# Python 2.7 prints the version to stderr, 3.4+ to stdout.
|
|
|
|
if six.PY3:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertMultiLineEqual(stdout.getvalue(), "a-b-c.111\n")
|
2017-09-05 08:01:21 +00:00
|
|
|
else:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertMultiLineEqual(stderr.getvalue(), "a-b-c.111\n")
|