2013-10-27 18:47:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-05-16 09:48:57 +00:00
|
|
|
import mock
|
2013-10-27 18:47:13 +00:00
|
|
|
import unittest
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
from pungi.arch import (
|
|
|
|
get_compatible_arches,
|
|
|
|
get_valid_arches,
|
|
|
|
get_valid_multilib_arches,
|
|
|
|
is_excluded,
|
|
|
|
is_valid_arch,
|
|
|
|
split_name_arch,
|
|
|
|
)
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestArch(unittest.TestCase):
|
|
|
|
def test_i386(self):
|
|
|
|
arches = get_valid_arches("i386")
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(arches, ["i686", "i586", "i486", "i386", "noarch"])
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
arches = get_valid_arches("i386", multilib=False)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(arches, ["i686", "i586", "i486", "i386", "noarch"])
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
arches = get_valid_arches("i386", add_src=True)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(arches, ["i686", "i586", "i486", "i386", "noarch", "src"])
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
def test_x86_64(self):
|
|
|
|
arches = get_valid_arches("x86_64")
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
arches, ["x86_64", "athlon", "i686", "i586", "i486", "i386", "noarch"]
|
|
|
|
)
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
arches = get_valid_arches("x86_64", multilib=False)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(arches, ["x86_64", "noarch"])
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
arches = get_valid_arches("x86_64", add_src=True)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
arches,
|
|
|
|
["x86_64", "athlon", "i686", "i586", "i486", "i386", "noarch", "src"],
|
|
|
|
)
|
2013-10-27 18:47:13 +00:00
|
|
|
|
2015-07-22 12:27:56 +00:00
|
|
|
def test_armhfp(self):
|
|
|
|
arches = get_valid_arches("armhfp")
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(arches, ["armv7hnl", "armv7hl", "armv6hl", "noarch"])
|
2015-07-22 12:27:56 +00:00
|
|
|
|
|
|
|
arches = get_valid_arches("armhfp", multilib=False)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(arches, ["armv7hnl", "armv7hl", "armv6hl", "noarch"])
|
2015-07-22 12:27:56 +00:00
|
|
|
|
|
|
|
arches = get_valid_arches("armhfp", add_src=True)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(arches, ["armv7hnl", "armv7hl", "armv6hl", "noarch", "src"])
|
2015-07-22 12:27:56 +00:00
|
|
|
|
2013-10-27 18:47:13 +00:00
|
|
|
def test_get_compatible_arches(self):
|
|
|
|
self.assertEqual(get_compatible_arches("noarch"), ["noarch"])
|
|
|
|
self.assertEqual(get_compatible_arches("i386"), get_valid_arches("i386"))
|
|
|
|
self.assertEqual(get_compatible_arches("i586"), get_valid_arches("i386"))
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
get_compatible_arches("x86_64"), get_valid_arches("x86_64", multilib=False)
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
get_compatible_arches("ppc64p7"), get_valid_arches("ppc64", multilib=False)
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
get_compatible_arches("armhfp"),
|
|
|
|
get_valid_arches("armv7hnl", multilib=False),
|
|
|
|
)
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
def test_is_valid_arch(self):
|
|
|
|
self.assertEqual(is_valid_arch("i386"), True)
|
|
|
|
self.assertEqual(is_valid_arch("x86_64"), True)
|
|
|
|
self.assertEqual(is_valid_arch("noarch"), True)
|
|
|
|
self.assertEqual(is_valid_arch("src"), True)
|
|
|
|
self.assertEqual(is_valid_arch("nosrc"), True)
|
|
|
|
self.assertEqual(is_valid_arch("foo"), False)
|
2015-07-22 12:27:56 +00:00
|
|
|
self.assertEqual(is_valid_arch("armhfp"), False)
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
def test_split_name_arch(self):
|
|
|
|
self.assertEqual(split_name_arch("package"), ("package", None))
|
|
|
|
self.assertEqual(split_name_arch("package.x86_64"), ("package", "x86_64"))
|
|
|
|
self.assertEqual(split_name_arch("package.foo"), ("package.foo", None))
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
split_name_arch("i386"), ("i386", None)
|
|
|
|
) # we suppose that $name is never empty
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
def test_get_valid_multilib_arches(self):
|
|
|
|
self.assertEqual(get_valid_multilib_arches("noarch"), [])
|
|
|
|
self.assertEqual(get_valid_multilib_arches("athlon"), [])
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
get_valid_multilib_arches("x86_64"),
|
|
|
|
["athlon", "i686", "i586", "i486", "i386"],
|
|
|
|
)
|
2013-10-27 18:47:13 +00:00
|
|
|
|
|
|
|
|
2017-06-06 13:25:04 +00:00
|
|
|
class TestExclusiveExcludeArch(unittest.TestCase):
|
|
|
|
def test_no_exclude(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = mock.Mock(excludearch=[], exclusivearch=[], file_name="pkg.rpm")
|
|
|
|
self.assertFalse(is_excluded(pkg, ["x86_64"]))
|
2017-06-06 13:25:04 +00:00
|
|
|
|
|
|
|
def test_exclude_arch(self):
|
|
|
|
log = mock.Mock()
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = mock.Mock(excludearch=["x86_64"], exclusivearch=[], file_name="pkg.rpm")
|
|
|
|
self.assertTrue(is_excluded(pkg, ["x86_64"], logger=log))
|
|
|
|
self.assertEqual(
|
|
|
|
log.mock_calls,
|
|
|
|
[mock.call.debug("Excluding (EXCLUDEARCH: ['x86_64']): pkg.rpm")],
|
|
|
|
)
|
2017-06-06 13:25:04 +00:00
|
|
|
|
|
|
|
def test_exclusive_arch(self):
|
|
|
|
log = mock.Mock()
|
2020-01-22 10:02:22 +00:00
|
|
|
pkg = mock.Mock(excludearch=[], exclusivearch=["aarch64"], file_name="pkg.rpm")
|
|
|
|
self.assertTrue(is_excluded(pkg, ["x86_64"], logger=log))
|
|
|
|
self.assertEqual(
|
|
|
|
log.mock_calls,
|
|
|
|
[mock.call.debug("Excluding (EXCLUSIVEARCH: ['aarch64']): pkg.rpm")],
|
|
|
|
)
|