def test_function_args(self): class Foo(int): pass def foo(a, b): return type(a), type(b) FUNCTIONS.update({"foo": (lambda self: foo, (Foo, int), "")}) try: sandbox = self.sandbox() source = 'foo("a", "b")' with self.assertRaises(SandboxExecutionError) as se: sandbox.exec_source(source, "foo.mozbuild") e = se.exception self.assertIsInstance(e.exc_value, ValueError) sandbox = self.sandbox() source = 'foo(1, "b")' with self.assertRaises(SandboxExecutionError) as se: sandbox.exec_source(source, "foo.mozbuild") e = se.exception self.assertIsInstance(e.exc_value, ValueError) sandbox = self.sandbox() source = "a = foo(1, 2)" sandbox.exec_source(source, "foo.mozbuild") self.assertEquals(sandbox["a"], (Foo, int)) finally: del FUNCTIONS["foo"]
def test_documentation_formatting(self): for typ, inp, doc, tier in VARIABLES.values(): self._verify_doc(doc) for attr, args, doc in FUNCTIONS.values(): self._verify_doc(doc) for func, typ, doc in SPECIAL_VARIABLES.values(): self._verify_doc(doc)
def test_symbol_presence(self): # Ensure no discrepancies between the master symbol table and what's in # the sandbox. sandbox = self.sandbox() sandbox._context.add_source(sandbox.normalize_path("moz.build")) all_symbols = set() all_symbols |= set(FUNCTIONS.keys()) all_symbols |= set(SPECIAL_VARIABLES.keys()) for symbol in all_symbols: self.assertIsNotNone(sandbox[symbol])
def test_symbol_presence(self): # Ensure no discrepancies between the master symbol table and what's in # the sandbox. sandbox = self.sandbox() sandbox._context.add_source(sandbox.normalize_path('moz.build')) all_symbols = set() all_symbols |= set(FUNCTIONS.keys()) all_symbols |= set(SPECIAL_VARIABLES.keys()) for symbol in all_symbols: self.assertIsNotNone(sandbox[symbol])
def test_function_args(self): class Foo(int): pass def foo(a, b): return type(a), type(b) FUNCTIONS.update( { "foo": (lambda self: foo, (Foo, int), ""), } ) try: sandbox = self.sandbox() source = 'foo("a", "b")' with self.assertRaises(SandboxExecutionError) as se: sandbox.exec_source(source, "foo.mozbuild") e = se.exception self.assertIsInstance(e.exc_value, ValueError) sandbox = self.sandbox() source = 'foo(1, "b")' with self.assertRaises(SandboxExecutionError) as se: sandbox.exec_source(source, "foo.mozbuild") e = se.exception self.assertIsInstance(e.exc_value, ValueError) sandbox = self.sandbox() source = "a = foo(1, 2)" sandbox.exec_source(source, "foo.mozbuild") self.assertEquals(sandbox["a"], (Foo, int)) finally: del FUNCTIONS["foo"]
def test_documentation_formatting(self): for typ, inp, doc in VARIABLES.values(): self._verify_doc(doc) for attr, args, doc in FUNCTIONS.values(): self._verify_doc(doc) for func, typ, doc in SPECIAL_VARIABLES.values(): self._verify_doc(doc) for name, cls in SUBCONTEXTS.items(): self._verify_doc(cls.__doc__) for name, v in cls.VARIABLES.items(): self._verify_doc(v[2])
def test_documentation_formatting(self): for typ, inp, doc, tier in VARIABLES.values(): self._verify_doc(doc) for attr, args, doc in FUNCTIONS.values(): self._verify_doc(doc) for func, typ, doc in SPECIAL_VARIABLES.values(): self._verify_doc(doc) for name, cls in SUBCONTEXTS.items(): self._verify_doc(cls.__doc__) for name, v in cls.VARIABLES.items(): self._verify_doc(v[2])