/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_export.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Black-box tests for bzr export.
25
25
import tarfile
26
26
import zipfile
27
27
 
28
 
from bzrlib.export import (
29
 
    zip_exporter,
 
28
 
 
29
from bzrlib import (
 
30
    export,
 
31
    tests,
30
32
    )
31
 
from bzrlib.tests import TestSkipped
32
33
from bzrlib.tests.blackbox import ExternalBase
33
34
 
34
35
 
59
60
 
60
61
        if sys.version_info < (2, 5, 2) and sys.platform == 'darwin':
61
62
            raise tests.KnownFailure('python %r has a tar related bug, upgrade'
62
 
                                     % sys.version_info)
 
63
                                     % (sys.version_info,))
63
64
        out, err = self.run_bzr('export --format=tgz --root=test -')
64
65
        ball = tarfile.open('', fileobj=StringIO(out))
65
66
        self.assertEqual(['test/a'], sorted(ball.getnames()))
66
67
 
67
68
    def test_tar_export_unicode(self):
68
69
        tree = self.make_branch_and_tree('tar')
69
 
        fname = u'\xe5.txt'
 
70
        # FIXME: using fname = u'\xe5.txt' below triggers a bug revealed since
 
71
        # bzr.dev revno 4216 but more related to OSX/working trees/unicode than
 
72
        # export itself --vila 20090406
 
73
        fname = u'\N{Euro Sign}.txt'
70
74
        try:
71
75
            self.build_tree(['tar/' + fname])
72
76
        except UnicodeError:
73
 
            raise TestSkipped('Unable to represent path %r' % (fname,))
 
77
            raise tests.TestSkipped('Unable to represent path %r' % (fname,))
74
78
        tree.add([fname])
75
79
        tree.commit('first')
76
80
 
81
85
        self.assertEqual(['test/' + fname.encode('utf8')],
82
86
                         sorted(ball.getnames()))
83
87
 
 
88
    def test_tar_export_unicode_basedir(self):
 
89
        """Test for bug #413406"""
 
90
        basedir = u'\N{euro sign}'
 
91
        os.mkdir(basedir)
 
92
        os.chdir(basedir)
 
93
        self.run_bzr(['init', 'branch'])
 
94
        os.chdir('branch')
 
95
        self.run_bzr(['export', '--format', 'tgz', u'test.tar.gz'])
 
96
 
84
97
    def test_zip_export(self):
85
98
        tree = self.make_branch_and_tree('zip')
86
99
        self.build_tree(['zip/a'])
107
120
 
108
121
    def test_zip_export_unicode(self):
109
122
        tree = self.make_branch_and_tree('zip')
110
 
        fname = u'\xe5.txt'
 
123
        fname = u'\N{Euro Sign}.txt'
111
124
        try:
112
125
            self.build_tree(['zip/' + fname])
113
126
        except UnicodeError:
114
 
            raise TestSkipped('Unable to represent path %r' % (fname,))
 
127
            raise tests.TestSkipped('Unable to represent path %r' % (fname,))
115
128
        tree.add([fname])
116
129
        tree.commit('first')
117
130
 
137
150
        # forward slashes
138
151
        self.assertEqual(['test/a', 'test/b/', 'test/b/c', 'test/d/'], names)
139
152
 
140
 
        file_attr = stat.S_IFREG
141
 
        dir_attr = stat.S_IFDIR | zip_exporter.ZIP_DIRECTORY_BIT
 
153
        file_attr = stat.S_IFREG | export.zip_exporter.FILE_PERMISSIONS
 
154
        dir_attr = stat.S_IFDIR | export.zip_exporter.ZIP_DIRECTORY_BIT
142
155
 
143
156
        a_info = zfile.getinfo(names[0])
144
157
        self.assertEqual(file_attr, a_info.external_attr)
187
200
        tree.add('goodbye')
188
201
        tree.commit('setup')
189
202
        return tree
190
 
        
 
203
 
191
204
    def test_basic_directory_export(self):
192
205
        self.example_branch()
193
206
        os.chdir('branch')
262
275
            self.assertEqual('foo', zf.read('pizza/hello'))
263
276
        finally:
264
277
            zf.close()
265
 
        
 
278
 
266
279
        self.run_bzr('export ../first-zip --format=zip -r 1')
267
280
        zf = zipfile.ZipFile('../first-zip')
268
281
        try:
289
302
        tree.commit('more setup')
290
303
        out, err = self.run_bzr('export exported branch/subdir')
291
304
        self.assertEqual(['foo.txt'], os.listdir('exported'))
 
305
 
 
306
    def test_dir_export_per_file_timestamps(self):
 
307
        tree = self.example_branch()
 
308
        self.build_tree_contents([('branch/har', 'foo')])
 
309
        tree.add('har')
 
310
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
 
311
        tree.commit('setup', timestamp=315532800)
 
312
        self.run_bzr('export --per-file-timestamps t branch')
 
313
        har_st = os.stat('t/har')
 
314
        self.assertEquals(315532800, har_st.st_mtime)
 
315