コード例 #1
0
    def test_access_non_normalized(self):
        # Sometimes we can access non-normalized files by their normalized
        # path, verify that normalized_filename returns the right info
        files = [a_circle_d+'.1', a_dots_d+'.2', z_umlat_d+'.3']

        try:
            self.build_tree(files)
        except UnicodeError:
            raise TestSkipped("filesystem cannot create unicode files")

        for fname in files:
            # We should get an exception if we can't open the file at
            # this location.
            path, can_access = osutils.normalized_filename(fname)

            self.assertNotEqual(path, fname)

            # We should always be able to access them from the name
            # they were created with
            f = open(fname, 'rb')
            f.close()

            # And normalized_filename sholud tell us correctly if we can
            # access them by an alternate name
            if can_access:
                f = open(path, 'rb')
                f.close()
            else:
                self.assertRaises(IOError, open, path, 'rb')
コード例 #2
0
    def test_access_normalized(self):
        # We should always be able to access files created with
        # normalized filenames
        # With FAT32 and certain encodings on win32
        # a_circle_c and a_dots_c actually map to the same file
        # adding a suffix kicks in the 'preserving but insensitive'
        # route, and maintains the right files
        files = [a_circle_c+'.1', a_dots_c+'.2', z_umlat_c+'.3',
                 squared_c+'.4', quarter_c+'.5']
        try:
            self.build_tree(files, line_endings='native')
        except UnicodeError:
            raise TestSkipped("filesystem cannot create unicode files")

        for fname in files:
            # We should get an exception if we can't open the file at
            # this location.
            path, can_access = osutils.normalized_filename(fname)

            self.assertEqual(path, fname)
            self.assertTrue(can_access)

            f = open(path, 'rb')
            try:
                # Check the contents
                shouldbe = 'contents of %s%s' % (path.encode('utf8'),
                                                 os.linesep)
                actual = f.read()
            finally:
                f.close()
            self.assertEqual(shouldbe, actual,
                             'contents of %r is incorrect: %r != %r'
                             % (path, shouldbe, actual))