2017-09-11 06:15:34 +00:00
|
|
|
import mock
|
|
|
|
import unittest
|
|
|
|
import six
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
from tests.helpers import load_bin
|
2017-09-11 06:15:34 +00:00
|
|
|
|
|
|
|
cli = load_bin("pungi-koji")
|
|
|
|
|
|
|
|
|
|
|
|
class PungiKojiTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
@mock.patch('sys.argv', new=['prog', '--version'])
|
|
|
|
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
2017-09-05 08:01:21 +00:00
|
|
|
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
2017-09-11 06:15:34 +00:00
|
|
|
@mock.patch('pungi_cli_fake_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):
|
2017-09-11 06:15:34 +00:00
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
cli.main()
|
2017-09-05 08:01:21 +00:00
|
|
|
# Python 2.7 prints the version to stderr, 3.4+ to stdout.
|
|
|
|
if six.PY3:
|
|
|
|
self.assertMultiLineEqual(stdout.getvalue(), 'a-b-c.111\n')
|
|
|
|
else:
|
|
|
|
self.assertMultiLineEqual(stderr.getvalue(), 'a-b-c.111\n')
|