diff --git a/modulemd/tests/ModulemdTests/base.py b/modulemd/tests/ModulemdTests/base.py index 55ac742b..16b90e0f 100644 --- a/modulemd/tests/ModulemdTests/base.py +++ b/modulemd/tests/ModulemdTests/base.py @@ -67,6 +67,36 @@ def assertProcessFailure(self, callable, *args): if os.WIFSIGNALED(status): raise AssertionError("Child process was unexpectedly aborted") + def assertTypeExceptionOrProcessFailure(self, callable, *args): + """Calls the callable in a subprocess and checks that the process + raised a TypeError exception, or was killed depending on Glib warning + fatality. + + Since pygobject-3.55.0 setting a G_PARAM_CONSTRUCT_ONLY property + raises a Python exception. Old pygobject continues down to Glib + which kills the process if Glib warnings a fatal, otherwise Glib + warning is printed and the code continues. + """ + pid = os.fork() + if pid == 0: + try: + callable(*args) + except TypeError: + os._exit(1) + os._exit(0) + _, status = os.waitpid(pid, 0) + if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 1: + return + if self.warnings_fatal: + if not os.WIFSIGNALED(status): + raise AssertionError( + "Child process did not raise TypeError " + "exception or was not aborted" + ) + else: + if os.WIFSIGNALED(status): + raise AssertionError("Child process was unexpectedly aborted") + @property def warnings_fatal(self): gdebug = os.getenv("G_DEBUG", "").split(",") diff --git a/modulemd/tests/ModulemdTests/defaults.py b/modulemd/tests/ModulemdTests/defaults.py index 3a1b9fe5..2f2ec023 100644 --- a/modulemd/tests/ModulemdTests/defaults.py +++ b/modulemd/tests/ModulemdTests/defaults.py @@ -111,7 +111,9 @@ def test_module_name(self): assert defs.get_module_name() == "foo" # Ensure we cannot set the module_name - self.assertProcessFailure(_set_module_name_to_none, defs) + self.assertTypeExceptionOrProcessFailure( + _set_module_name_to_none, defs + ) def test_modified(self): defs = Modulemd.Defaults.new( diff --git a/modulemd/tests/ModulemdTests/profile.py b/modulemd/tests/ModulemdTests/profile.py index 765c57d4..f8c7b931 100644 --- a/modulemd/tests/ModulemdTests/profile.py +++ b/modulemd/tests/ModulemdTests/profile.py @@ -94,7 +94,9 @@ def test_get_name(self): assert p.get_name() == "testprofile" assert p.props.name == "testprofile" - self.assertProcessFailure(_set_props_name, p, "notadrill") + self.assertTypeExceptionOrProcessFailure( + _set_props_name, p, "notadrill" + ) def test_get_set_description(self): p = Modulemd.Profile(name="testprofile") diff --git a/modulemd/tests/ModulemdTests/servicelevel.py b/modulemd/tests/ModulemdTests/servicelevel.py index fc9c648b..71289eb3 100644 --- a/modulemd/tests/ModulemdTests/servicelevel.py +++ b/modulemd/tests/ModulemdTests/servicelevel.py @@ -103,7 +103,7 @@ def test_get_name(self): assert sl.props.name == "foo" # This property is not writable, make sure it fails to attempt it - self.assertProcessFailure(_set_props_name, sl, "bar") + self.assertTypeExceptionOrProcessFailure(_set_props_name, sl, "bar") def test_get_set_eol(self): sl = Modulemd.ServiceLevel.new("foo") diff --git a/modulemd/tests/ModulemdTests/translationentry.py b/modulemd/tests/ModulemdTests/translationentry.py index 9fce4435..685349e2 100644 --- a/modulemd/tests/ModulemdTests/translationentry.py +++ b/modulemd/tests/ModulemdTests/translationentry.py @@ -172,7 +172,7 @@ def test_get_locale(self): assert te.get_locale() == "en_US" assert te.props.locale == "en_US" - self.assertProcessFailure(_set_locale, te) + self.assertTypeExceptionOrProcessFailure(_set_locale, te) def test_get_set_summary(self): te = Modulemd.TranslationEntry(locale="en_US")