Skip to content

Commit b2a2393

Browse files
mmathesiussgallagher
authored andcommitted
Add python tests for PackagerV3.get/set_xmd()
Signed-off-by: Merlin Mathesius <[email protected]>
1 parent 55a0097 commit b2a2393

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

modulemd/tests/ModulemdTests/modulepackager.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,49 @@ def test_fail_v1(self):
186186
)
187187
)
188188

189+
def test_v3_xmd(self):
190+
191+
# We have a chicken-egg problem with overrides, since they can only
192+
# be tested if they are already installed. This means they need to
193+
# be run in the CI. In order to avoid changes to these tests or the
194+
# overrides breaking things, we'll skip them if the appropriate
195+
# override is not installed.
196+
if "_overrides_module" in dir(Modulemd) and hasattr(
197+
gi.overrides.Modulemd, "PackagerV3"
198+
):
199+
200+
# The XMD python tests can only be run against the installed lib
201+
# because the overrides that translate between python and GVariant
202+
# must be installed in /usr/lib/python*/site-packages/gi/overrides
203+
# or they are not included when importing Modulemd
204+
packager = Modulemd.PackagerV3.new()
205+
# An empty dictionary should be returned if no xmd value is set
206+
self.assertEqual(packager.get_xmd(), dict())
207+
208+
xmd = {"outer_key": {"inner_key": ["scalar", "another_scalar"]}}
209+
210+
packager.set_xmd(xmd)
211+
212+
xmd_copy = packager.get_xmd()
213+
assert xmd_copy
214+
assert "outer_key" in xmd_copy
215+
assert "inner_key" in xmd_copy["outer_key"]
216+
assert "scalar" in xmd_copy["outer_key"]["inner_key"]
217+
assert "another_scalar" in xmd_copy["outer_key"]["inner_key"]
218+
219+
# Verify that we can add content and save it back
220+
xmd["something"] = ["foo", "bar"]
221+
packager.set_xmd(xmd)
222+
223+
xmd_copy = packager.get_xmd()
224+
assert xmd_copy
225+
assert "outer_key" in xmd_copy
226+
assert "inner_key" in xmd_copy["outer_key"]
227+
assert "scalar" in xmd_copy["outer_key"]["inner_key"]
228+
assert "another_scalar" in xmd_copy["outer_key"]["inner_key"]
229+
assert "something" in xmd_copy
230+
assert xmd_copy["something"] == ["foo", "bar"]
231+
189232

190233
if __name__ == "__main__":
191234
unittest.main()

0 commit comments

Comments
 (0)