Files
poky/meta/lib/oe/tests/test_utils.py
Ross Burton fcfba0ddd9 utils: add trim_version() function
Add a helper function that returns just the first <num_parts> of <version>,
split by periods.  For example, trim_version("1.2.3", 2) will return "1.2".

This should help reduce the spread of numerous copies of this idea across
classes and recipes.

(From OE-Core rev: 17a12e3c62807a7d60fcbf0aa4fd9cf4a739a204)

Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-05-30 20:59:09 +01:00

48 lines
1.5 KiB
Python

import unittest
import bb, oe.utils
class TestPackagesFilterOutSystem(unittest.TestCase):
def test_filter(self):
"""
Test that oe.utils.packages_filter_out_system works.
"""
d = bb.data_smart.DataSmart()
d.setVar("PN", "foo")
d.setVar("PACKAGES", "foo foo-doc foo-dev")
pkgs = oe.utils.packages_filter_out_system(d)
self.assertEqual(pkgs, [])
d.setVar("PACKAGES", "foo foo-doc foo-data foo-dev")
pkgs = oe.utils.packages_filter_out_system(d)
self.assertEqual(pkgs, ["foo-data"])
d.setVar("PACKAGES", "foo foo-locale-en-gb")
pkgs = oe.utils.packages_filter_out_system(d)
self.assertEqual(pkgs, [])
d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb")
pkgs = oe.utils.packages_filter_out_system(d)
self.assertEqual(pkgs, ["foo-data"])
class TestTrimVersion(unittest.TestCase):
def test_version_exception(self):
with self.assertRaises(TypeError):
trim_version(None, 2)
with self.assertRaises(TypeError):
trim_version((1, 2, 3), 2)
def test_num_exception(self):
with self.assertRaises(ValueError):
trim_version("1.2.3", 0)
with self.assertRaises(ValueError):
trim_version("1.2.3", -1)
def test_valid(self):
self.assertEqual(trim_version("1.2.3", 1), "1")
self.assertEqual(trim_version("1.2.3", 2), "1.2")
self.assertEqual(trim_version("1.2.3", 3), "1.2.3")
self.assertEqual(trim_version("1.2.3", 4), "1.2.3")