summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/tests')
-rw-r--r--bitbake/lib/bb/tests/__init__.py0
-rw-r--r--bitbake/lib/bb/tests/codeparser.py374
-rw-r--r--bitbake/lib/bb/tests/cow.py136
-rw-r--r--bitbake/lib/bb/tests/data.py254
-rw-r--r--bitbake/lib/bb/tests/fetch.py424
-rw-r--r--bitbake/lib/bb/tests/utils.py53
6 files changed, 1241 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/__init__.py b/bitbake/lib/bb/tests/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/bitbake/lib/bb/tests/__init__.py
diff --git a/bitbake/lib/bb/tests/codeparser.py b/bitbake/lib/bb/tests/codeparser.py
new file mode 100644
index 0000000000..938b04b2c6
--- /dev/null
+++ b/bitbake/lib/bb/tests/codeparser.py
@@ -0,0 +1,374 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# BitBake Test for codeparser.py
5#
6# Copyright (C) 2010 Chris Larson
7# Copyright (C) 2012 Richard Purdie
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21#
22
23import unittest
24import logging
25import bb
26
27logger = logging.getLogger('BitBake.TestCodeParser')
28
29# bb.data references bb.parse but can't directly import due to circular dependencies.
30# Hack around it for now :(
31import bb.parse
32import bb.data
33
34class ReferenceTest(unittest.TestCase):
35 def setUp(self):
36 self.d = bb.data.init()
37
38 def setEmptyVars(self, varlist):
39 for k in varlist:
40 self.d.setVar(k, "")
41
42 def setValues(self, values):
43 for k, v in values.items():
44 self.d.setVar(k, v)
45
46 def assertReferences(self, refs):
47 self.assertEqual(self.references, refs)
48
49 def assertExecs(self, execs):
50 self.assertEqual(self.execs, execs)
51
52class VariableReferenceTest(ReferenceTest):
53
54 def parseExpression(self, exp):
55 parsedvar = self.d.expandWithRefs(exp, None)
56 self.references = parsedvar.references
57
58 def test_simple_reference(self):
59 self.setEmptyVars(["FOO"])
60 self.parseExpression("${FOO}")
61 self.assertReferences(set(["FOO"]))
62
63 def test_nested_reference(self):
64 self.setEmptyVars(["BAR"])
65 self.d.setVar("FOO", "BAR")
66 self.parseExpression("${${FOO}}")
67 self.assertReferences(set(["FOO", "BAR"]))
68
69 def test_python_reference(self):
70 self.setEmptyVars(["BAR"])
71 self.parseExpression("${@bb.data.getVar('BAR', d, True) + 'foo'}")
72 self.assertReferences(set(["BAR"]))
73
74class ShellReferenceTest(ReferenceTest):
75
76 def parseExpression(self, exp):
77 parsedvar = self.d.expandWithRefs(exp, None)
78 parser = bb.codeparser.ShellParser("ParserTest", logger)
79 parser.parse_shell(parsedvar.value)
80
81 self.references = parsedvar.references
82 self.execs = parser.execs
83
84 def test_quotes_inside_assign(self):
85 self.parseExpression('foo=foo"bar"baz')
86 self.assertReferences(set([]))
87
88 def test_quotes_inside_arg(self):
89 self.parseExpression('sed s#"bar baz"#"alpha beta"#g')
90 self.assertExecs(set(["sed"]))
91
92 def test_arg_continuation(self):
93 self.parseExpression("sed -i -e s,foo,bar,g \\\n *.pc")
94 self.assertExecs(set(["sed"]))
95
96 def test_dollar_in_quoted(self):
97 self.parseExpression('sed -i -e "foo$" *.pc')
98 self.assertExecs(set(["sed"]))
99
100 def test_quotes_inside_arg_continuation(self):
101 self.setEmptyVars(["bindir", "D", "libdir"])
102 self.parseExpression("""
103sed -i -e s#"moc_location=.*$"#"moc_location=${bindir}/moc4"# \\
104-e s#"uic_location=.*$"#"uic_location=${bindir}/uic4"# \\
105${D}${libdir}/pkgconfig/*.pc
106""")
107 self.assertReferences(set(["bindir", "D", "libdir"]))
108
109 def test_assign_subshell_expansion(self):
110 self.parseExpression("foo=$(echo bar)")
111 self.assertExecs(set(["echo"]))
112
113 def test_shell_unexpanded(self):
114 self.setEmptyVars(["QT_BASE_NAME"])
115 self.parseExpression('echo "${QT_BASE_NAME}"')
116 self.assertExecs(set(["echo"]))
117 self.assertReferences(set(["QT_BASE_NAME"]))
118
119 def test_incomplete_varexp_single_quotes(self):
120 self.parseExpression("sed -i -e 's:IP{:I${:g' $pc")
121 self.assertExecs(set(["sed"]))
122
123
124 def test_until(self):
125 self.parseExpression("until false; do echo true; done")
126 self.assertExecs(set(["false", "echo"]))
127 self.assertReferences(set())
128
129 def test_case(self):
130 self.parseExpression("""
131case $foo in
132*)
133bar
134;;
135esac
136""")
137 self.assertExecs(set(["bar"]))
138 self.assertReferences(set())
139
140 def test_assign_exec(self):
141 self.parseExpression("a=b c='foo bar' alpha 1 2 3")
142 self.assertExecs(set(["alpha"]))
143
144 def test_redirect_to_file(self):
145 self.setEmptyVars(["foo"])
146 self.parseExpression("echo foo >${foo}/bar")
147 self.assertExecs(set(["echo"]))
148 self.assertReferences(set(["foo"]))
149
150 def test_heredoc(self):
151 self.setEmptyVars(["theta"])
152 self.parseExpression("""
153cat <<END
154alpha
155beta
156${theta}
157END
158""")
159 self.assertReferences(set(["theta"]))
160
161 def test_redirect_from_heredoc(self):
162 v = ["B", "SHADOW_MAILDIR", "SHADOW_MAILFILE", "SHADOW_UTMPDIR", "SHADOW_LOGDIR", "bindir"]
163 self.setEmptyVars(v)
164 self.parseExpression("""
165cat <<END >${B}/cachedpaths
166shadow_cv_maildir=${SHADOW_MAILDIR}
167shadow_cv_mailfile=${SHADOW_MAILFILE}
168shadow_cv_utmpdir=${SHADOW_UTMPDIR}
169shadow_cv_logdir=${SHADOW_LOGDIR}
170shadow_cv_passwd_dir=${bindir}
171END
172""")
173 self.assertReferences(set(v))
174 self.assertExecs(set(["cat"]))
175
176# def test_incomplete_command_expansion(self):
177# self.assertRaises(reftracker.ShellSyntaxError, reftracker.execs,
178# bbvalue.shparse("cp foo`", self.d), self.d)
179
180# def test_rogue_dollarsign(self):
181# self.setValues({"D" : "/tmp"})
182# self.parseExpression("install -d ${D}$")
183# self.assertReferences(set(["D"]))
184# self.assertExecs(set(["install"]))
185
186
187class PythonReferenceTest(ReferenceTest):
188
189 def setUp(self):
190 self.d = bb.data.init()
191 if hasattr(bb.utils, "_context"):
192 self.context = bb.utils._context
193 else:
194 import __builtin__
195 self.context = __builtin__.__dict__
196
197 def parseExpression(self, exp):
198 parsedvar = self.d.expandWithRefs(exp, None)
199 parser = bb.codeparser.PythonParser("ParserTest", logger)
200 parser.parse_python(parsedvar.value)
201
202 self.references = parsedvar.references | parser.references
203 self.execs = parser.execs
204
205 @staticmethod
206 def indent(value):
207 """Python Snippets have to be indented, python values don't have to
208be. These unit tests are testing snippets."""
209 return " " + value
210
211 def test_getvar_reference(self):
212 self.parseExpression("bb.data.getVar('foo', d, True)")
213 self.assertReferences(set(["foo"]))
214 self.assertExecs(set())
215
216 def test_getvar_computed_reference(self):
217 self.parseExpression("bb.data.getVar('f' + 'o' + 'o', d, True)")
218 self.assertReferences(set())
219 self.assertExecs(set())
220
221 def test_getvar_exec_reference(self):
222 self.parseExpression("eval('bb.data.getVar(\"foo\", d, True)')")
223 self.assertReferences(set())
224 self.assertExecs(set(["eval"]))
225
226 def test_var_reference(self):
227 self.context["foo"] = lambda x: x
228 self.setEmptyVars(["FOO"])
229 self.parseExpression("foo('${FOO}')")
230 self.assertReferences(set(["FOO"]))
231 self.assertExecs(set(["foo"]))
232 del self.context["foo"]
233
234 def test_var_exec(self):
235 for etype in ("func", "task"):
236 self.d.setVar("do_something", "echo 'hi mom! ${FOO}'")
237 self.d.setVarFlag("do_something", etype, True)
238 self.parseExpression("bb.build.exec_func('do_something', d)")
239 self.assertReferences(set(["do_something"]))
240
241 def test_function_reference(self):
242 self.context["testfunc"] = lambda msg: bb.msg.note(1, None, msg)
243 self.d.setVar("FOO", "Hello, World!")
244 self.parseExpression("testfunc('${FOO}')")
245 self.assertReferences(set(["FOO"]))
246 self.assertExecs(set(["testfunc"]))
247 del self.context["testfunc"]
248
249 def test_qualified_function_reference(self):
250 self.parseExpression("time.time()")
251 self.assertExecs(set(["time.time"]))
252
253 def test_qualified_function_reference_2(self):
254 self.parseExpression("os.path.dirname('/foo/bar')")
255 self.assertExecs(set(["os.path.dirname"]))
256
257 def test_qualified_function_reference_nested(self):
258 self.parseExpression("time.strftime('%Y%m%d',time.gmtime())")
259 self.assertExecs(set(["time.strftime", "time.gmtime"]))
260
261 def test_function_reference_chained(self):
262 self.context["testget"] = lambda: "\tstrip me "
263 self.parseExpression("testget().strip()")
264 self.assertExecs(set(["testget"]))
265 del self.context["testget"]
266
267
268class DependencyReferenceTest(ReferenceTest):
269
270 pydata = """
271bb.data.getVar('somevar', d, True)
272def test(d):
273 foo = 'bar %s' % 'foo'
274def test2(d):
275 d.getVar(foo, True)
276 d.getVar('bar', False)
277 test2(d)
278
279def a():
280 \"\"\"some
281 stuff
282 \"\"\"
283 return "heh"
284
285test(d)
286
287bb.data.expand(bb.data.getVar("something", False, d), d)
288bb.data.expand("${inexpand} somethingelse", d)
289bb.data.getVar(a(), d, False)
290"""
291
292 def test_python(self):
293 self.d.setVar("FOO", self.pydata)
294 self.setEmptyVars(["inexpand", "a", "test2", "test"])
295 self.d.setVarFlags("FOO", {"func": True, "python": True})
296
297 deps, values = bb.data.build_dependencies("FOO", set(self.d.keys()), set(), set(), self.d)
298
299 self.assertEquals(deps, set(["somevar", "bar", "something", "inexpand", "test", "test2", "a"]))
300
301
302 shelldata = """
303foo () {
304bar
305}
306{
307echo baz
308$(heh)
309eval `moo`
310}
311a=b
312c=d
313(
314true && false
315test -f foo
316testval=something
317$testval
318) || aiee
319! inverted
320echo ${somevar}
321
322case foo in
323bar)
324echo bar
325;;
326baz)
327echo baz
328;;
329foo*)
330echo foo
331;;
332esac
333"""
334
335 def test_shell(self):
336 execs = ["bar", "echo", "heh", "moo", "true", "aiee"]
337 self.d.setVar("somevar", "heh")
338 self.d.setVar("inverted", "echo inverted...")
339 self.d.setVarFlag("inverted", "func", True)
340 self.d.setVar("FOO", self.shelldata)
341 self.d.setVarFlags("FOO", {"func": True})
342 self.setEmptyVars(execs)
343
344 deps, values = bb.data.build_dependencies("FOO", set(self.d.keys()), set(), set(), self.d)
345
346 self.assertEquals(deps, set(["somevar", "inverted"] + execs))
347
348
349 def test_vardeps(self):
350 self.d.setVar("oe_libinstall", "echo test")
351 self.d.setVar("FOO", "foo=oe_libinstall; eval $foo")
352 self.d.setVarFlag("FOO", "vardeps", "oe_libinstall")
353
354 deps, values = bb.data.build_dependencies("FOO", set(self.d.keys()), set(), set(), self.d)
355
356 self.assertEquals(deps, set(["oe_libinstall"]))
357
358 def test_vardeps_expand(self):
359 self.d.setVar("oe_libinstall", "echo test")
360 self.d.setVar("FOO", "foo=oe_libinstall; eval $foo")
361 self.d.setVarFlag("FOO", "vardeps", "${@'oe_libinstall'}")
362
363 deps, values = bb.data.build_dependencies("FOO", set(self.d.keys()), set(), set(), self.d)
364
365 self.assertEquals(deps, set(["oe_libinstall"]))
366
367 #Currently no wildcard support
368 #def test_vardeps_wildcards(self):
369 # self.d.setVar("oe_libinstall", "echo test")
370 # self.d.setVar("FOO", "foo=oe_libinstall; eval $foo")
371 # self.d.setVarFlag("FOO", "vardeps", "oe_*")
372 # self.assertEquals(deps, set(["oe_libinstall"]))
373
374
diff --git a/bitbake/lib/bb/tests/cow.py b/bitbake/lib/bb/tests/cow.py
new file mode 100644
index 0000000000..35c5841f32
--- /dev/null
+++ b/bitbake/lib/bb/tests/cow.py
@@ -0,0 +1,136 @@
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 Copy-on-Write (cow.py)
5#
6# Copyright 2006 Holger Freyther <freyther@handhelds.org>
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 os
24
25class COWTestCase(unittest.TestCase):
26 """
27 Test case for the COW module from mithro
28 """
29
30 def testGetSet(self):
31 """
32 Test and set
33 """
34 from bb.COW import COWDictBase
35 a = COWDictBase.copy()
36
37 self.assertEquals(False, a.has_key('a'))
38
39 a['a'] = 'a'
40 a['b'] = 'b'
41 self.assertEquals(True, a.has_key('a'))
42 self.assertEquals(True, a.has_key('b'))
43 self.assertEquals('a', a['a'] )
44 self.assertEquals('b', a['b'] )
45
46 def testCopyCopy(self):
47 """
48 Test the copy of copies
49 """
50
51 from bb.COW import COWDictBase
52
53 # create two COW dict 'instances'
54 b = COWDictBase.copy()
55 c = COWDictBase.copy()
56
57 # assign some keys to one instance, some keys to another
58 b['a'] = 10
59 b['c'] = 20
60 c['a'] = 30
61
62 # test separation of the two instances
63 self.assertEquals(False, c.has_key('c'))
64 self.assertEquals(30, c['a'])
65 self.assertEquals(10, b['a'])
66
67 # test copy
68 b_2 = b.copy()
69 c_2 = c.copy()
70
71 self.assertEquals(False, c_2.has_key('c'))
72 self.assertEquals(10, b_2['a'])
73
74 b_2['d'] = 40
75 self.assertEquals(False, c_2.has_key('d'))
76 self.assertEquals(True, b_2.has_key('d'))
77 self.assertEquals(40, b_2['d'])
78 self.assertEquals(False, b.has_key('d'))
79 self.assertEquals(False, c.has_key('d'))
80
81 c_2['d'] = 30
82 self.assertEquals(True, c_2.has_key('d'))
83 self.assertEquals(True, b_2.has_key('d'))
84 self.assertEquals(30, c_2['d'])
85 self.assertEquals(40, b_2['d'])
86 self.assertEquals(False, b.has_key('d'))
87 self.assertEquals(False, c.has_key('d'))
88
89 # test copy of the copy
90 c_3 = c_2.copy()
91 b_3 = b_2.copy()
92 b_3_2 = b_2.copy()
93
94 c_3['e'] = 4711
95 self.assertEquals(4711, c_3['e'])
96 self.assertEquals(False, c_2.has_key('e'))
97 self.assertEquals(False, b_3.has_key('e'))
98 self.assertEquals(False, b_3_2.has_key('e'))
99 self.assertEquals(False, b_2.has_key('e'))
100
101 b_3['e'] = 'viel'
102 self.assertEquals('viel', b_3['e'])
103 self.assertEquals(4711, c_3['e'])
104 self.assertEquals(False, c_2.has_key('e'))
105 self.assertEquals(True, b_3.has_key('e'))
106 self.assertEquals(False, b_3_2.has_key('e'))
107 self.assertEquals(False, b_2.has_key('e'))
108
109 def testCow(self):
110 from bb.COW import COWDictBase
111 c = COWDictBase.copy()
112 c['123'] = 1027
113 c['other'] = 4711
114 c['d'] = { 'abc' : 10, 'bcd' : 20 }
115
116 copy = c.copy()
117
118 self.assertEquals(1027, c['123'])
119 self.assertEquals(4711, c['other'])
120 self.assertEquals({'abc':10, 'bcd':20}, c['d'])
121 self.assertEquals(1027, copy['123'])
122 self.assertEquals(4711, copy['other'])
123 self.assertEquals({'abc':10, 'bcd':20}, copy['d'])
124
125 # cow it now
126 copy['123'] = 1028
127 copy['other'] = 4712
128 copy['d']['abc'] = 20
129
130
131 self.assertEquals(1027, c['123'])
132 self.assertEquals(4711, c['other'])
133 self.assertEquals({'abc':10, 'bcd':20}, c['d'])
134 self.assertEquals(1028, copy['123'])
135 self.assertEquals(4712, copy['other'])
136 self.assertEquals({'abc':20, 'bcd':20}, copy['d'])
diff --git a/bitbake/lib/bb/tests/data.py b/bitbake/lib/bb/tests/data.py
new file mode 100644
index 0000000000..f281a353f4
--- /dev/null
+++ b/bitbake/lib/bb/tests/data.py
@@ -0,0 +1,254 @@
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 the Data Store (data.py/data_smart.py)
5#
6# Copyright (C) 2010 Chris Larson
7# Copyright (C) 2012 Richard Purdie
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21#
22
23import unittest
24import bb
25import bb.data
26
27class DataExpansions(unittest.TestCase):
28 def setUp(self):
29 self.d = bb.data.init()
30 self.d["foo"] = "value_of_foo"
31 self.d["bar"] = "value_of_bar"
32 self.d["value_of_foo"] = "value_of_'value_of_foo'"
33
34 def test_one_var(self):
35 val = self.d.expand("${foo}")
36 self.assertEqual(str(val), "value_of_foo")
37
38 def test_indirect_one_var(self):
39 val = self.d.expand("${${foo}}")
40 self.assertEqual(str(val), "value_of_'value_of_foo'")
41
42 def test_indirect_and_another(self):
43 val = self.d.expand("${${foo}} ${bar}")
44 self.assertEqual(str(val), "value_of_'value_of_foo' value_of_bar")
45
46 def test_python_snippet(self):
47 val = self.d.expand("${@5*12}")
48 self.assertEqual(str(val), "60")
49
50 def test_expand_in_python_snippet(self):
51 val = self.d.expand("${@'boo ' + '${foo}'}")
52 self.assertEqual(str(val), "boo value_of_foo")
53
54 def test_python_snippet_getvar(self):
55 val = self.d.expand("${@d.getVar('foo', True) + ' ${bar}'}")
56 self.assertEqual(str(val), "value_of_foo value_of_bar")
57
58 def test_python_snippet_syntax_error(self):
59 self.d.setVar("FOO", "${@foo = 5}")
60 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
61
62 def test_python_snippet_runtime_error(self):
63 self.d.setVar("FOO", "${@int('test')}")
64 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
65
66 def test_python_snippet_error_path(self):
67 self.d.setVar("FOO", "foo value ${BAR}")
68 self.d.setVar("BAR", "bar value ${@int('test')}")
69 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
70
71 def test_value_containing_value(self):
72 val = self.d.expand("${@d.getVar('foo', True) + ' ${bar}'}")
73 self.assertEqual(str(val), "value_of_foo value_of_bar")
74
75 def test_reference_undefined_var(self):
76 val = self.d.expand("${undefinedvar} meh")
77 self.assertEqual(str(val), "${undefinedvar} meh")
78
79 def test_double_reference(self):
80 self.d.setVar("BAR", "bar value")
81 self.d.setVar("FOO", "${BAR} foo ${BAR}")
82 val = self.d.getVar("FOO", True)
83 self.assertEqual(str(val), "bar value foo bar value")
84
85 def test_direct_recursion(self):
86 self.d.setVar("FOO", "${FOO}")
87 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
88
89 def test_indirect_recursion(self):
90 self.d.setVar("FOO", "${BAR}")
91 self.d.setVar("BAR", "${BAZ}")
92 self.d.setVar("BAZ", "${FOO}")
93 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
94
95 def test_recursion_exception(self):
96 self.d.setVar("FOO", "${BAR}")
97 self.d.setVar("BAR", "${${@'FOO'}}")
98 self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True)
99
100 def test_incomplete_varexp_single_quotes(self):
101 self.d.setVar("FOO", "sed -i -e 's:IP{:I${:g' $pc")
102 val = self.d.getVar("FOO", True)
103 self.assertEqual(str(val), "sed -i -e 's:IP{:I${:g' $pc")
104
105 def test_nonstring(self):
106 self.d.setVar("TEST", 5)
107 val = self.d.getVar("TEST", True)
108 self.assertEqual(str(val), "5")
109
110 def test_rename(self):
111 self.d.renameVar("foo", "newfoo")
112 self.assertEqual(self.d.getVar("newfoo"), "value_of_foo")
113 self.assertEqual(self.d.getVar("foo"), None)
114
115 def test_deletion(self):
116 self.d.delVar("foo")
117 self.assertEqual(self.d.getVar("foo"), None)
118
119 def test_keys(self):
120 keys = self.d.keys()
121 self.assertEqual(keys, ['value_of_foo', 'foo', 'bar'])
122
123class TestNestedExpansions(unittest.TestCase):
124 def setUp(self):
125 self.d = bb.data.init()
126 self.d["foo"] = "foo"
127 self.d["bar"] = "bar"
128 self.d["value_of_foobar"] = "187"
129
130 def test_refs(self):
131 val = self.d.expand("${value_of_${foo}${bar}}")
132 self.assertEqual(str(val), "187")
133
134 #def test_python_refs(self):
135 # val = self.d.expand("${@${@3}**2 + ${@4}**2}")
136 # self.assertEqual(str(val), "25")
137
138 def test_ref_in_python_ref(self):
139 val = self.d.expand("${@'${foo}' + 'bar'}")
140 self.assertEqual(str(val), "foobar")
141
142 def test_python_ref_in_ref(self):
143 val = self.d.expand("${${@'f'+'o'+'o'}}")
144 self.assertEqual(str(val), "foo")
145
146 def test_deep_nesting(self):
147 depth = 100
148 val = self.d.expand("${" * depth + "foo" + "}" * depth)
149 self.assertEqual(str(val), "foo")
150
151 #def test_deep_python_nesting(self):
152 # depth = 50
153 # val = self.d.expand("${@" * depth + "1" + "+1}" * depth)
154 # self.assertEqual(str(val), str(depth + 1))
155
156 def test_mixed(self):
157 val = self.d.expand("${value_of_${@('${foo}'+'bar')[0:3]}${${@'BAR'.lower()}}}")
158 self.assertEqual(str(val), "187")
159
160 def test_runtime(self):
161 val = self.d.expand("${${@'value_of' + '_f'+'o'+'o'+'b'+'a'+'r'}}")
162 self.assertEqual(str(val), "187")
163
164class TestMemoize(unittest.TestCase):
165 def test_memoized(self):
166 d = bb.data.init()
167 d.setVar("FOO", "bar")
168 self.assertTrue(d.getVar("FOO") is d.getVar("FOO"))
169
170 def test_not_memoized(self):
171 d1 = bb.data.init()
172 d2 = bb.data.init()
173 d1.setVar("FOO", "bar")
174 d2.setVar("FOO", "bar2")
175 self.assertTrue(d1.getVar("FOO") is not d2.getVar("FOO"))
176
177 def test_changed_after_memoized(self):
178 d = bb.data.init()
179 d.setVar("foo", "value of foo")
180 self.assertEqual(str(d.getVar("foo")), "value of foo")
181 d.setVar("foo", "second value of foo")
182 self.assertEqual(str(d.getVar("foo")), "second value of foo")
183
184 def test_same_value(self):
185 d = bb.data.init()
186 d.setVar("foo", "value of")
187 d.setVar("bar", "value of")
188 self.assertEqual(d.getVar("foo"),
189 d.getVar("bar"))
190
191class TestConcat(unittest.TestCase):
192 def setUp(self):
193 self.d = bb.data.init()
194 self.d.setVar("FOO", "foo")
195 self.d.setVar("VAL", "val")
196 self.d.setVar("BAR", "bar")
197
198 def test_prepend(self):
199 self.d.setVar("TEST", "${VAL}")
200 self.d.prependVar("TEST", "${FOO}:")
201 self.assertEqual(self.d.getVar("TEST", True), "foo:val")
202
203 def test_append(self):
204 self.d.setVar("TEST", "${VAL}")
205 self.d.appendVar("TEST", ":${BAR}")
206 self.assertEqual(self.d.getVar("TEST", True), "val:bar")
207
208 def test_multiple_append(self):
209 self.d.setVar("TEST", "${VAL}")
210 self.d.prependVar("TEST", "${FOO}:")
211 self.d.appendVar("TEST", ":val2")
212 self.d.appendVar("TEST", ":${BAR}")
213 self.assertEqual(self.d.getVar("TEST", True), "foo:val:val2:bar")
214
215class TestOverrides(unittest.TestCase):
216 def setUp(self):
217 self.d = bb.data.init()
218 self.d.setVar("OVERRIDES", "foo:bar:local")
219 self.d.setVar("TEST", "testvalue")
220
221 def test_no_override(self):
222 bb.data.update_data(self.d)
223 self.assertEqual(self.d.getVar("TEST", True), "testvalue")
224
225 def test_one_override(self):
226 self.d.setVar("TEST_bar", "testvalue2")
227 bb.data.update_data(self.d)
228 self.assertEqual(self.d.getVar("TEST", True), "testvalue2")
229
230 def test_multiple_override(self):
231 self.d.setVar("TEST_bar", "testvalue2")
232 self.d.setVar("TEST_local", "testvalue3")
233 self.d.setVar("TEST_foo", "testvalue4")
234 bb.data.update_data(self.d)
235 self.assertEqual(self.d.getVar("TEST", True), "testvalue3")
236
237
238class TestFlags(unittest.TestCase):
239 def setUp(self):
240 self.d = bb.data.init()
241 self.d.setVar("foo", "value of foo")
242 self.d.setVarFlag("foo", "flag1", "value of flag1")
243 self.d.setVarFlag("foo", "flag2", "value of flag2")
244
245 def test_setflag(self):
246 self.assertEqual(self.d.getVarFlag("foo", "flag1"), "value of flag1")
247 self.assertEqual(self.d.getVarFlag("foo", "flag2"), "value of flag2")
248
249 def test_delflag(self):
250 self.d.delVarFlag("foo", "flag2")
251 self.assertEqual(self.d.getVarFlag("foo", "flag1"), "value of flag1")
252 self.assertEqual(self.d.getVarFlag("foo", "flag2"), None)
253
254
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
new file mode 100644
index 0000000000..4bcff543fc
--- /dev/null
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -0,0 +1,424 @@
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 the Fetcher (fetch2/)
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 tempfile
24import subprocess
25import os
26from bb.fetch2 import URI
27import bb
28
29class URITest(unittest.TestCase):
30 test_uris = {
31 "http://www.google.com/index.html" : {
32 'uri': 'http://www.google.com/index.html',
33 'scheme': 'http',
34 'hostname': 'www.google.com',
35 'port': None,
36 'hostport': 'www.google.com',
37 'path': '/index.html',
38 'userinfo': '',
39 'username': '',
40 'password': '',
41 'params': {},
42 'relative': False
43 },
44 "http://www.google.com/index.html;param1=value1" : {
45 'uri': 'http://www.google.com/index.html;param1=value1',
46 'scheme': 'http',
47 'hostname': 'www.google.com',
48 'port': None,
49 'hostport': 'www.google.com',
50 'path': '/index.html',
51 'userinfo': '',
52 'username': '',
53 'password': '',
54 'params': {
55 'param1': 'value1'
56 },
57 'relative': False
58 },
59 "http://www.example.com:8080/index.html" : {
60 'uri': 'http://www.example.com:8080/index.html',
61 'scheme': 'http',
62 'hostname': 'www.example.com',
63 'port': 8080,
64 'hostport': 'www.example.com:8080',
65 'path': '/index.html',
66 'userinfo': '',
67 'username': '',
68 'password': '',
69 'params': {},
70 'relative': False
71 },
72 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : {
73 'uri': 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg',
74 'scheme': 'cvs',
75 'hostname': 'cvs.handhelds.org',
76 'port': None,
77 'hostport': 'cvs.handhelds.org',
78 'path': '/cvs',
79 'userinfo': 'anoncvs',
80 'username': 'anoncvs',
81 'password': '',
82 'params': {
83 'module': 'familiar/dist/ipkg'
84 },
85 'relative': False
86 },
87 "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg": {
88 'uri': 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg',
89 'scheme': 'cvs',
90 'hostname': 'cvs.handhelds.org',
91 'port': None,
92 'hostport': 'cvs.handhelds.org',
93 'path': '/cvs',
94 'userinfo': 'anoncvs:anonymous',
95 'username': 'anoncvs',
96 'password': 'anonymous',
97 'params': {
98 'tag': 'V0-99-81',
99 'module': 'familiar/dist/ipkg'
100 },
101 'relative': False
102 },
103 "file://example.diff": { # NOTE: Not RFC compliant!
104 'uri': 'file:example.diff',
105 'scheme': 'file',
106 'hostname': '',
107 'port': None,
108 'hostport': '',
109 'path': 'example.diff',
110 'userinfo': '',
111 'username': '',
112 'password': '',
113 'params': {},
114 'relative': True
115 },
116 "file:example.diff": { # NOTE: RFC compliant version of the former
117 'uri': 'file:example.diff',
118 'scheme': 'file',
119 'hostname': '',
120 'port': None,
121 'hostport': '',
122 'path': 'example.diff',
123 'userinfo': '',
124 'userinfo': '',
125 'username': '',
126 'password': '',
127 'params': {},
128 'relative': True
129 },
130 "file:///tmp/example.diff": {
131 'uri': 'file:///tmp/example.diff',
132 'scheme': 'file',
133 'hostname': '',
134 'port': None,
135 'hostport': '',
136 'path': '/tmp/example.diff',
137 'userinfo': '',
138 'userinfo': '',
139 'username': '',
140 'password': '',
141 'params': {},
142 'relative': False
143 },
144 "git:///path/example.git": {
145 'uri': 'git:///path/example.git',
146 'scheme': 'git',
147 'hostname': '',
148 'port': None,
149 'hostport': '',
150 'path': '/path/example.git',
151 'userinfo': '',
152 'userinfo': '',
153 'username': '',
154 'password': '',
155 'params': {},
156 'relative': False
157 },
158 "git:path/example.git": {
159 'uri': 'git:path/example.git',
160 'scheme': 'git',
161 'hostname': '',
162 'port': None,
163 'hostport': '',
164 'path': 'path/example.git',
165 'userinfo': '',
166 'userinfo': '',
167 'username': '',
168 'password': '',
169 'params': {},
170 'relative': True
171 },
172 "git://example.net/path/example.git": {
173 'uri': 'git://example.net/path/example.git',
174 'scheme': 'git',
175 'hostname': 'example.net',
176 'port': None,
177 'hostport': 'example.net',
178 'path': '/path/example.git',
179 'userinfo': '',
180 'userinfo': '',
181 'username': '',
182 'password': '',
183 'params': {},
184 'relative': False
185 }
186 }
187
188 def test_uri(self):
189 for test_uri, ref in self.test_uris.items():
190 uri = URI(test_uri)
191
192 self.assertEqual(str(uri), ref['uri'])
193
194 # expected attributes
195 self.assertEqual(uri.scheme, ref['scheme'])
196
197 self.assertEqual(uri.userinfo, ref['userinfo'])
198 self.assertEqual(uri.username, ref['username'])
199 self.assertEqual(uri.password, ref['password'])
200
201 self.assertEqual(uri.hostname, ref['hostname'])
202 self.assertEqual(uri.port, ref['port'])
203 self.assertEqual(uri.hostport, ref['hostport'])
204
205 self.assertEqual(uri.path, ref['path'])
206 self.assertEqual(uri.params, ref['params'])
207
208 self.assertEqual(uri.relative, ref['relative'])
209
210 def test_dict(self):
211 for test in self.test_uris.values():
212 uri = URI()
213
214 self.assertEqual(uri.scheme, '')
215 self.assertEqual(uri.userinfo, '')
216 self.assertEqual(uri.username, '')
217 self.assertEqual(uri.password, '')
218 self.assertEqual(uri.hostname, '')
219 self.assertEqual(uri.port, None)
220 self.assertEqual(uri.path, '')
221 self.assertEqual(uri.params, {})
222
223
224 uri.scheme = test['scheme']
225 self.assertEqual(uri.scheme, test['scheme'])
226
227 uri.userinfo = test['userinfo']
228 self.assertEqual(uri.userinfo, test['userinfo'])
229 self.assertEqual(uri.username, test['username'])
230 self.assertEqual(uri.password, test['password'])
231
232 uri.hostname = test['hostname']
233 self.assertEqual(uri.hostname, test['hostname'])
234 self.assertEqual(uri.hostport, test['hostname'])
235
236 uri.port = test['port']
237 self.assertEqual(uri.port, test['port'])
238 self.assertEqual(uri.hostport, test['hostport'])
239
240 uri.path = test['path']
241 self.assertEqual(uri.path, test['path'])
242
243 uri.params = test['params']
244 self.assertEqual(uri.params, test['params'])
245
246 self.assertEqual(str(uri)+str(uri.relative), str(test['uri'])+str(test['relative']))
247
248 self.assertEqual(str(uri), test['uri'])
249
250 uri.params = {}
251 self.assertEqual(uri.params, {})
252 self.assertEqual(str(uri), (str(uri).split(";"))[0])
253
254class FetcherTest(unittest.TestCase):
255
256 def setUp(self):
257 self.d = bb.data.init()
258 self.tempdir = tempfile.mkdtemp()
259 self.dldir = os.path.join(self.tempdir, "download")
260 os.mkdir(self.dldir)
261 self.d.setVar("DL_DIR", self.dldir)
262 self.unpackdir = os.path.join(self.tempdir, "unpacked")
263 os.mkdir(self.unpackdir)
264 persistdir = os.path.join(self.tempdir, "persistdata")
265 self.d.setVar("PERSISTENT_DIR", persistdir)
266
267 def tearDown(self):
268 bb.utils.prunedir(self.tempdir)
269
270class MirrorUriTest(FetcherTest):
271
272 replaceuris = {
273 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/")
274 : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz",
275 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
276 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
277 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http")
278 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
279 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http")
280 : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
281 ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake")
282 : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890",
283 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache")
284 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
285 ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/")
286 : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
287 ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/somedir3")
288 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
289 ("http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz")
290 : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz",
291 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://www.apache.org/dist", "http://archive.apache.org/dist")
292 : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2",
293 ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/")
294 : "file:///somepath/downloads/subversion-1.7.1.tar.bz2",
295 ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
296 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
297 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http")
298 : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
299 ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http")
300 : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http",
301
302 #Renaming files doesn't work
303 #("http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere2.org/somedir3/somefile_2.3.4.tar.gz") : "http://somewhere2.org/somedir3/somefile_2.3.4.tar.gz"
304 #("file://sstate-xyz.tgz", "file://.*/.*", "file:///somewhere/1234/sstate-cache") : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz",
305 }
306
307 mirrorvar = "http://.*/.* file:///somepath/downloads/ \n" \
308 "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n" \
309 "https://.*/.* file:///someotherpath/downloads/ \n" \
310 "http://.*/.* file:///someotherpath/downloads/ \n"
311
312 def test_urireplace(self):
313 for k, v in self.replaceuris.items():
314 ud = bb.fetch.FetchData(k[0], self.d)
315 ud.setup_localpath(self.d)
316 mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2]))
317 newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d)
318 self.assertEqual([v], newuris)
319
320 def test_urilist1(self):
321 fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
322 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
323 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
324 self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', 'file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
325
326 def test_urilist2(self):
327 # Catch https:// -> files:// bug
328 fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d)
329 mirrors = bb.fetch2.mirror_from_string(self.mirrorvar)
330 uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d)
331 self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz'])
332
333class FetcherNetworkTest(FetcherTest):
334
335 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
336 print("Unset BB_SKIP_NETTESTS to run network tests")
337 else:
338 def test_fetch(self):
339 fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d)
340 fetcher.download()
341 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
342 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892)
343 self.d.setVar("BB_NO_NETWORK", "1")
344 fetcher = bb.fetch.Fetch(["http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d)
345 fetcher.download()
346 fetcher.unpack(self.unpackdir)
347 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9)
348 self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9)
349
350 def test_fetch_mirror(self):
351 self.d.setVar("MIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake")
352 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
353 fetcher.download()
354 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
355
356 def test_fetch_premirror(self):
357 self.d.setVar("PREMIRRORS", "http://.*/.* http://downloads.yoctoproject.org/releases/bitbake")
358 fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
359 fetcher.download()
360 self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749)
361
362 def gitfetcher(self, url1, url2):
363 def checkrevision(self, fetcher):
364 fetcher.unpack(self.unpackdir)
365 revision = bb.process.run("git rev-parse HEAD", shell=True, cwd=self.unpackdir + "/git")[0].strip()
366 self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
367
368 self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1")
369 self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5")
370 fetcher = bb.fetch.Fetch([url1], self.d)
371 fetcher.download()
372 checkrevision(self, fetcher)
373 # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works
374 bb.utils.prunedir(self.dldir + "/git2/")
375 bb.utils.prunedir(self.unpackdir)
376 self.d.setVar("BB_NO_NETWORK", "1")
377 fetcher = bb.fetch.Fetch([url2], self.d)
378 fetcher.download()
379 checkrevision(self, fetcher)
380
381 def test_gitfetch(self):
382 url1 = url2 = "git://git.openembedded.org/bitbake"
383 self.gitfetcher(url1, url2)
384
385 def test_gitfetch_premirror(self):
386 url1 = "git://git.openembedded.org/bitbake"
387 url2 = "git://someserver.org/bitbake"
388 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
389 self.gitfetcher(url1, url2)
390
391 def test_gitfetch_premirror2(self):
392 url1 = url2 = "git://someserver.org/bitbake"
393 self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
394 self.gitfetcher(url1, url2)
395
396 def test_gitfetch_premirror3(self):
397 realurl = "git://git.openembedded.org/bitbake"
398 dummyurl = "git://someserver.org/bitbake"
399 self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git")
400 os.chdir(self.tempdir)
401 bb.process.run("git clone %s %s 2> /dev/null" % (realurl, self.sourcedir), shell=True)
402 self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file \n" % (dummyurl, self.sourcedir))
403 self.gitfetcher(dummyurl, dummyurl)
404
405class URLHandle(unittest.TestCase):
406
407 datatable = {
408 "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}),
409 "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}),
410 "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', {'tag': 'V0-99-81', 'module': 'familiar/dist/ipkg'})
411 }
412
413 def test_decodeurl(self):
414 for k, v in self.datatable.items():
415 result = bb.fetch.decodeurl(k)
416 self.assertEqual(result, v)
417
418 def test_encodeurl(self):
419 for k, v in self.datatable.items():
420 result = bb.fetch.encodeurl(v)
421 self.assertEqual(result, k)
422
423
424
diff --git a/bitbake/lib/bb/tests/utils.py b/bitbake/lib/bb/tests/utils.py
new file mode 100644
index 0000000000..7c50b1d786
--- /dev/null
+++ b/bitbake/lib/bb/tests/utils.py
@@ -0,0 +1,53 @@
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
24
25class VerCmpString(unittest.TestCase):
26
27 def test_vercmpstring(self):
28 result = bb.utils.vercmp_string('1', '2')
29 self.assertTrue(result < 0)
30 result = bb.utils.vercmp_string('2', '1')
31 self.assertTrue(result > 0)
32 result = bb.utils.vercmp_string('1', '1.0')
33 self.assertTrue(result < 0)
34 result = bb.utils.vercmp_string('1', '1.1')
35 self.assertTrue(result < 0)
36 result = bb.utils.vercmp_string('1.1', '1_p2')
37 self.assertTrue(result < 0)
38
39 def test_explode_dep_versions(self):
40 correctresult = {"foo" : ["= 1.10"]}
41 result = bb.utils.explode_dep_versions2("foo (= 1.10)")
42 self.assertEqual(result, correctresult)
43 result = bb.utils.explode_dep_versions2("foo (=1.10)")
44 self.assertEqual(result, correctresult)
45 result = bb.utils.explode_dep_versions2("foo ( = 1.10)")
46 self.assertEqual(result, correctresult)
47 result = bb.utils.explode_dep_versions2("foo ( =1.10)")
48 self.assertEqual(result, correctresult)
49 result = bb.utils.explode_dep_versions2("foo ( = 1.10 )")
50 self.assertEqual(result, correctresult)
51 result = bb.utils.explode_dep_versions2("foo ( =1.10 )")
52 self.assertEqual(result, correctresult)
53