コード例 #1
0
ファイル: test_tempfile.py プロジェクト: Kelauni22/Meeple
def _inside_empty_temp_dir():
    dir = tempfile.mkdtemp()
    try:
        with support.swap_attr(tempfile, 'tempdir', dir):
            yield
    finally:
        support.rmtree(dir)
コード例 #2
0
def _inside_empty_temp_dir():
    dir = tempfile.mkdtemp()
    try:
        with support.swap_attr(tempfile, 'tempdir', dir):
            yield
    finally:
        support.rmtree(dir)
コード例 #3
0
 def tearDown(self):
     try:
         os.chdir(self.cwd)
         if self.pythonexe != sys.executable:
             os.remove(self.pythonexe)
         test_support.rmtree(self.parent_dir)
     finally:
         BaseTestCase.tearDown(self)
コード例 #4
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
 def tearDown(self):
     sys.path[:] = self.sys_path
     if self.orig_module is not None:
         sys.modules[self.module_name] = self.orig_module
     else:
         unload(self.module_name)
     unlink(self.file_name)
     unlink(self.compiled_name)
     rmtree(self.dir_name)
コード例 #5
0
ファイル: test_all.py プロジェクト: underrun/pybsddb
def get_new_environment_path() :
    path=get_new_path("environment")
    import os
    try:
        os.makedirs(path,mode=0700)
    except os.error:
        test_support.rmtree(path)
        os.makedirs(path)
    return path
コード例 #6
0
 def tearDown(self):
     sys.path[:] = self.sys_path
     if self.orig_module is not None:
         sys.modules[self.module_name] = self.orig_module
     else:
         unload(self.module_name)
     unlink(self.file_name)
     unlink(self.compiled_name)
     rmtree(self.dir_name)
コード例 #7
0
def get_new_environment_path() :
    path=get_new_path("environment")
    import os
    try:
        os.makedirs(path,mode=0o700)
    except os.error:
        test_support.rmtree(path)
        os.makedirs(path)
    return path
コード例 #8
0
 def check_script_output(self, src, expected):
     tmpd = tempfile.mkdtemp()
     try:
         fn = os.path.join(tmpd, 'test.py')
         with open(fn, 'wb') as fp:
             fp.write(src)
         rc, out, err = script_helper.assert_python_ok(fn)
     finally:
         rmtree(tmpd)
     self.assertEqual(out.rstrip(), expected)
コード例 #9
0
 def check_script_output(self, src, expected):
     tmpd = tempfile.mkdtemp()
     try:
         fn = os.path.join(tmpd, 'test.py')
         with open(fn, 'wb') as fp:
             fp.write(src)
         rc, out, err = script_helper.assert_python_ok(fn)
     finally:
         rmtree(tmpd)
     self.assertEqual(out.rstrip(), expected)
コード例 #10
0
ファイル: util.py プロジェクト: ralphbean/importlib_full
def create_modules(*names):
    u"""Temporarily create each named module with an attribute (named 'attr')
    that contains the name passed into the context manager that caused the
    creation of the module.

    All files are created in a temporary directory returned by
    tempfile.mkdtemp(). This directory is inserted at the beginning of
    sys.path. When the context manager exits all created files (source and
    bytecode) are explicitly deleted.

    No magic is performed when creating packages! This means that if you create
    a module within a package you must also create the package's __init__ as
    well.

    """
    source = u'attr = {0!r}'
    created_paths = []
    mapping = {}
    state_manager = None
    uncache_manager = None
    try:
        temp_dir = tempfile.mkdtemp()
        mapping[u'.root'] = temp_dir
        import_names = set()
        for name in names:
            if not name.endswith(u'__init__'):
                import_name = name
            else:
                import_name = name[:-len(u'.__init__')]
            import_names.add(import_name)
            if import_name in sys.modules:
                del sys.modules[import_name]
            name_parts = name.split(u'.')
            file_path = temp_dir
            for directory in name_parts[:-1]:
                file_path = os.path.join(file_path, directory)
                if not os.path.exists(file_path):
                    os.mkdir(file_path)
                    created_paths.append(file_path)
            file_path = os.path.join(file_path, name_parts[-1] + u'.py')
            with open(file_path, u'w') as file:
                file.write(source.format(name))
            created_paths.append(file_path)
            mapping[name] = file_path
        uncache_manager = util.uncache(*import_names)
        uncache_manager.__enter__()
        state_manager = util.import_state(path=[temp_dir])
        state_manager.__enter__()
        yield mapping
    finally:
        if state_manager is not None:
            state_manager.__exit__(None, None, None)
        if uncache_manager is not None:
            uncache_manager.__exit__(None, None, None)
        support.rmtree(temp_dir)
