def test_strict_ordering_on_append_list_with_flags_factory_extend(self): FooList = StrictOrderingOnAppendListWithFlagsFactory({ 'foo': bool, 'bar': unicode }) foo = FooList(['a', 'b', 'c']) foo['a'].foo = True foo['b'].bar = 'bar' # Don't allow extending lists with different flag definitions. BarList = StrictOrderingOnAppendListWithFlagsFactory({ 'foo': unicode, 'baz': bool }) bar = BarList(['d', 'e', 'f']) bar['d'].foo = 'foo' bar['e'].baz = True with self.assertRaises(ValueError): foo + bar with self.assertRaises(ValueError): bar + foo # It's not obvious what to do with duplicate list items with possibly # different flag values, so don't allow that case. with self.assertRaises(ValueError): foo + foo def assertExtended(l): self.assertEqual(len(l), 6) self.assertEqual(l['a'].foo, True) self.assertEqual(l['b'].bar, 'bar') self.assertTrue('c' in l) self.assertEqual(l['d'].foo, True) self.assertEqual(l['e'].bar, 'bar') self.assertTrue('f' in l) # Test extend. zot = FooList(['d', 'e', 'f']) zot['d'].foo = True zot['e'].bar = 'bar' zot.extend(foo) assertExtended(zot) # Test __add__. zot = FooList(['d', 'e', 'f']) zot['d'].foo = True zot['e'].bar = 'bar' assertExtended(foo + zot) assertExtended(zot + foo) # Test __iadd__. foo += zot assertExtended(foo) # Test __setslice__. foo[3:] = [] self.assertEqual(len(foo), 3) foo[3:] = zot assertExtended(foo)
def test_strict_ordering_on_append_list_with_flags_factory(self): cls = StrictOrderingOnAppendListWithFlagsFactory({ 'foo': bool, 'bar': int, }) l = cls() l += ['a', 'b'] with self.assertRaises(Exception): l['a'] = 'foo' with self.assertRaises(Exception): c = l['c'] self.assertEqual(l['a'].foo, False) l['a'].foo = True self.assertEqual(l['a'].foo, True) with self.assertRaises(TypeError): l['a'].bar = 'bar' self.assertEqual(l['a'].bar, 0) l['a'].bar = 42 self.assertEqual(l['a'].bar, 42) l['b'].foo = True self.assertEqual(l['b'].foo, True) with self.assertRaises(AttributeError): l['b'].baz = False
def test_path_typed_list(self): config = self.config ctxt1 = Context(config=config) ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build")) ctxt2 = Context(config=config) ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build")) paths = [ "!../bar/qux", "!/qux/qux", "!qux", "../bar/qux", "/qux/qux", "qux", ] MyList = ContextDerivedTypedList(Path) l = MyList(ctxt1) l += paths for p_str, p_path in zip(paths, l): self.assertEqual(p_str, p_path) self.assertEqual(p_path, Path(ctxt1, p_str)) self.assertEqual(p_path.join("foo"), Path(ctxt1, mozpath.join(p_str, "foo"))) l2 = MyList(ctxt2) l2 += paths for p_str, p_path in zip(paths, l2): self.assertEqual(p_str, p_path) self.assertEqual(p_path, Path(ctxt2, p_str)) # Assigning with Paths from another context doesn't rebase them l2 = MyList(ctxt2) l2 += l for p_str, p_path in zip(paths, l2): self.assertEqual(p_str, p_path) self.assertEqual(p_path, Path(ctxt1, p_str)) MyListWithFlags = ContextDerivedTypedListWithItems( Path, StrictOrderingOnAppendListWithFlagsFactory({ "foo": bool, }), ) l = MyListWithFlags(ctxt1) l += paths for p in paths: l[p].foo = True for p_str, p_path in zip(paths, l): self.assertEqual(p_str, p_path) self.assertEqual(p_path, Path(ctxt1, p_str)) self.assertEqual(l[p_str].foo, True) self.assertEqual(l[p_path].foo, True)
def test_strict_ordering_on_append_list_with_flags_factory(self): cls = StrictOrderingOnAppendListWithFlagsFactory({ "foo": bool, "bar": int, }) l = cls() l += ["a", "b"] with self.assertRaises(Exception): l["a"] = "foo" with self.assertRaises(Exception): l["c"] self.assertEqual(l["a"].foo, False) l["a"].foo = True self.assertEqual(l["a"].foo, True) with self.assertRaises(TypeError): l["a"].bar = "bar" self.assertEqual(l["a"].bar, 0) l["a"].bar = 42 self.assertEqual(l["a"].bar, 42) l["b"].foo = True self.assertEqual(l["b"].foo, True) with self.assertRaises(AttributeError): l["b"].baz = False l["b"].update(foo=False, bar=12) self.assertEqual(l["b"].foo, False) self.assertEqual(l["b"].bar, 12) with self.assertRaises(AttributeError): l["b"].update(xyz=1)
def test_strict_ordering_on_append_list_with_flags_factory_extend(self): FooList = StrictOrderingOnAppendListWithFlagsFactory({ "foo": bool, "bar": six.text_type }) foo = FooList(["a", "b", "c"]) foo["a"].foo = True foo["b"].bar = "bar" # Don't allow extending lists with different flag definitions. BarList = StrictOrderingOnAppendListWithFlagsFactory({ "foo": six.text_type, "baz": bool }) bar = BarList(["d", "e", "f"]) bar["d"].foo = "foo" bar["e"].baz = True with self.assertRaises(ValueError): foo + bar with self.assertRaises(ValueError): bar + foo # It's not obvious what to do with duplicate list items with possibly # different flag values, so don't allow that case. with self.assertRaises(ValueError): foo + foo def assertExtended(l): self.assertEqual(len(l), 6) self.assertEqual(l["a"].foo, True) self.assertEqual(l["b"].bar, "bar") self.assertTrue("c" in l) self.assertEqual(l["d"].foo, True) self.assertEqual(l["e"].bar, "bar") self.assertTrue("f" in l) # Test extend. zot = FooList(["d", "e", "f"]) zot["d"].foo = True zot["e"].bar = "bar" zot.extend(foo) assertExtended(zot) # Test __add__. zot = FooList(["d", "e", "f"]) zot["d"].foo = True zot["e"].bar = "bar" assertExtended(foo + zot) assertExtended(zot + foo) # Test __iadd__. foo += zot assertExtended(foo) # Test __setitem__. foo[3:] = [] self.assertEqual(len(foo), 3) foo[3:] = zot assertExtended(foo)
def __cmp__(self, other): return cmp(self.value, str(other)) def __hash__(self): return hash(self.value) VARIABLES = { 'HOGE': (unicode, unicode, None), 'FUGA': (Fuga, unicode, None), 'PIYO': (Piyo, unicode, None), 'HOGERA': (ContextDerivedTypedList(Piyo, StrictOrderingOnAppendList), list, None), 'HOGEHOGE': (ContextDerivedTypedListWithItems( Piyo, StrictOrderingOnAppendListWithFlagsFactory({ 'foo': bool, })), list, None), } class TestContext(unittest.TestCase): def test_key_rejection(self): # Lowercase keys should be rejected during normal operation. ns = Context(allowed_variables=VARIABLES) with self.assertRaises(KeyError) as ke: ns['foo'] = True e = ke.exception.args self.assertEqual(e[0], 'global_ns') self.assertEqual(e[1], 'set_unknown')
file. """, 'export'), 'ANDROID_RES_DIRS': (List, list, """Android resource directories. This variable contains a list of directories, each relative to the srcdir, containing static files to package into a 'res' directory and merge into an APK file. """, 'export'), 'ANDROID_ECLIPSE_PROJECT_TARGETS': (dict, dict, """Defines Android Eclipse project targets. This variable should not be populated directly. Instead, it should populated by calling add_android_eclipse{_library}_project(). """, 'export'), 'SOURCES': (StrictOrderingOnAppendListWithFlagsFactory({ 'no_pgo': bool, 'flags': List }), list, """Source code files. This variable contains a list of source code files to compile. Accepts assembler, C, C++, Objective C/C++. """, None), 'GENERATED_SOURCES': (StrictOrderingOnAppendList, list, """Generated source code files. This variable contains a list of generated source code files to compile. Accepts assembler, C, C++, Objective C/C++. """, None), 'FILES_PER_UNIFIED_FILE': (int, int, """The number of source files to compile into each unified source file.
'ANDROID_RES_DIRS': (list, list, """Android resource directories. This variable contains a list of directories, each relative to the srcdir, containing static files to package into a 'res' directory and merge into an APK file. """, 'export'), 'ANDROID_ECLIPSE_PROJECT_TARGETS': (dict, dict, """Defines Android Eclipse project targets. This variable should not be populated directly. Instead, it should populated by calling add_android_eclipse{_library}_project(). """, 'export'), 'SOURCES': (StrictOrderingOnAppendListWithFlagsFactory({'no_pgo': bool}), list, """Source code files. This variable contains a list of source code files to compile. Accepts assembler, C, C++, Objective C/C++. """, 'compile'), 'GENERATED_SOURCES': (StrictOrderingOnAppendList, list, """Generated source code files. This variable contains a list of generated source code files to compile. Accepts assembler, C, C++, Objective C/C++. """, 'compile'), 'FILES_PER_UNIFIED_FILE': (int, int, """The number of source files to compile into each unified source file.
def __hash__(self): return hash(self.value) VARIABLES = { "HOGE": (six.text_type, six.text_type, None), "FUGA": (Fuga, six.text_type, None), "PIYO": (Piyo, six.text_type, None), "HOGERA": (ContextDerivedTypedList(Piyo, StrictOrderingOnAppendList), list, None), "HOGEHOGE": ( ContextDerivedTypedListWithItems( Piyo, StrictOrderingOnAppendListWithFlagsFactory( { "foo": bool, } ), ), list, None, ), } class TestContext(unittest.TestCase): def test_key_rejection(self): # Lowercase keys should be rejected during normal operation. ns = Context(allowed_variables=VARIABLES) with self.assertRaises(KeyError) as ke:
'ANDROID_GENERATED_RESFILES': (StrictOrderingOnAppendList, list, """Android resource files generated as part of the build. This variable contains a list of files that are expected to be generated (often by preprocessing) into a 'res' directory as part of the build process, and subsequently merged into an APK file. """, 'export'), 'ANDROID_RES_DIRS': (list, list, """Android resource directories. This variable contains a list of directories, each relative to the srcdir, containing static files to package into a 'res' directory and merge into an APK file. """, 'export'), 'SOURCES': (StrictOrderingOnAppendListWithFlagsFactory({'no_pgo': bool}), list, """Source code files. This variable contains a list of source code files to compile. Accepts assembler, C, C++, Objective C/C++. """, 'compile'), 'GENERATED_SOURCES': (StrictOrderingOnAppendList, list, """Generated source code files. This variable contains a list of generated source code files to compile. Accepts assembler, C, C++, Objective C/C++. """, 'compile'), 'FILES_PER_UNIFIED_FILE': (int, int, """The number of source files to compile into each unified source file.