Esempio n. 1
0
 def tearDown(self):
     for f in glob.glob(self.fn + "*"):
         os_helper.unlink(f)
Esempio n. 2
0
 def test_realpath_relative(self):
     try:
         os.symlink(posixpath.relpath(ABSTFN+"1"), ABSTFN)
         self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
     finally:
         os_helper.unlink(ABSTFN)
Esempio n. 3
0
 def tearDown(self):
     for suffix in ["", "1", "2"]:
         os_helper.unlink(os_helper.TESTFN + suffix)
         safe_rmdir(os_helper.TESTFN + suffix)
Esempio n. 4
0
 def tearDown(self):
     unlink(TESTFN)
Esempio n. 5
0
 def tearDown(self):
     os_helper.unlink(os_helper.TESTFN)
Esempio n. 6
0
 def tearDown(self):
     unlink(self.codefile)
     unlink(self.coverfile)
Esempio n. 7
0
    def test_issue5604(self):
        # Test cannot cover imp.load_compiled function.
        # Martin von Loewis note what shared library cannot have non-ascii
        # character because init_xxx function cannot be compiled
        # and issue never happens for dynamic modules.
        # But sources modified to follow generic way for processing paths.

        # the return encoding could be uppercase or None
        fs_encoding = sys.getfilesystemencoding()

        # covers utf-8 and Windows ANSI code pages
        # one non-space symbol from every page
        # (http://en.wikipedia.org/wiki/Code_page)
        known_locales = {
            'utf-8': b'\xc3\xa4',
            'cp1250': b'\x8C',
            'cp1251': b'\xc0',
            'cp1252': b'\xc0',
            'cp1253': b'\xc1',
            'cp1254': b'\xc0',
            'cp1255': b'\xe0',
            'cp1256': b'\xe0',
            'cp1257': b'\xc0',
            'cp1258': b'\xc0',
        }

        if sys.platform == 'darwin':
            self.assertEqual(fs_encoding, 'utf-8')
            # Mac OS X uses the Normal Form D decomposition
            # http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
            special_char = b'a\xcc\x88'
        else:
            special_char = known_locales.get(fs_encoding)

        if not special_char:
            self.skipTest(
                "can't run this test with %s as filesystem encoding" %
                fs_encoding)
        decoded_char = special_char.decode(fs_encoding)
        temp_mod_name = 'test_imp_helper_' + decoded_char
        test_package_name = 'test_imp_helper_package_' + decoded_char
        init_file_name = os.path.join(test_package_name, '__init__.py')
        try:
            # if the curdir is not in sys.path the test fails when run with
            # ./python ./Lib/test/regrtest.py test_imp
            sys.path.insert(0, os.curdir)
            with open(temp_mod_name + '.py', 'w', encoding="utf-8") as file:
                file.write('a = 1\n')
            file, filename, info = imp.find_module(temp_mod_name)
            with file:
                self.assertIsNotNone(file)
                self.assertTrue(filename[:-3].endswith(temp_mod_name))
                self.assertEqual(info[0], '.py')
                self.assertEqual(info[1], 'r')
                self.assertEqual(info[2], imp.PY_SOURCE)

                mod = imp.load_module(temp_mod_name, file, filename, info)
                self.assertEqual(mod.a, 1)

            with warnings.catch_warnings():
                warnings.simplefilter('ignore')
                mod = imp.load_source(temp_mod_name, temp_mod_name + '.py')
            self.assertEqual(mod.a, 1)

            with warnings.catch_warnings():
                warnings.simplefilter('ignore')
                if not sys.dont_write_bytecode:
                    mod = imp.load_compiled(
                        temp_mod_name,
                        imp.cache_from_source(temp_mod_name + '.py'))
            self.assertEqual(mod.a, 1)

            if not os.path.exists(test_package_name):
                os.mkdir(test_package_name)
            with open(init_file_name, 'w', encoding="utf-8") as file:
                file.write('b = 2\n')
            with warnings.catch_warnings():
                warnings.simplefilter('ignore')
                package = imp.load_package(test_package_name,
                                           test_package_name)
            self.assertEqual(package.b, 2)
        finally:
            del sys.path[0]
            for ext in ('.py', '.pyc'):
                os_helper.unlink(temp_mod_name + ext)
                os_helper.unlink(init_file_name + ext)
            os_helper.rmtree(test_package_name)
            os_helper.rmtree('__pycache__')
Esempio n. 8
0
 def tearDown(self):
     if self.g is not None:
         self.g.close()
     unlink(filename)
Esempio n. 9
0
 def setUp(self):
     unlink(TESTFN)
Esempio n. 10
0
 def tearDown(self):
     os_helper.unlink(self.filename)
Esempio n. 11
0
def delete_files():
    # we don't know the precise name the underlying database uses
    # so we use glob to locate all names
    for f in glob.glob(glob.escape(_fname) + "*"):
        os_helper.unlink(f)
