diff options
| author | Ross Burton <ross.burton@intel.com> | 2013-05-23 18:45:01 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-05-30 20:59:09 +0100 |
| commit | fcfba0ddd95fd459f03a4996c69ff5484aa4f083 (patch) | |
| tree | 7527579d72475e34327fd564df9dbec27ac0e90d /meta/lib/oe/tests/test_utils.py | |
| parent | f5d0f6becc6d1eb3a525a9e66ffd8bba52e2ae4e (diff) | |
| download | poky-fcfba0ddd95fd459f03a4996c69ff5484aa4f083.tar.gz | |
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>
Diffstat (limited to 'meta/lib/oe/tests/test_utils.py')
| -rw-r--r-- | meta/lib/oe/tests/test_utils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/meta/lib/oe/tests/test_utils.py b/meta/lib/oe/tests/test_utils.py index 466c47eb9c..78b1361161 100644 --- a/meta/lib/oe/tests/test_utils.py +++ b/meta/lib/oe/tests/test_utils.py | |||
| @@ -25,3 +25,23 @@ class TestPackagesFilterOutSystem(unittest.TestCase): | |||
| 25 | d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb") | 25 | d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb") |
| 26 | pkgs = oe.utils.packages_filter_out_system(d) | 26 | pkgs = oe.utils.packages_filter_out_system(d) |
| 27 | self.assertEqual(pkgs, ["foo-data"]) | 27 | self.assertEqual(pkgs, ["foo-data"]) |
| 28 | |||
| 29 | |||
| 30 | class TestTrimVersion(unittest.TestCase): | ||
| 31 | def test_version_exception(self): | ||
| 32 | with self.assertRaises(TypeError): | ||
| 33 | trim_version(None, 2) | ||
| 34 | with self.assertRaises(TypeError): | ||
| 35 | trim_version((1, 2, 3), 2) | ||
| 36 | |||
| 37 | def test_num_exception(self): | ||
| 38 | with self.assertRaises(ValueError): | ||
| 39 | trim_version("1.2.3", 0) | ||
| 40 | with self.assertRaises(ValueError): | ||
| 41 | trim_version("1.2.3", -1) | ||
| 42 | |||
| 43 | def test_valid(self): | ||
| 44 | self.assertEqual(trim_version("1.2.3", 1), "1") | ||
| 45 | self.assertEqual(trim_version("1.2.3", 2), "1.2") | ||
| 46 | self.assertEqual(trim_version("1.2.3", 3), "1.2.3") | ||
| 47 | self.assertEqual(trim_version("1.2.3", 4), "1.2.3") | ||
