def test_not_memoized(self): d1 = bb.data.init() d2 = bb.data.init() d1.setVar("FOO", "bar") d2.setVar("FOO", "bar") self.assertTrue(bbvalue.bbvalue("FOO", d1) is not bbvalue.bbvalue("FOO", d2))
def test_changed_after_memoized(self): d = bb.data.init() d.setVar("foo", "value of foo") val = bbvalue.bbparse("${foo}", d) self.assertEqual(str(bbvalue.bbvalue("foo", d)), "value of foo") d.setVar("foo", "second value of foo") self.assertEqual(str(bbvalue.bbvalue("foo", d)), "second value of foo")
def test_normal_append(self): value = bbvalue.LazyCompound(self.metadata) value.append(bbvalue.bbvalue("VAL", self.metadata)) value.lazy_prepend(bbvalue.bbparse("${FOO}:", self.metadata)) value.lazy_append(bbvalue.bbparse(":${BAR}", self.metadata)) value.append(bbvalue.bbparse(":val2", self.metadata)) self.assertEqual(value.resolve(), "foo:val:val2:bar")
def data_for_hash(key, seen): """Returns an iterator over the variable names and their values, including references""" if key in seen: return seen.add(key) if self.is_blacklisted(key): return valstr = self.metadata.getVar(key, False) if valstr is not None: try: value = self.transform_blacklisted( bbvalue.bbvalue(key, self.metadata)) except (SyntaxError, NotImplementedError, bbvalue.PythonExpansionError, bbvalue.RecursionError), exc: msg.error(None, "Unable to parse %s, excluding from signature: %s" % (key, exc)) else: yield key, value refs = reftracker.references(value, self.metadata) refs |= reftracker.references_from_flags(key, self.metadata) for ref in refs: for other in data_for_hash(ref, seen): yield other
def test_python(self): self.d.setVar("FOO", self.pydata) self.d.setVarFlags("FOO", {"func": True, "python": True}) value = bbvalue.bbvalue("FOO", self.d) self.assertEquals(reftracker.references(value, self.d), set(["somevar", "bar", "something", "inexpand"])) self.assertEquals(reftracker.calls(value, self.d), set(["test", "test2", "a"]))
def test_recursion_exception(self): self.d.setVar("FOO", "${BAR}") self.d.setVar("BAR", "${${@'FOO'}}") value = bbvalue.bbvalue("FOO", self.d) self.assertRaises(bbvalue.RecursionError, str, value)
def test_indirect_recursion(self): self.d.setVar("FOO", "${BAR}") self.d.setVar("BAR", "${BAZ}") self.d.setVar("BAZ", "${FOO}") value = bbvalue.bbvalue("FOO", self.d) self.assertRaises(bbvalue.RecursionError, str, value)
def test_double_reference(self): self.d.setVar("BAR", "bar value") self.d.setVar("FOO", "${BAR} foo ${BAR}") val = bbvalue.bbvalue("FOO", self.d) self.assertEqual(str(val), "bar value foo bar value")
def test_python_snippet_error_path(self): self.d.setVar("FOO", "foo value ${BAR}") self.d.setVar("BAR", "bar value ${@int('test')}") val = bbvalue.bbvalue("FOO", self.d) self.assertRaises(bbvalue.PythonExpansionError, val.resolve)
def test_python_snippet_runtime_error(self): self.d.setVar("FOO", "${@int('test')}") val = bbvalue.bbvalue("FOO", self.d) self.assertRaises(bbvalue.PythonExpansionError, val.resolve)
def test_python_snippet_syntax_error(self): self.d.setVar("FOO", "${@foo = 5}") val = bbvalue.bbvalue("FOO", self.d) self.assertRaises(SyntaxError, val.resolve)
def test_false_condition(self): value = bbvalue.Conditional(self.metadata, lambda d: 'foo' in d.getVar("OVERRIDES", True).split(":"), [bbvalue.bbvalue("TEST", self.metadata)]) self.metadata.setVar("OVERRIDES", "bar:local") self.assertEqual(value.resolve(), "")
def test_nonstring(self): self.d.setVar("TEST", 5) val = bbvalue.bbvalue("TEST", self.d) self.assertEqual(str(val), "5")
def test_append(self): value = bbvalue.LazyCompound(self.metadata) value.append(bbvalue.bbvalue("VAL", self.metadata)) value.lazy_append(bbvalue.bbparse(":${BAR}", self.metadata)) self.assertEqual(value.resolve(), "val:bar")
def test_prepend(self): value = bbvalue.LazyCompound(self.metadata) value.append(bbvalue.bbvalue("VAL", self.metadata)) value.lazy_prepend(bbvalue.bbparse("${FOO}:", self.metadata)) self.assertEqual(value.resolve(), "foo:val")
def test_same_value(self): d = bb.data.init() d.setVar("foo", "value of") d.setVar("bar", "value of") self.assertEqual(bbvalue.bbvalue("foo", d), bbvalue.bbvalue("bar", d))
def test_memoized(self): d = bb.data.init() d.setVar("FOO", "bar") self.assertTrue(bbvalue.bbvalue("FOO", d) is bbvalue.bbvalue("FOO", d))
def test_no_condition(self): value = bbvalue.Conditional(self.metadata, None, [bbvalue.bbvalue("TEST", self.metadata)]) self.assertEqual(value.resolve(), "testvalue")
def references_from_name(varname, metadata): refs = references(bbvalue.bbvalue(varname, metadata), metadata) refs |= references_from_flags(varname, metadata) return refs