summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/tests/utils.py')
-rw-r--r--bitbake/lib/bb/tests/utils.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/utils.py b/bitbake/lib/bb/tests/utils.py
new file mode 100644
index 0000000000..677b3872ba
--- /dev/null
+++ b/bitbake/lib/bb/tests/utils.py
@@ -0,0 +1,103 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# BitBake Tests for utils.py
5#
6# Copyright (C) 2012 Richard Purdie
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2 as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21
22import unittest
23import bb
24import os
25
26class VerCmpString(unittest.TestCase):
27
28 def test_vercmpstring(self):
29 result = bb.utils.vercmp_string('1', '2')
30 self.assertTrue(result < 0)
31 result = bb.utils.vercmp_string('2', '1')
32 self.assertTrue(result > 0)
33 result = bb.utils.vercmp_string('1', '1.0')
34 self.assertTrue(result < 0)
35 result = bb.utils.vercmp_string('1', '1.1')
36 self.assertTrue(result < 0)
37 result = bb.utils.vercmp_string('1.1', '1_p2')
38 self.assertTrue(result < 0)
39
40 def test_explode_dep_versions(self):
41 correctresult = {"foo" : ["= 1.10"]}
42 result = bb.utils.explode_dep_versions2("foo (= 1.10)")
43 self.assertEqual(result, correctresult)
44 result = bb.utils.explode_dep_versions2("foo (=1.10)")
45 self.assertEqual(result, correctresult)
46 result = bb.utils.explode_dep_versions2("foo ( = 1.10)")
47 self.assertEqual(result, correctresult)
48 result = bb.utils.explode_dep_versions2("foo ( =1.10)")
49 self.assertEqual(result, correctresult)
50 result = bb.utils.explode_dep_versions2("foo ( = 1.10 )")
51 self.assertEqual(result, correctresult)
52 result = bb.utils.explode_dep_versions2("foo ( =1.10 )")
53 self.assertEqual(result, correctresult)
54
55 def test_vercmp_string_op(self):
56 compareops = [('1', '1', '=', True),
57 ('1', '1', '==', True),
58 ('1', '1', '!=', False),
59 ('1', '1', '>', False),
60 ('1', '1', '<', False),
61 ('1', '1', '>=', True),
62 ('1', '1', '<=', True),
63 ('1', '0', '=', False),
64 ('1', '0', '==', False),
65 ('1', '0', '!=', True),
66 ('1', '0', '>', True),
67 ('1', '0', '<', False),
68 ('1', '0', '>>', True),
69 ('1', '0', '<<', False),
70 ('1', '0', '>=', True),
71 ('1', '0', '<=', False),
72 ('0', '1', '=', False),
73 ('0', '1', '==', False),
74 ('0', '1', '!=', True),
75 ('0', '1', '>', False),
76 ('0', '1', '<', True),
77 ('0', '1', '>>', False),
78 ('0', '1', '<<', True),
79 ('0', '1', '>=', False),
80 ('0', '1', '<=', True)]
81
82 for arg1, arg2, op, correctresult in compareops:
83 result = bb.utils.vercmp_string_op(arg1, arg2, op)
84 self.assertEqual(result, correctresult, 'vercmp_string_op("%s", "%s", "%s") != %s' % (arg1, arg2, op, correctresult))
85
86 # Check that clearly invalid operator raises an exception
87 self.assertRaises(bb.utils.VersionStringException, bb.utils.vercmp_string_op, '0', '0', '$')
88
89
90class Path(unittest.TestCase):
91 def test_unsafe_delete_path(self):
92 checkitems = [('/', True),
93 ('//', True),
94 ('///', True),
95 (os.getcwd().count(os.sep) * ('..' + os.sep), True),
96 (os.environ.get('HOME', '/home/test'), True),
97 ('/home/someone', True),
98 ('/home/other/', True),
99 ('/home/other/subdir', False),
100 ('', False)]
101 for arg1, correctresult in checkitems:
102 result = bb.utils._check_unsafe_delete_path(arg1)
103 self.assertEqual(result, correctresult, '_check_unsafe_delete_path("%s") != %s' % (arg1, correctresult))