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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#!/usr/bin/python3
# This file is part of libmodulemd
# Copyright (C) 2018 Red Hat, Inc.
#
# 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 sys
try:
import unittest
import gi
gi.require_version("Modulemd", "2.0")
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 TestBuildopts(TestBase):
def test_constructor(self):
# Test that the new() function works
b = Modulemd.Buildopts.new()
assert b
assert b.props.rpm_macros is None
assert b.get_rpm_macros() is None
assert b.get_rpm_whitelist() == []
assert b.get_arches() == []
# Test that init works with rpm_macros
b = Modulemd.Buildopts(rpm_macros="Test macros")
assert b
assert b.props.rpm_macros == "Test macros"
assert b.get_rpm_macros() == "Test macros"
assert b.get_rpm_whitelist() == []
assert b.get_arches() == []
def test_copy(self):
b_orig = Modulemd.Buildopts()
b = b_orig.copy()
assert b
assert b.props.rpm_macros is None
assert b.get_rpm_macros() is None
assert b.get_rpm_whitelist() == []
assert b.get_arches() == []
b.add_rpm_to_whitelist("test2")
b.add_rpm_to_whitelist("test3")
b.add_rpm_to_whitelist("test1")
b.add_arch("x86_64")
b.add_arch("ppc64le")
b = b_orig.copy()
assert b
# make sure lists added to b above got clobbered by copy
assert b.get_rpm_whitelist() == []
assert b.get_arches() == []
b_orig.set_rpm_macros("Test macros")
b_orig.add_rpm_to_whitelist("test2")
b_orig.add_rpm_to_whitelist("test3")
b_orig.add_rpm_to_whitelist("test1")
b_orig.add_arch("x86_64")
b_orig.add_arch("ppc64le")
b = b_orig.copy()
assert b
assert b.props.rpm_macros == "Test macros"
assert b.get_rpm_macros() == "Test macros"
assert b.get_rpm_whitelist() == ["test1", "test2", "test3"]
assert b.get_arches() == ["ppc64le", "x86_64"]
def test_get_set_rpm_macros(self):
b = Modulemd.Buildopts()
assert b.props.rpm_macros is None
assert b.get_rpm_macros() is None
b.set_rpm_macros("foobar")
assert b.props.rpm_macros == "foobar"
assert b.get_rpm_macros() == "foobar"
b.props.rpm_macros = "barfoo"
assert b.props.rpm_macros == "barfoo"
assert b.get_rpm_macros() == "barfoo"
b.props.rpm_macros = None
assert b.props.rpm_macros is None
assert b.get_rpm_macros() is None
def test_whitelist(self):
b = Modulemd.Buildopts()
assert b.get_rpm_whitelist() == []
b.add_rpm_to_whitelist("test2")
assert b.get_rpm_whitelist() == ["test2"]
b.add_rpm_to_whitelist("test3")
b.add_rpm_to_whitelist("test1")
assert b.get_rpm_whitelist() == ["test1", "test2", "test3"]
b.add_rpm_to_whitelist("test2")
assert b.get_rpm_whitelist() == ["test1", "test2", "test3"]
b.remove_rpm_from_whitelist("test1")
assert b.get_rpm_whitelist() == ["test2", "test3"]
b.clear_rpm_whitelist()
assert b.get_rpm_whitelist() == []
def test_arches(self):
b = Modulemd.Buildopts()
assert b.get_arches() == []
b.add_arch("s390x")
assert b.get_arches() == ["s390x"]
b.add_arch("x86_64")
b.add_arch("ppc64le")
assert b.get_arches() == ["ppc64le", "s390x", "x86_64"]
b.add_arch("s390x")
assert b.get_arches() == ["ppc64le", "s390x", "x86_64"]
b.remove_arch("ppc64le")
assert b.get_arches() == ["s390x", "x86_64"]
b.clear_arches()
assert b.get_arches() == []
if __name__ == "__main__":
unittest.main()
|