Ejemplo n.º 1
0
    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")
Ejemplo n.º 2
0
    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")
Ejemplo n.º 3
0
    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")
Ejemplo n.º 4
0
    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")
Ejemplo n.º 5
0
    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)