def test_module_in_package(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, 'script')
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script')
         self._check_script(launch_name, script_name, script_name, 'test_pkg')
예제 #2
0
 def test_package_error(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, "test_pkg")
         make_pkg(pkg_dir)
         msg = "'test_pkg' is a package and cannot " "be directly executed"
         launch_name = _make_launch_script(script_dir, "launch", "test_pkg")
         self._check_import_error(launch_name, msg)
예제 #3
0
    def test_recursion_limit(self):
        subpackage = os.path.join(self.pkgdir, 'spam')
        subpackage2 = os.path.join(subpackage, 'ham')
        subpackage3 = os.path.join(subpackage2, 'eggs')
        for pkg in (subpackage, subpackage2, subpackage3):
            script_helper.make_pkg(pkg)

        subinitfn = os.path.join(subpackage, '__init__.py')
        hamfn = script_helper.make_script(subpackage, 'ham', '')
        spamfn = script_helper.make_script(subpackage2, 'spam', '')
        eggfn = script_helper.make_script(subpackage3, 'egg', '')

        self.assertRunOK('-q', '-r 0', self.pkgdir)
        self.assertNotCompiled(subinitfn)
        self.assertFalse(
            os.path.exists(os.path.join(subpackage, '__pycache__')))

        self.assertRunOK('-q', '-r 1', self.pkgdir)
        self.assertCompiled(subinitfn)
        self.assertCompiled(hamfn)
        self.assertNotCompiled(spamfn)

        self.assertRunOK('-q', '-r 2', self.pkgdir)
        self.assertCompiled(subinitfn)
        self.assertCompiled(hamfn)
        self.assertCompiled(spamfn)
        self.assertNotCompiled(eggfn)

        self.assertRunOK('-q', '-r 5', self.pkgdir)
        self.assertCompiled(subinitfn)
        self.assertCompiled(hamfn)
        self.assertCompiled(spamfn)
        self.assertCompiled(eggfn)
예제 #4
0
 def test_module_in_package(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, 'script')
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script')
         self._check_script(launch_name, script_name, script_name, 'test_pkg')
예제 #5
0
 def test_package(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, "test_pkg")
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, "__main__")
         launch_name = _make_launch_script(script_dir, "launch", "test_pkg")
         self._check_script(launch_name, script_name, script_name, "test_pkg")
 def test_package_error(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         msg = ("'test_pkg' is a package and cannot "
                "be directly executed")
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_import_error(launch_name, msg)
예제 #7
0
 def test_package(self):
     source = self.main_in_children_source
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__', source=source)
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name)
 def test_package(self):
     source = self.main_in_children_source
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__',
                                         source=source)
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name)
예제 #9
0
 def test_module_in_package(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, "test_pkg")
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, "script")
         launch_name = _make_launch_script(script_dir, "launch", "test_pkg.script")
         self._check_script(
             launch_name, script_name, script_name, script_dir, "test_pkg", importlib.machinery.SourceFileLoader
         )
예제 #10
0
 def test_package(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__')
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name, script_name,
                            script_name, script_dir, 'test_pkg',
                            importlib.machinery.SourceFileLoader)
 def test_package(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__')
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name, script_name,
                            script_name, script_dir, 'test_pkg',
                            importlib.machinery.SourceFileLoader)
예제 #12
0
 def test_package_compiled(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, "test_pkg")
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, "__main__")
         compiled_name = compile_script(script_name)
         os.remove(script_name)
         launch_name = _make_launch_script(script_dir, "launch", "test_pkg")
         self._check_script(launch_name, compiled_name, compiled_name, "test_pkg")
예제 #13
0
 def test_package_compiled(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__')
         compiled_name = compile_script(script_name)
         os.remove(script_name)
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name, compiled_name, compiled_name,
                            'test_pkg')
예제 #14
0
 def test_package_compiled(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__')
         compiled_name = py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name, pyc_file,
                            pyc_file, script_dir, 'test_pkg')
예제 #15
0
 def test_package_recursion(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         main_dir = os.path.join(pkg_dir, '__main__')
         make_pkg(main_dir)
         msg = ("Cannot use package as __main__ module; "
                "'test_pkg' is a package and cannot "
                "be directly executed")
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_import_error(launch_name, msg)
예제 #16
0
 def test_package_compiled(self):
     source = self.main_in_children_source
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__', source=source)
         compiled_name = py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name)
