Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import unittest |
| 2 | from oe.utils import packages_filter_out_system |
| 3 | |
| 4 | class TestPackagesFilterOutSystem(unittest.TestCase): |
| 5 | def test_filter(self): |
| 6 | """ |
| 7 | Test that oe.utils.packages_filter_out_system works. |
| 8 | """ |
| 9 | try: |
| 10 | import bb |
| 11 | except ImportError: |
| 12 | self.skipTest("Cannot import bb") |
| 13 | |
| 14 | d = bb.data_smart.DataSmart() |
| 15 | d.setVar("PN", "foo") |
| 16 | |
| 17 | d.setVar("PACKAGES", "foo foo-doc foo-dev") |
| 18 | pkgs = packages_filter_out_system(d) |
| 19 | self.assertEqual(pkgs, []) |
| 20 | |
| 21 | d.setVar("PACKAGES", "foo foo-doc foo-data foo-dev") |
| 22 | pkgs = packages_filter_out_system(d) |
| 23 | self.assertEqual(pkgs, ["foo-data"]) |
| 24 | |
| 25 | d.setVar("PACKAGES", "foo foo-locale-en-gb") |
| 26 | pkgs = packages_filter_out_system(d) |
| 27 | self.assertEqual(pkgs, []) |
| 28 | |
| 29 | d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb") |
| 30 | pkgs = packages_filter_out_system(d) |
| 31 | self.assertEqual(pkgs, ["foo-data"]) |
| 32 | |
| 33 | |
| 34 | class TestTrimVersion(unittest.TestCase): |
| 35 | def test_version_exception(self): |
| 36 | with self.assertRaises(TypeError): |
| 37 | trim_version(None, 2) |
| 38 | with self.assertRaises(TypeError): |
| 39 | trim_version((1, 2, 3), 2) |
| 40 | |
| 41 | def test_num_exception(self): |
| 42 | with self.assertRaises(ValueError): |
| 43 | trim_version("1.2.3", 0) |
| 44 | with self.assertRaises(ValueError): |
| 45 | trim_version("1.2.3", -1) |
| 46 | |
| 47 | def test_valid(self): |
| 48 | self.assertEqual(trim_version("1.2.3", 1), "1") |
| 49 | self.assertEqual(trim_version("1.2.3", 2), "1.2") |
| 50 | self.assertEqual(trim_version("1.2.3", 3), "1.2.3") |
| 51 | self.assertEqual(trim_version("1.2.3", 4), "1.2.3") |