def test_build_file_entrypoint(self): s = builder.build_file({}, "print('valid!')") try: compile(s, "inlined.py", "exec", dont_inherit=True) except Exception: self.fail("compilation should be valid")
def test_build_file_namespace(self): s = builder.build_file({}, "", namespace_packages=True) try: compile(s, "inlined.py", "exec", dont_inherit=True) except Exception: self.fail("compilation should be valid")
def test_build_file_shebang(self): s = builder.build_file({}, "", shebang="#!/usr/bin/env python3") try: compile(s, "inlined.py", "exec", dont_inherit=True) except Exception: self.fail("compilation should be valid")
def test_build_file_modules(self): hex_val = hex(random.getrandbits(128))[2:] s = builder.build_file( { "test": ModuleDefinition( "test", False, "IS_TEST=True\nTEST_VALUE={!r}".format(hex_val)) }, "") self.assertIn(hex_val, s) try: compile(s, "inlined.py", "exec", dont_inherit=True) except Exception: self.fail("compilation should be valid")
def test_build_file_entrypoint_invalid(self): s = builder.build_file({}, "print('invalid!") with self.assertRaises(SyntaxError): compile(s, "inlined.py", "exec", dont_inherit=True)