예제 #17
0
 def test_package_compiled(self):
     if test.test_support.check_impl_detail(pypy=True):
         raise unittest.SkipTest("pypy won't load lone .pyc files")
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__')
         compiled_name = compile_script(script_name)
         os.remove(script_name)
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name, compiled_name, compiled_name,
                            'test_pkg')
예제 #18
0
 def test_dash_m_error_code_is_one(self):
     # If a module is invoked with the -m command line flag
     # and results in an error that the return code to the
     # shell is '1'
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, 'other', "if __name__ == '__main__': raise ValueError")
         rc, out, err = assert_python_failure('-m', 'test_pkg.other', *example_args)
         if verbose > 1:
             print(out)
         self.assertEqual(rc, 1)
예제 #19
0
 def test_package_compiled(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, "test_pkg")
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, "__main__")
         compiled_name = py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         launch_name = _make_launch_script(script_dir, "launch", "test_pkg")
         self._check_script(
             launch_name, pyc_file, pyc_file, script_dir, "test_pkg", importlib.machinery.SourcelessFileLoader
         )
 def test_package_compiled(self):
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__')
         compiled_name = py_compile.compile(script_name, doraise=True)
         os.remove(script_name)
         pyc_file = support.make_legacy_pyc(script_name)
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name, pyc_file,
                            pyc_file, script_dir, 'test_pkg',
                            importlib.machinery.SourcelessFileLoader)
예제 #21
0
 def test_dash_m_error_code_is_one(self):
     # If a module is invoked with the -m command line flag
     # and results in an error that the return code to the
     # shell is '1'
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, 'other', "if __name__ == '__main__': raise ValueError")
         rc, out, err = assert_python_failure('-m', 'test_pkg.other', *example_args)
         if verbose > 1:
             print(out)
         self.assertEqual(rc, 1)
예제 #22
0
 def test_package_compiled(self):
     if test.test_support.check_impl_detail(pypy=True):
         raise unittest.SkipTest("pypy won't load lone .pyc files")
     with temp_dir() as script_dir:
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir)
         script_name = _make_test_script(pkg_dir, '__main__')
         compiled_name = compile_script(script_name)
         os.remove(script_name)
         launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg')
         self._check_script(launch_name, compiled_name,
                            compiled_name, 'test_pkg')
예제 #23
0
 def test_issue8202(self):
     # Make sure package __init__ modules see "-m" in sys.argv0 while
     # searching for the module to execute
     with temp_dir() as script_dir:
         with support.temp_cwd(path=script_dir):
             pkg_dir = os.path.join(script_dir, 'test_pkg')
             make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])")
             script_name = _make_test_script(pkg_dir, 'script')
             rc, out, err = assert_python_ok('-m', 'test_pkg.script', *example_args)
             if verbose > 1:
                 print(out)
             expected = "init_argv0==%r" % '-m'
             self.assertIn(expected.encode('utf-8'), out)
             self._check_output(script_name, rc, out,
                                script_name, script_name, '', 'test_pkg')
예제 #24
0
 def test_issue8202(self):
     # Make sure package __init__ modules see "-m" in sys.argv0 while
     # searching for the module to execute
     with temp_dir() as script_dir:
         with support.temp_cwd(path=script_dir):
             pkg_dir = os.path.join(script_dir, "test_pkg")
             make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])")
             script_name = _make_test_script(pkg_dir, "script")
             rc, out, err = assert_python_ok("-m", "test_pkg.script", *example_args)
             if verbose > 1:
                 print(out)
             expected = "init_argv0==%r" % "-m"
             self.assertIn(expected.encode("utf-8"), out)
             self._check_output(
                 script_name, rc, out, script_name, script_name, "", "test_pkg", importlib.machinery.SourceFileLoader
             )
 def setup_test_pkg(self, *args):
     with temp_dir() as script_dir, \
             test.test_support.change_cwd(script_dir):
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir, *args)
         yield pkg_dir
예제 #26
0
 def setup_test_pkg(self, *args):
     with temp_dir() as script_dir, \
             test.test_support.change_cwd(script_dir):
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir, *args)
         yield pkg_dir