コード例 #11
0
 def test_yet_more_evil_still_undecodable(self):
     # Issue #25388
     src = b"#\x00\n#\xfd\n"
     tmpd = tempfile.mkdtemp()
     try:
         fn = os.path.join(tmpd, "bad.py")
         with open(fn, "wb") as fp:
             fp.write(src)
         rc, out, err = script_helper.assert_python_failure(fn)
     finally:
         test_support.rmtree(tmpd)
     self.assertIn(b"Non-ASCII", err)
コード例 #12
0
 def test_yet_more_evil_still_undecodable(self):
     # Issue #25388
     src = b"#\x00\n#\xfd\n"
     tmpd = tempfile.mkdtemp()
     try:
         fn = os.path.join(tmpd, "bad.py")
         with open(fn, "wb") as fp:
             fp.write(src)
         rc, out, err = script_helper.assert_python_failure(fn)
     finally:
         test_support.rmtree(tmpd)
     self.assertIn(b"Non-ASCII", err)
コード例 #13
0
 def test_replace_parent_in_sys_modules(self):
     dir_name = os.path.abspath(TESTFN)
     os.mkdir(dir_name)
     try:
         pkg_dir = os.path.join(dir_name, 'sa')
         os.mkdir(pkg_dir)
         with open(os.path.join(pkg_dir, '__init__.py'), 'w') as init_file:
             init_file.write("import v1")
         with open(os.path.join(pkg_dir, 'v1.py'), 'w') as v1_file:
             v1_file.write("import sys;"
                           "sys.modules['sa'] = sys.modules[__name__];"
                           "import sa")
         sys.path.insert(0, dir_name)
         # a segfault means the test failed!
         import sa
     finally:
         rmtree(dir_name)
コード例 #14
0
ファイル: test_compile.py プロジェクト: mozillazg/pypy
 def test_yet_more_evil_still_undecodable(self):
     # Issue #25388
     src = b"#\x00\n#\xfd\n"
     tmpd = tempfile.mkdtemp()
     try:
         fn = os.path.join(tmpd, "bad.py")
         with open(fn, "wb") as fp:
             fp.write(src)
         try:
             rc, out, err = script_helper.assert_python_failure(fn)
         except AssertionError:
             if check_impl_detail(pypy=True):
                 # as long as we don't crash
                 return
             raise
     finally:
         test_support.rmtree(tmpd)
     self.assertIn(b"Non-ASCII", err)
コード例 #15
0
 def test_readonly_files(self):
     dir = _fname
     os.mkdir(dir)
     try:
         fname = os.path.join(dir, 'db')
         f = dumbdbm.open(fname, 'n')
         self.assertEqual(list(f.keys()), [])
         for key in self._dict:
             f[key] = self._dict[key]
         f.close()
         os.chmod(fname + ".dir", stat.S_IRUSR)
         os.chmod(fname + ".dat", stat.S_IRUSR)
         os.chmod(dir, stat.S_IRUSR|stat.S_IXUSR)
         f = dumbdbm.open(fname, 'r')
         self.assertEqual(sorted(f.keys()), sorted(self._dict))
         f.close()  # don't write
     finally:
         test_support.rmtree(dir)
コード例 #16
0
 def test_readonly_files(self):
     dir = _fname
     os.mkdir(dir)
     try:
         fname = os.path.join(dir, 'db')
         f = dumbdbm.open(fname, 'n')
         self.assertEqual(list(f.keys()), [])
         for key in self._dict:
             f[key] = self._dict[key]
         f.close()
         os.chmod(fname + ".dir", stat.S_IRUSR)
         os.chmod(fname + ".dat", stat.S_IRUSR)
         os.chmod(dir, stat.S_IRUSR | stat.S_IXUSR)
         f = dumbdbm.open(fname, 'r')
         self.assertEqual(sorted(f.keys()), sorted(self._dict))
         f.close()  # don't write
     finally:
         test_support.rmtree(dir)
