Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions modulemd/tests/ModulemdTests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")
Expand Down
4 changes: 3 additions & 1 deletion modulemd/tests/ModulemdTests/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion modulemd/tests/ModulemdTests/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion modulemd/tests/ModulemdTests/servicelevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion modulemd/tests/ModulemdTests/translationentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading