2 # -*- coding: utf-8 -*-
4 # Copyright © 2022 Endless OS Foundation, LLC
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 """Integration tests for gobject-query utility."""
32 Result = collections.namedtuple("Result", ("info", "out", "err"))
35 class TestGobjectQuery(unittest.TestCase):
36 """Integration test for running gobject-query.
38 This can be run when installed or uninstalled. When uninstalled, it
39 requires G_TEST_BUILDDIR and G_TEST_SRCDIR to be set.
41 The idea with this test harness is to test the gobject-query utility, its
42 handling of command line arguments, and its exit statuses.
46 self.timeout_seconds = 10 # seconds per test
47 if "G_TEST_BUILDDIR" in os.environ:
48 self.__gobject_query = os.path.join(
49 os.environ["G_TEST_BUILDDIR"], "..", "gobject-query"
52 self.__gobject_query = shutil.which("gobject-query")
53 print("gobject-query:", self.__gobject_query)
55 def runGobjectQuery(self, *args):
56 argv = [self.__gobject_query]
58 print("Running:", argv)
60 env = os.environ.copy()
61 env["LC_ALL"] = "C.UTF-8"
62 print("Environment:", env)
64 # We want to ensure consistent line endings...
65 info = subprocess.run(
67 timeout=self.timeout_seconds,
68 stdout=subprocess.PIPE,
69 stderr=subprocess.PIPE,
74 info.check_returncode()
75 out = info.stdout.strip()
76 err = info.stderr.strip()
78 result = Result(info, out, err)
80 print("Output:", result.out)
84 """Test the --help argument."""
85 result = self.runGobjectQuery("--help")
86 self.assertIn("usage: gobject-query", result.out)
88 def test_version(self):
89 """Test the --version argument."""
90 result = self.runGobjectQuery("--version")
91 self.assertIn("2.", result.out)
93 def test_froots(self):
94 """Test running froots with no other arguments."""
95 result = self.runGobjectQuery("froots")
97 self.assertEqual("", result.err)
98 self.assertIn("├gboolean", result.out)
99 self.assertIn("├GObject", result.out)
102 """Test running tree with no other arguments."""
103 result = self.runGobjectQuery("tree")
105 self.assertEqual("", result.err)
106 self.assertIn("GObject", result.out)
109 if __name__ == "__main__":
110 unittest.main(testRunner=taptestrunner.TAPTestRunner())