Esempio n. 12
0
 def setUp(self):
     os_helper.unlink(self.filename)
Esempio n. 13
0
    def test_builtin_zip(self):
        self.assertEqual(list(zip()), [])
        self.assertEqual(list(zip(*[])), [])
        self.assertEqual(list(zip(*[(1, 2), 'ab'])), [(1, 'a'), (2, 'b')])

        self.assertRaises(TypeError, zip, None)
        self.assertRaises(TypeError, zip, range(10), 42)
        self.assertRaises(TypeError, zip, range(10), zip)

        self.assertEqual(list(zip(IteratingSequenceClass(3))), [(0, ), (1, ),
                                                                (2, )])
        self.assertEqual(list(zip(SequenceClass(3))), [(0, ), (1, ), (2, )])

        d = {"one": 1, "two": 2, "three": 3}
        self.assertEqual(list(d.items()), list(zip(d, d.values())))

        # Generate all ints starting at constructor arg.
        class IntsFrom:
            def __init__(self, start):
                self.i = start

            def __iter__(self):
                return self

            def __next__(self):
                i = self.i
                self.i = i + 1
                return i

        f = open(TESTFN, "w")
        try:
            f.write("a\n" "bbb\n" "cc\n")
        finally:
            f.close()
        f = open(TESTFN, "r")
        try:
            self.assertEqual(list(zip(IntsFrom(0), f, IntsFrom(-100))),
                             [(0, "a\n", -100), (1, "bbb\n", -99),
                              (2, "cc\n", -98)])
        finally:
            f.close()
            try:
                unlink(TESTFN)
            except OSError:
                pass

        self.assertEqual(list(zip(range(5))), [(i, ) for i in range(5)])

        # Classes that lie about their lengths.
        class NoGuessLen5:
            def __getitem__(self, i):
                if i >= 5:
                    raise IndexError
                return i

        class Guess3Len5(NoGuessLen5):
            def __len__(self):
                return 3

        class Guess30Len5(NoGuessLen5):
            def __len__(self):
                return 30

        def lzip(*args):
            return list(zip(*args))

        self.assertEqual(len(Guess3Len5()), 3)
        self.assertEqual(len(Guess30Len5()), 30)
        self.assertEqual(lzip(NoGuessLen5()), lzip(range(5)))
        self.assertEqual(lzip(Guess3Len5()), lzip(range(5)))
        self.assertEqual(lzip(Guess30Len5()), lzip(range(5)))

        expected = [(i, i) for i in range(5)]
        for x in NoGuessLen5(), Guess3Len5(), Guess30Len5():
            for y in NoGuessLen5(), Guess3Len5(), Guess30Len5():
                self.assertEqual(lzip(x, y), expected)
Esempio n. 14
0
    def tearDown(self):
        try:
            sys.path.remove(str(self.zip_path))
        except ValueError:
            pass

        try:
            del sys.path_importer_cache[str(self.zip_path)]
            del sys.modules[self.data.__name__]
        except KeyError:
            pass

        try:
<<<<<<< HEAD
            unlink(self.zip_path)
=======
            support.unlink(self.zip_path)
>>>>>>> 3.9
        except OSError:
            # If the test fails, this will probably fail too
            pass

    def test_contents_does_not_keep_open(self):
        c = resources.contents('ziptestdata')
        self.zip_path.unlink()
<<<<<<< HEAD
        del c
=======
>>>>>>> 3.9
Esempio n. 15
0
 def test_unlink(self):
     with open(TESTFN, "w", encoding="utf-8") as f:
         pass
     os_helper.unlink(TESTFN)
     self.assertFalse(os.path.exists(TESTFN))
     os_helper.unlink(TESTFN)
Esempio n. 16
0
def tearDownModule():
    unlink(TESTFN)
    unlink(TESTFN2)
Esempio n. 17
0
 def tearDown(self):
     rmtree(TESTFN)
     unlink(TESTFN)
Esempio n. 18
0
 def tearDown(self):
     unlink(self.filename)
Esempio n. 19
0
 def tearDown(self):
     os_helper.unlink(self.fname1)
     os_helper.unlink(self.fname2)
     os_helper.unlink(self.fname3)
Esempio n. 20
0
 def tearDown(self):
     if self.f:
         self.f.close()
     os_helper.unlink(TESTFN)
Esempio n. 21
0
 def tearDownClass(cls):
     os_helper.unlink(os_helper.TESTFN)
     super().tearDownClass()
Esempio n. 22
0
 def tearDown(self):
     if self.f and not self.f.closed:
         self.f.close()
     unlink(TESTFN)
Esempio n. 23
0
def temporary_filename():
    filename = tempfile.mktemp()
    try:
        yield filename
    finally:
        os_helper.unlink(filename)