コード例 #17
0
 def test_yet_more_evil_still_undecodable(self):
     # Issue #25388
     src = b"#\x00\n#\xfd\n"
     tmpd = tempfile.mkdtemp()
     try:
         fn = os.path.join(tmpd, "bad.py")
         with open(fn, "wb") as fp:
             fp.write(src)
         try:
             rc, out, err = script_helper.assert_python_failure(fn)
         except AssertionError:
             if check_impl_detail(pypy=True):
                 # as long as we don't crash
                 return
             raise
     finally:
         test_support.rmtree(tmpd)
     self.assertIn(b"Non-ASCII", err)
コード例 #18
0
ファイル: test_netrc.py プロジェクト: exodrifter/unity-python
 def test_security(self):
     # This test is incomplete since we are normally not run as root and
     # therefore can't test the file ownership being wrong.
     os.unlink(temp_filename)
     d = test_support.TESTFN
     try:
         os.mkdir(d)
         fn = os.path.join(d, '.netrc')
         with open(fn, 'wt') as f:
             f.write(TEST_NETRC)
         with test_support.EnvironmentVarGuard() as environ:
             environ.set('HOME', d)
             os.chmod(fn, 0600)
             self.netrc = netrc.netrc()
             self.test_case_1()
             os.chmod(fn, 0622)
             self.assertRaises(netrc.NetrcParseError, netrc.netrc)
     finally:
         test_support.rmtree(d)
コード例 #19
0
 def test_security(self):
     # This test is incomplete since we are normally not run as root and
     # therefore can't test the file ownership being wrong.
     os.unlink(temp_filename)
     d = test_support.TESTFN
     try:
         os.mkdir(d)
         fn = os.path.join(d, '.netrc')
         with open(fn, 'wt') as f:
             f.write(TEST_NETRC)
         with test_support.EnvironmentVarGuard() as environ:
             environ.set('HOME', d)
             os.chmod(fn, 0600)
             self.netrc = netrc.netrc()
             self.test_case_1()
             os.chmod(fn, 0622)
             self.assertRaises(netrc.NetrcParseError, netrc.netrc)
     finally:
         test_support.rmtree(d)
コード例 #20
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
 def tearDown(self):
     rmtree(self.path)
     sys.path[:] = self.syspath
コード例 #21
0
 def tearDownClass(cls):
     td = cls.tmpdir
     if td and os.path.isdir(td):
         test_support.rmtree(td)
コード例 #22
0
ファイル: test_rpm.py プロジェクト: thinhnd8752/junkcode
 def tearDown(self):
     rmtree(self.topdir)
コード例 #23
0
 def tearDown(self):
     test_support.rmtree(self.tmpdir)
コード例 #24
0
ファイル: test_all.py プロジェクト: underrun/pybsddb
def remove_test_path_directory() :
    test_support.rmtree(get_new_path.prefix)
コード例 #25
0
 def tearDown(self):
     test_support.rmtree(self.tmpdir)
コード例 #26
0
ファイル: test_trace.py プロジェクト: e42s/stackless_historic
 def tearDown(self):
     rmtree(TESTFN)
     unlink(TESTFN)
コード例 #27
0
 def newdirinpath(dir):
     os.mkdir(dir)
     sys.path.insert(0, dir)
     yield
     sys.path.pop(0)
     rmtree(dir)
コード例 #28
0
ファイル: test_rpm.py プロジェクト: olegdenega/junkcode
    def tearDown(self):
	rmtree(self.topdir)
コード例 #29
0
ファイル: test_pydoc.py プロジェクト: redb/MNPP
 def newdirinpath(dir):
     os.mkdir(dir)
     sys.path.insert(0, dir)
     yield
     sys.path.pop(0)
     rmtree(dir)
コード例 #30
0
ファイル: test_trace.py プロジェクト: 0xcc/python-read
 def tearDown(self):
     rmtree(TESTFN)
     unlink(TESTFN)
コード例 #31
0
def remove_test_path_directory() :
    test_support.rmtree(get_new_path.prefix)
コード例 #32
0
 def tearDown(self):
     rmtree(self.path)
     sys.path[:] = self.syspath
コード例 #33
0
ファイル: test_import_jy.py プロジェクト: jythontools/jython
 def tearDownClass(cls):
     td = cls.tmpdir
     if td and os.path.isdir(td):
         test_support.rmtree(td)