diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-05-04 16:18:55 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-05-04 16:58:35 +0100 |
| commit | 12ebec4c940f37b17bc565299347dddf44cd1b90 (patch) | |
| tree | 6c75ca9ddda98353378e2b77c95738917a96e39c /bitbake/lib/bb/tests/data.py | |
| parent | 2ee0d3f05405602ab0ec73aef150e9643fff04c2 (diff) | |
| download | poky-12ebec4c940f37b17bc565299347dddf44cd1b90.tar.gz | |
bitbake: Add start of bitbake regression/self testing
This adds some basic unit testing for the codeparser and data store code. Many of
the actual test cases were taken from work by Chris Larson's OE-Signatures work but with
changes to adapt to the current bitbake APIs we need to test.
I also imported CoW tests written by Holger Freyther from the original bitbake-test
codebase: http://svn.berlios.de/wsvn/bitbake/trunk/bitbake-tests/tests/ and
some tests from the doctests that were removed in commit:
http://git.openembedded.org/bitbake/commit?id=3a11c2807972bbbddffde2fa67fc380d159da467
(Bitbake rev: ae4a95780e3e08cf73c854efa8cd93379e00c4e5)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/tests/data.py')
| -rw-r--r-- | bitbake/lib/bb/tests/data.py | 252 |
1 files changed, 252 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/data.py b/bitbake/lib/bb/tests/data.py new file mode 100644 index 0000000000..b2ab8eeeb8 --- /dev/null +++ b/bitbake/lib/bb/tests/data.py | |||
| @@ -0,0 +1,252 @@ | |||
| 1 | # | ||
| 2 | # BitBake Tests for the Data Store (data.py/data_smart.py) | ||
| 3 | # | ||
| 4 | # Copyright (C) 2010 Chris Larson | ||
| 5 | # Copyright (C) 2012 Richard Purdie | ||
| 6 | # | ||
| 7 | # This program is free software; you can redistribute it and/or modify | ||
| 8 | # it under the terms of the GNU General Public License version 2 as | ||
| 9 | # published by the Free Software Foundation. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License along | ||
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | # | ||
| 20 | |||
| 21 | import unittest | ||
| 22 | import bb | ||
| 23 | import bb.data | ||
| 24 | |||
| 25 | class DataExpansions(unittest.TestCase): | ||
| 26 | def setUp(self): | ||
| 27 | self.d = bb.data.init() | ||
| 28 | self.d["foo"] = "value of foo" | ||
| 29 | self.d["bar"] = "value of bar" | ||
| 30 | self.d["value of foo"] = "value of 'value of foo'" | ||
| 31 | |||
| 32 | def test_one_var(self): | ||
| 33 | val = self.d.expand("${foo}") | ||
| 34 | self.assertEqual(str(val), "value of foo") | ||
| 35 | |||
| 36 | def test_indirect_one_var(self): | ||
| 37 | val = self.d.expand("${${foo}}") | ||
| 38 | self.assertEqual(str(val), "value of 'value of foo'") | ||
| 39 | |||
| 40 | def test_indirect_and_another(self): | ||
| 41 | val = self.d.expand("${${foo}} ${bar}") | ||
| 42 | self.assertEqual(str(val), "value of 'value of foo' value of bar") | ||
| 43 | |||
| 44 | def test_python_snippet(self): | ||
| 45 | val = self.d.expand("${@5*12}") | ||
| 46 | self.assertEqual(str(val), "60") | ||
| 47 | |||
| 48 | def test_expand_in_python_snippet(self): | ||
| 49 | val = self.d.expand("${@'boo ' + '${foo}'}") | ||
| 50 | self.assertEqual(str(val), "boo value of foo") | ||
| 51 | |||
| 52 | def test_python_snippet_getvar(self): | ||
| 53 | val = self.d.expand("${@d.getVar('foo', True) + ' ${bar}'}") | ||
| 54 | self.assertEqual(str(val), "value of foo value of bar") | ||
| 55 | |||
| 56 | def test_python_snippet_syntax_error(self): | ||
| 57 | self.d.setVar("FOO", "${@foo = 5}") | ||
| 58 | self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True) | ||
| 59 | |||
| 60 | def test_python_snippet_runtime_error(self): | ||
| 61 | self.d.setVar("FOO", "${@int('test')}") | ||
| 62 | self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True) | ||
| 63 | |||
| 64 | def test_python_snippet_error_path(self): | ||
| 65 | self.d.setVar("FOO", "foo value ${BAR}") | ||
| 66 | self.d.setVar("BAR", "bar value ${@int('test')}") | ||
| 67 | self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True) | ||
| 68 | |||
| 69 | def test_value_containing_value(self): | ||
| 70 | val = self.d.expand("${@d.getVar('foo', True) + ' ${bar}'}") | ||
| 71 | self.assertEqual(str(val), "value of foo value of bar") | ||
| 72 | |||
| 73 | def test_reference_undefined_var(self): | ||
| 74 | val = self.d.expand("${undefinedvar} meh") | ||
| 75 | self.assertEqual(str(val), "${undefinedvar} meh") | ||
| 76 | |||
| 77 | def test_double_reference(self): | ||
| 78 | self.d.setVar("BAR", "bar value") | ||
| 79 | self.d.setVar("FOO", "${BAR} foo ${BAR}") | ||
| 80 | val = self.d.getVar("FOO", True) | ||
| 81 | self.assertEqual(str(val), "bar value foo bar value") | ||
| 82 | |||
| 83 | def test_direct_recursion(self): | ||
| 84 | self.d.setVar("FOO", "${FOO}") | ||
| 85 | self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True) | ||
| 86 | |||
| 87 | def test_indirect_recursion(self): | ||
| 88 | self.d.setVar("FOO", "${BAR}") | ||
| 89 | self.d.setVar("BAR", "${BAZ}") | ||
| 90 | self.d.setVar("BAZ", "${FOO}") | ||
| 91 | self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True) | ||
| 92 | |||
| 93 | def test_recursion_exception(self): | ||
| 94 | self.d.setVar("FOO", "${BAR}") | ||
| 95 | self.d.setVar("BAR", "${${@'FOO'}}") | ||
| 96 | self.assertRaises(bb.data_smart.ExpansionError, self.d.getVar, "FOO", True) | ||
| 97 | |||
| 98 | def test_incomplete_varexp_single_quotes(self): | ||
| 99 | self.d.setVar("FOO", "sed -i -e 's:IP{:I${:g' $pc") | ||
| 100 | val = self.d.getVar("FOO", True) | ||
| 101 | self.assertEqual(str(val), "sed -i -e 's:IP{:I${:g' $pc") | ||
| 102 | |||
| 103 | def test_nonstring(self): | ||
| 104 | self.d.setVar("TEST", 5) | ||
| 105 | val = self.d.getVar("TEST", True) | ||
| 106 | self.assertEqual(str(val), "5") | ||
| 107 | |||
| 108 | def test_rename(self): | ||
| 109 | self.d.renameVar("foo", "newfoo") | ||
| 110 | self.assertEqual(self.d.getVar("newfoo"), "value of foo") | ||
| 111 | self.assertEqual(self.d.getVar("foo"), None) | ||
| 112 | |||
| 113 | def test_deletion(self): | ||
| 114 | self.d.delVar("foo") | ||
| 115 | self.assertEqual(self.d.getVar("foo"), None) | ||
| 116 | |||
| 117 | def test_keys(self): | ||
| 118 | keys = self.d.keys() | ||
| 119 | self.assertEqual(keys, ['value of foo', 'foo', 'bar']) | ||
| 120 | |||
| 121 | class TestNestedExpansions(unittest.TestCase): | ||
| 122 | def setUp(self): | ||
| 123 | self.d = bb.data.init() | ||
| 124 | self.d["foo"] = "foo" | ||
| 125 | self.d["bar"] = "bar" | ||
| 126 | self.d["value of foobar"] = "187" | ||
| 127 | |||
| 128 | def test_refs(self): | ||
| 129 | val = self.d.expand("${value of ${foo}${bar}}") | ||
| 130 | self.assertEqual(str(val), "187") | ||
| 131 | |||
| 132 | #def test_python_refs(self): | ||
| 133 | # val = self.d.expand("${@${@3}**2 + ${@4}**2}") | ||
| 134 | # self.assertEqual(str(val), "25") | ||
| 135 | |||
| 136 | def test_ref_in_python_ref(self): | ||
| 137 | val = self.d.expand("${@'${foo}' + 'bar'}") | ||
| 138 | self.assertEqual(str(val), "foobar") | ||
| 139 | |||
| 140 | def test_python_ref_in_ref(self): | ||
| 141 | val = self.d.expand("${${@'f'+'o'+'o'}}") | ||
| 142 | self.assertEqual(str(val), "foo") | ||
| 143 | |||
| 144 | def test_deep_nesting(self): | ||
| 145 | depth = 100 | ||
| 146 | val = self.d.expand("${" * depth + "foo" + "}" * depth) | ||
| 147 | self.assertEqual(str(val), "foo") | ||
| 148 | |||
| 149 | #def test_deep_python_nesting(self): | ||
| 150 | # depth = 50 | ||
| 151 | # val = self.d.expand("${@" * depth + "1" + "+1}" * depth) | ||
| 152 | # self.assertEqual(str(val), str(depth + 1)) | ||
| 153 | |||
| 154 | def test_mixed(self): | ||
| 155 | val = self.d.expand("${value of ${@('${foo}'+'bar')[0:3]}${${@'BAR'.lower()}}}") | ||
| 156 | self.assertEqual(str(val), "187") | ||
| 157 | |||
| 158 | def test_runtime(self): | ||
| 159 | val = self.d.expand("${${@'value of' + ' f'+'o'+'o'+'b'+'a'+'r'}}") | ||
| 160 | self.assertEqual(str(val), "187") | ||
| 161 | |||
| 162 | class TestMemoize(unittest.TestCase): | ||
| 163 | def test_memoized(self): | ||
| 164 | d = bb.data.init() | ||
| 165 | d.setVar("FOO", "bar") | ||
| 166 | self.assertTrue(d.getVar("FOO") is d.getVar("FOO")) | ||
| 167 | |||
| 168 | def test_not_memoized(self): | ||
| 169 | d1 = bb.data.init() | ||
| 170 | d2 = bb.data.init() | ||
| 171 | d1.setVar("FOO", "bar") | ||
| 172 | d2.setVar("FOO", "bar2") | ||
| 173 | self.assertTrue(d1.getVar("FOO") is not d2.getVar("FOO")) | ||
| 174 | |||
| 175 | def test_changed_after_memoized(self): | ||
| 176 | d = bb.data.init() | ||
| 177 | d.setVar("foo", "value of foo") | ||
| 178 | self.assertEqual(str(d.getVar("foo")), "value of foo") | ||
| 179 | d.setVar("foo", "second value of foo") | ||
| 180 | self.assertEqual(str(d.getVar("foo")), "second value of foo") | ||
| 181 | |||
| 182 | def test_same_value(self): | ||
| 183 | d = bb.data.init() | ||
| 184 | d.setVar("foo", "value of") | ||
| 185 | d.setVar("bar", "value of") | ||
| 186 | self.assertEqual(d.getVar("foo"), | ||
| 187 | d.getVar("bar")) | ||
| 188 | |||
| 189 | class TestConcat(unittest.TestCase): | ||
| 190 | def setUp(self): | ||
| 191 | self.d = bb.data.init() | ||
| 192 | self.d.setVar("FOO", "foo") | ||
| 193 | self.d.setVar("VAL", "val") | ||
| 194 | self.d.setVar("BAR", "bar") | ||
| 195 | |||
| 196 | def test_prepend(self): | ||
| 197 | self.d.setVar("TEST", "${VAL}") | ||
| 198 | self.d.prependVar("TEST", "${FOO}:") | ||
| 199 | self.assertEqual(self.d.getVar("TEST", True), "foo:val") | ||
| 200 | |||
| 201 | def test_append(self): | ||
| 202 | self.d.setVar("TEST", "${VAL}") | ||
| 203 | self.d.appendVar("TEST", ":${BAR}") | ||
| 204 | self.assertEqual(self.d.getVar("TEST", True), "val:bar") | ||
| 205 | |||
| 206 | def test_multiple_append(self): | ||
| 207 | self.d.setVar("TEST", "${VAL}") | ||
| 208 | self.d.prependVar("TEST", "${FOO}:") | ||
| 209 | self.d.appendVar("TEST", ":val2") | ||
| 210 | self.d.appendVar("TEST", ":${BAR}") | ||
| 211 | self.assertEqual(self.d.getVar("TEST", True), "foo:val:val2:bar") | ||
| 212 | |||
| 213 | class TestOverrides(unittest.TestCase): | ||
| 214 | def setUp(self): | ||
| 215 | self.d = bb.data.init() | ||
| 216 | self.d.setVar("OVERRIDES", "foo:bar:local") | ||
| 217 | self.d.setVar("TEST", "testvalue") | ||
| 218 | |||
| 219 | def test_no_override(self): | ||
| 220 | bb.data.update_data(self.d) | ||
| 221 | self.assertEqual(self.d.getVar("TEST", True), "testvalue") | ||
| 222 | |||
| 223 | def test_one_override(self): | ||
| 224 | self.d.setVar("TEST_bar", "testvalue2") | ||
| 225 | bb.data.update_data(self.d) | ||
| 226 | self.assertEqual(self.d.getVar("TEST", True), "testvalue2") | ||
| 227 | |||
| 228 | def test_multiple_override(self): | ||
| 229 | self.d.setVar("TEST_bar", "testvalue2") | ||
| 230 | self.d.setVar("TEST_local", "testvalue3") | ||
| 231 | self.d.setVar("TEST_foo", "testvalue4") | ||
| 232 | bb.data.update_data(self.d) | ||
| 233 | self.assertEqual(self.d.getVar("TEST", True), "testvalue3") | ||
| 234 | |||
| 235 | |||
| 236 | class TestFlags(unittest.TestCase): | ||
| 237 | def setUp(self): | ||
| 238 | self.d = bb.data.init() | ||
| 239 | self.d.setVar("foo", "value of foo") | ||
| 240 | self.d.setVarFlag("foo", "flag1", "value of flag1") | ||
| 241 | self.d.setVarFlag("foo", "flag2", "value of flag2") | ||
| 242 | |||
| 243 | def test_setflag(self): | ||
| 244 | self.assertEqual(self.d.getVarFlag("foo", "flag1"), "value of flag1") | ||
| 245 | self.assertEqual(self.d.getVarFlag("foo", "flag2"), "value of flag2") | ||
| 246 | |||
| 247 | def test_delflag(self): | ||
| 248 | self.d.delVarFlag("foo", "flag2") | ||
| 249 | self.assertEqual(self.d.getVarFlag("foo", "flag1"), "value of flag1") | ||
| 250 | self.assertEqual(self.d.getVarFlag("foo", "flag2"), None) | ||
| 251 | |||
| 252 | |||
