2023-11-01 16:58:43 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright © 2018, 2019 Endless Mobile, Inc.
|
|
|
|
# Copyright © 2023 Philip Withnall
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA
|
|
|
|
|
|
|
|
"""Integration tests for the gio utility."""
|
|
|
|
|
2025-07-09 00:45:13 +02:00
|
|
|
import platform
|
2023-11-01 16:58:43 +00:00
|
|
|
import subprocess
|
2023-11-08 10:29:43 +00:00
|
|
|
import sys
|
2023-11-01 16:58:43 +00:00
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
|
2025-07-08 22:51:36 +02:00
|
|
|
from pathlib import Path
|
|
|
|
|
2023-11-01 16:58:43 +00:00
|
|
|
import taptestrunner
|
2025-02-05 00:58:29 +01:00
|
|
|
import testprogramrunner
|
2023-11-01 16:58:43 +00:00
|
|
|
|
|
|
|
|
2025-02-05 00:58:29 +01:00
|
|
|
class TestGioTool(testprogramrunner.TestProgramRunner):
|
2023-11-01 16:58:43 +00:00
|
|
|
"""Integration test for running the gio tool.
|
|
|
|
|
|
|
|
This can be run when installed or uninstalled. When uninstalled, it
|
|
|
|
requires G_TEST_BUILDDIR and G_TEST_SRCDIR to be set.
|
|
|
|
|
|
|
|
The idea with this test harness is to test the gio utility, its
|
|
|
|
handling of command line arguments, its exit statuses, and its actual
|
|
|
|
effects on the file system.
|
|
|
|
"""
|
|
|
|
|
2025-02-05 00:58:29 +01:00
|
|
|
PROGRAM_NAME = "gio"
|
|
|
|
PROGRAM_TYPE = testprogramrunner.ProgramType.NATIVE
|
2023-11-01 16:58:43 +00:00
|
|
|
|
|
|
|
def runGio(self, *args):
|
2025-08-04 10:47:50 +02:00
|
|
|
return self.runTestProgram(args)
|
2023-11-01 16:58:43 +00:00
|
|
|
|
|
|
|
def test_help(self):
|
|
|
|
"""Test the --help argument and help subcommand."""
|
|
|
|
result = self.runGio("--help")
|
|
|
|
result2 = self.runGio("help")
|
|
|
|
|
|
|
|
self.assertEqual(result.out, result2.out)
|
|
|
|
self.assertEqual(result.err, result2.err)
|
|
|
|
|
|
|
|
self.assertIn("Usage:\n gio COMMAND", result.out)
|
|
|
|
self.assertIn("List the contents of locations", result.out)
|
|
|
|
|
|
|
|
def test_no_args(self):
|
|
|
|
"""Test running with no arguments at all."""
|
|
|
|
with self.assertRaises(subprocess.CalledProcessError):
|
|
|
|
self.runGio()
|
|
|
|
|
2023-11-01 17:01:50 +00:00
|
|
|
def test_info_non_default_attributes(self):
|
|
|
|
"""Test running `gio info --attributes` with a non-default list."""
|
|
|
|
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name) as tmpfile:
|
|
|
|
result = self.runGio(
|
|
|
|
"info", "--attributes=standard::content-type", tmpfile.name
|
|
|
|
)
|
2023-11-08 10:29:43 +00:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
self.assertIn("standard::content-type: public.text", result.out)
|
|
|
|
else:
|
|
|
|
self.assertIn(
|
|
|
|
"standard::content-type: application/x-zerosize", result.out
|
|
|
|
)
|
2023-11-01 17:01:50 +00:00
|
|
|
|
2023-11-01 16:58:43 +00:00
|
|
|
|
2025-07-09 00:45:13 +02:00
|
|
|
@unittest.skipIf(platform.system() == "Darwin", "gio launch not supported on darwin")
|
2025-07-08 22:51:36 +02:00
|
|
|
class TestGioLaunchExpandsDesktopEntry(testprogramrunner.TestProgramRunner):
|
|
|
|
"""Integration test for `gio launch` with field code %k in the Exec line.
|
|
|
|
|
|
|
|
This can be run when installed or uninstalled. When uninstalled, it
|
|
|
|
requires G_TEST_BUILDDIR and G_TEST_SRCDIR to be set.
|
|
|
|
|
|
|
|
The idea with this test harness is to test that the `gio launch` command
|
|
|
|
expands the `%k` field code in a desktop entry's Exec line to its location,
|
|
|
|
i.e. its absolute path.
|
|
|
|
"""
|
|
|
|
|
|
|
|
PROGRAM_NAME = "gio"
|
|
|
|
PROGRAM_TYPE = testprogramrunner.ProgramType.NATIVE
|
|
|
|
|
|
|
|
TEMPLATE = """
|
|
|
|
[Desktop Entry]
|
|
|
|
Type = Application
|
|
|
|
Name = Test
|
|
|
|
Exec = {python} -c 'print("%k")'
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super().setUp()
|
|
|
|
|
|
|
|
self.parent = Path(self.tmpdir.name).resolve()
|
|
|
|
|
|
|
|
self.folder = self.parent / "folder"
|
|
|
|
self.entry = self.folder / "desktop.entry"
|
|
|
|
|
|
|
|
self.sibling = self.parent / "sibling"
|
|
|
|
|
|
|
|
self.folder.mkdir(exist_ok=True, parents=True)
|
|
|
|
self.sibling.mkdir(exist_ok=True, parents=True)
|
|
|
|
|
|
|
|
with self.entry.open("w", encoding="utf-8") as fd:
|
|
|
|
fd.write(self.TEMPLATE.format(python=sys.executable))
|
|
|
|
|
|
|
|
def launchAndCheck(self, entry: Path, cwd: Path = None):
|
|
|
|
result = self.runTestProgram(["launch", str(entry)], cwd=str(cwd))
|
|
|
|
|
2025-07-15 12:26:43 +01:00
|
|
|
self.assertIn(str(self.entry), result.out)
|
2025-07-08 22:51:36 +02:00
|
|
|
|
|
|
|
def test_absolute_from_folder(self):
|
|
|
|
"""Test with absolute path, with changing working directory to folder."""
|
|
|
|
self.launchAndCheck(self.entry, cwd=self.folder)
|
|
|
|
|
|
|
|
def test_absolute_from_parent(self):
|
|
|
|
"""Test with absolute path, with changing working directory to parent."""
|
|
|
|
self.launchAndCheck(self.entry, cwd=self.parent)
|
|
|
|
|
|
|
|
def test_absolute_from_sibling(self):
|
|
|
|
"""Test with absolute path, with changing working directory to sibling."""
|
|
|
|
self.launchAndCheck(self.entry, cwd=self.sibling)
|
|
|
|
|
|
|
|
def test_relative_from_folder(self):
|
|
|
|
"""Test with relative path, with changing working directory to folder."""
|
|
|
|
self.launchAndCheck(self.entry.relative_to(self.folder), cwd=self.folder)
|
|
|
|
|
|
|
|
def test_relative_from_parent(self):
|
|
|
|
"""Test with relative path, with changing working directory to parent."""
|
|
|
|
self.launchAndCheck(self.entry.relative_to(self.parent), cwd=self.parent)
|
|
|
|
|
|
|
|
def test_relative_from_sibling(self):
|
|
|
|
"""Test with relative path, with changing working directory to sibling."""
|
|
|
|
self.launchAndCheck(
|
|
|
|
Path("..") / self.entry.relative_to(self.parent), cwd=self.sibling
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-01 16:58:43 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main(testRunner=taptestrunner.TAPTestRunner())
|