예제 #1
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)
예제 #2
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)
 def test_package_error(self):
     with support.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")
         self._check_import_error(["-m", "test_pkg"], msg, cwd=script_dir)
예제 #4
0
 def test_package_error(self):
     with support.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)
 def test_module_in_package(self):
     with support.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, 'check_sibling')
         launch_name = _make_launch_script(script_dir, 'launch',
                                           'test_pkg.check_sibling')
         self._check_script(launch_name)
 def test_package(self):
     source = self.main_in_children_source
     with support.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):
     with support.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_module_in_package(self):
     with support.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')
         self._check_script(["-m", "test_pkg.script"], script_name, script_name,
                            script_dir, 'test_pkg',
                            importlib.machinery.SourceFileLoader,
                            cwd=script_dir)
예제 #9
0
 def test_module_in_package(self):
     with support.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_recursion(self):
     with support.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")
         self._check_import_error(["-m", "test_pkg"], msg, cwd=script_dir)
 def test_package_recursion(self):
     with support.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)
 def test_package_compiled(self):
     source = self.main_in_children_source
     with support.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)
 def test_package_compiled(self):
     with support.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_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 support.temp_dir() as script_dir:
         with support.change_cwd(path=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(repr(out))
             self.assertEqual(rc, 1)
 def test_issue8202(self):
     # Make sure package __init__ modules see "-m" in sys.argv0 while
     # searching for the module to execute
     with support.temp_dir() as script_dir:
         with support.change_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, __isolated=False)
             if verbose > 1:
                 print(repr(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)
예제 #16
0
 def test_issue8202(self):
     # Make sure package __init__ modules see "-m" in sys.argv0 while
     # searching for the module to execute
     with support.temp_dir() as script_dir:
         with support.change_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,
                                             __isolated=False)
             if verbose > 1:
                 print(repr(out))
             expected = "init_argv0==%r" % '-m'
             self.assertIn(expected.encode('utf-8'), out)
             self._check_output(script_name, rc, out, script_name,
                                script_name, script_dir, 'test_pkg',
                                importlib.machinery.SourceFileLoader)
예제 #17
0
 def setup_test_pkg(self, *args):
     with support.temp_dir() as script_dir, \
             support.change_cwd(path=script_dir):
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir, *args)
         yield pkg_dir
 def setup_test_pkg(self, *args):
     with support.temp_dir() as script_dir, \
             support.change_cwd(path=script_dir):
         pkg_dir = os.path.join(script_dir, 'test_pkg')
         make_pkg(pkg_dir, *args)
         yield pkg_dir