Esempio n. 24
0
 def testEmptyFile(self):
     os_helper.unlink(TESTMOD)
     os_helper.create_empty_file(TESTMOD)
     self.assertZipFailure(TESTMOD)
Esempio n. 25
0
 def tearDown(self):
     os_helper.unlink(self.addr)
     BaseTestAPI.tearDown(self)
Esempio n. 26
0
 def testNotZipFile(self):
     os_helper.unlink(TESTMOD)
     fp = open(TESTMOD, 'w+')
     fp.write('a' * 22)
     fp.close()
     self.assertZipFailure(TESTMOD)
Esempio n. 27
0
    def test_realpath_symlink_loops(self):
        # Bug #930024, return the path unchanged if we get into an infinite
        # symlink loop in non-strict mode (default).
        try:
            os.symlink(ABSTFN, ABSTFN)
            self.assertEqual(realpath(ABSTFN), ABSTFN)

            os.symlink(ABSTFN+"1", ABSTFN+"2")
            os.symlink(ABSTFN+"2", ABSTFN+"1")
            self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1")
            self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2")

            self.assertEqual(realpath(ABSTFN+"1/x"), ABSTFN+"1/x")
            self.assertEqual(realpath(ABSTFN+"1/.."), dirname(ABSTFN))
            self.assertEqual(realpath(ABSTFN+"1/../x"), dirname(ABSTFN) + "/x")
            os.symlink(ABSTFN+"x", ABSTFN+"y")
            self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "y"),
                             ABSTFN + "y")
            self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "1"),
                             ABSTFN + "1")

            os.symlink(basename(ABSTFN) + "a/b", ABSTFN+"a")
            self.assertEqual(realpath(ABSTFN+"a"), ABSTFN+"a/b")

            os.symlink("../" + basename(dirname(ABSTFN)) + "/" +
                       basename(ABSTFN) + "c", ABSTFN+"c")
            self.assertEqual(realpath(ABSTFN+"c"), ABSTFN+"c")

            # Test using relative path as well.
            with os_helper.change_cwd(dirname(ABSTFN)):
                self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
        finally:
            os_helper.unlink(ABSTFN)
            os_helper.unlink(ABSTFN+"1")
            os_helper.unlink(ABSTFN+"2")
            os_helper.unlink(ABSTFN+"y")
            os_helper.unlink(ABSTFN+"c")
            os_helper.unlink(ABSTFN+"a")
Esempio n. 28
0
def tearDownModule():
    os_helper.unlink(TESTMOD)
Esempio n. 29
0
    def test_realpath_symlink_loops_strict(self):
        # Bug #43757, raise OSError if we get into an infinite symlink loop in
        # strict mode.
        try:
            os.symlink(ABSTFN, ABSTFN)
            self.assertRaises(OSError, realpath, ABSTFN, strict=True)

            os.symlink(ABSTFN+"1", ABSTFN+"2")
            os.symlink(ABSTFN+"2", ABSTFN+"1")
            self.assertRaises(OSError, realpath, ABSTFN+"1", strict=True)
            self.assertRaises(OSError, realpath, ABSTFN+"2", strict=True)

            self.assertRaises(OSError, realpath, ABSTFN+"1/x", strict=True)
            self.assertRaises(OSError, realpath, ABSTFN+"1/..", strict=True)
            self.assertRaises(OSError, realpath, ABSTFN+"1/../x", strict=True)
            os.symlink(ABSTFN+"x", ABSTFN+"y")
            self.assertRaises(OSError, realpath,
                              ABSTFN+"1/../" + basename(ABSTFN) + "y", strict=True)
            self.assertRaises(OSError, realpath,
                              ABSTFN+"1/../" + basename(ABSTFN) + "1", strict=True)

            os.symlink(basename(ABSTFN) + "a/b", ABSTFN+"a")
            self.assertRaises(OSError, realpath, ABSTFN+"a", strict=True)

            os.symlink("../" + basename(dirname(ABSTFN)) + "/" +
                       basename(ABSTFN) + "c", ABSTFN+"c")
            self.assertRaises(OSError, realpath, ABSTFN+"c", strict=True)

            # Test using relative path as well.
            with os_helper.change_cwd(dirname(ABSTFN)):
                self.assertRaises(OSError, realpath, basename(ABSTFN), strict=True)
        finally:
            os_helper.unlink(ABSTFN)
            os_helper.unlink(ABSTFN+"1")
            os_helper.unlink(ABSTFN+"2")
            os_helper.unlink(ABSTFN+"y")
            os_helper.unlink(ABSTFN+"c")
            os_helper.unlink(ABSTFN+"a")
Esempio n. 30
0
 def tearDown(self):
     for f in (TESTFN, TESTFN2):
         unlink(f)