1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#!/usr/bin/python3
# This file is part of libmodulemd
# Copyright (C) 2017-2018 Stephen Gallagher
#
# Fedora-License-Identifier: MIT
# SPDX-2.0-License-Identifier: MIT
# SPDX-3.0-License-Identifier: MIT
#
# This program is free software.
# For more information on the license, see COPYING.
# For more information on free software, see
# <https://www.gnu.org/philosophy/free-sw.en.html>.
import os
import sys
try:
import unittest
import gi
gi.require_version("Modulemd", "2.0")
from gi.repository import GLib
from gi.repository import Modulemd
except ImportError:
# Return error 77 to skip this test on platforms without the necessary
# python modules
sys.exit(77)
from base import TestBase
class TestRpmMapEntry(TestBase):
def test_basic(self):
# Test that the new() function works
entry = Modulemd.RpmMapEntry.new(
"bar", 0, "1.23", "1.module_deadbeef", "x86_64"
)
self.assertIsNotNone(entry)
self.assertEqual(entry.props.name, "bar")
self.assertEqual(entry.props.epoch, 0)
self.assertEqual(entry.props.version, "1.23")
self.assertEqual(entry.props.release, "1.module_deadbeef")
self.assertEqual(entry.props.arch, "x86_64")
self.assertEqual(
entry.props.nevra, "bar-0:1.23-1.module_deadbeef.x86_64"
)
# Test that object instantiation with attributes works
entry2 = Modulemd.RpmMapEntry(
name="bar",
version="1.23",
release="1.module_deadbeef",
arch="x86_64",
)
self.assertEqual(
entry2.props.nevra, "bar-0:1.23-1.module_deadbeef.x86_64"
)
# Test that nevra returns NULL if attributes are missing
# Remove name
entry2.props.name = None
with self.assertRaisesRegex(
gi.repository.GLib.GError, "Missing name attribute"
):
entry2.validate()
self.assertIsNone(entry2.props.nevra)
entry2.props.name = "bar"
# Remove the version
entry2.props.version = None
with self.assertRaisesRegex(
gi.repository.GLib.GError, "Missing version attribute"
):
entry2.validate()
self.assertIsNone(entry2.props.nevra)
entry2.props.version = "1.23"
# Remove the release
entry2.props.release = None
with self.assertRaisesRegex(
gi.repository.GLib.GError, "Missing release attribute"
):
entry2.validate()
self.assertIsNone(entry2.props.nevra)
entry2.props.release = "1.module_deadbeef"
# Remove the arch
entry2.props.arch = None
with self.assertRaisesRegex(
gi.repository.GLib.GError, "Missing arch attribute"
):
entry2.validate()
self.assertIsNone(entry2.props.nevra)
entry2.props.arch = "x86_64"
self.assertEqual(
entry2.props.nevra, "bar-0:1.23-1.module_deadbeef.x86_64"
)
def test_compare(self):
entry = Modulemd.RpmMapEntry.new(
"bar", 0, "1.23", "1.module_deadbeef", "x86_64"
)
self.assertIsNotNone(entry)
entry2 = Modulemd.RpmMapEntry.new(
"bar", 0, "1.23", "1.module_deadbeef", "x86_64"
)
self.assertIsNotNone(entry2)
entry3 = Modulemd.RpmMapEntry.new(
"foo", 0, "1.23", "1.module_deadbeef", "x86_64"
)
self.assertIsNotNone(entry3)
self.assertTrue(entry.equals(entry))
self.assertTrue(entry.equals(entry2))
self.assertFalse(entry.equals(entry3))
if __name__ == "__main__":
unittest.main()
|