Skip to content

Commit 1d57454

Browse files
committed
Tests: test output of action query
1 parent fabe75d commit 1d57454

File tree

1 file changed

+57
-13
lines changed

1 file changed

+57
-13
lines changed

tests/Controller.py

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from unittest.mock import patch, Mock
99
import subprocess
1010
from io import StringIO
11+
import textwrap
1112

1213
from TestUtils import (
1314
make_temp_dir, RiftTestCase, RiftProjectTestCase
@@ -44,22 +45,11 @@ def test_main_version(self):
4445
self.assert_except(SystemExit, "0", main, ['--version'])
4546

4647

47-
class ControllerProjectTest(RiftProjectTestCase):
48+
class ControllerProjectActionQueryTest(RiftProjectTestCase):
4849
"""
49-
Tests class for Controller
50+
Tests class for Controller action query
5051
"""
5152

52-
def _check_qemuuserstatic(self):
53-
"""Skip the test if none qemu-$arch-static executable is found for all
54-
architectures declared in project configuration."""
55-
if not any(
56-
[
57-
os.path.exists(f"/usr/bin/qemu-{arch}-static")
58-
for arch in self.config.get('arch')
59-
]
60-
):
61-
self.skipTest("qemu-user-static is not available")
62-
6353
def test_action_query(self):
6454
"""simple 'rift query' is ok """
6555
self.assertEqual(main(['query']), 0)
@@ -77,6 +67,60 @@ def test_action_query_on_bad_pkg(self):
7767
self.make_pkg(name='pkg2', metadata={})
7868
self.assertEqual(main(['query']), 0)
7969

70+
@patch('sys.stdout', new_callable=StringIO)
71+
def test_action_query_output_default(self, mock_stdout):
72+
self.make_pkg(name="pkg1")
73+
self.make_pkg(name="pkg2", version='2.1', release='3')
74+
self.assertEqual(main(['query']), 0)
75+
self.assertIn(
76+
"NAME MODULE MAINTAINERS VERSION RELEASE MODULEMANAGER",
77+
mock_stdout.getvalue())
78+
self.assertIn(textwrap.dedent("""
79+
---- ------ ----------- ------- ------- -------------
80+
pkg1 Great module Myself 1.0 1 buddy@somewhere.org
81+
pkg2 Great module Myself 2.1 3 buddy@somewhere.org
82+
"""),
83+
mock_stdout.getvalue())
84+
85+
@patch('sys.stdout', new_callable=StringIO)
86+
def test_action_query_output_format(self, mock_stdout):
87+
self.make_pkg(name="pkg1")
88+
self.make_pkg(name="pkg2", version='2.1', release='3')
89+
self.assertEqual(
90+
main([
91+
'query', '--format',
92+
'%name %module %origin %reason %tests %version %arch %release '
93+
'%changelogname %changelogtime %maintainers %modulemanager '
94+
'%buildrequires']), 0)
95+
self.assertIn(
96+
"NAME MODULE ORIGIN REASON TESTS VERSION ARCH "
97+
"RELEASE CHANGELOGNAME CHANGELOGTIME "
98+
"MAINTAINERS MODULEMANAGER BUILDREQUIRES",
99+
mock_stdout.getvalue())
100+
self.assertIn(textwrap.dedent("""
101+
---- ------ ------ ------ ----- ------- ---- ------- ------------- ------------- ----------- ------------- -------------
102+
pkg1 Great module Vendor Missing feature 0 1.0 noarch 1 Myself <buddy@somewhere.org> 1.0-1 2019-02-26 Myself buddy@somewhere.org br-package
103+
pkg2 Great module Vendor Missing feature 0 2.1 noarch 3 Myself <buddy@somewhere.org> 2.1-3 2019-02-26 Myself buddy@somewhere.org br-package
104+
"""),
105+
mock_stdout.getvalue())
106+
107+
108+
class ControllerProjectTest(RiftProjectTestCase):
109+
"""
110+
Tests class for Controller
111+
"""
112+
113+
def _check_qemuuserstatic(self):
114+
"""Skip the test if none qemu-$arch-static executable is found for all
115+
architectures declared in project configuration."""
116+
if not any(
117+
[
118+
os.path.exists(f"/usr/bin/qemu-{arch}-static")
119+
for arch in self.config.get('arch')
120+
]
121+
):
122+
self.skipTest("qemu-user-static is not available")
123+
80124
@patch('rift.Controller.remove_packages')
81125
@patch('rift.Controller.validate_pkgs')
82126
@patch('rift.Controller.get_packages_from_patch')

0 commit comments

Comments
 (0)