/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/test_export.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
 
1
# Copyright (C) 2009, 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Tests for breezy.export."""
 
17
"""Tests for bzrlib.export."""
18
18
 
 
19
from cStringIO import StringIO
19
20
import os
20
21
import tarfile
21
22
import time
22
23
import zipfile
23
24
 
24
 
from .. import (
 
25
from bzrlib import (
25
26
    errors,
26
27
    export,
27
28
    tests,
28
29
    )
29
 
from ..export import get_root_name
30
 
from ..export.tar_exporter import export_tarball_generator
31
 
from ..sixish import (
32
 
    BytesIO,
33
 
    )
34
 
from . import features
 
30
from bzrlib.export import get_root_name
 
31
from bzrlib.export.tar_exporter import export_tarball_generator
 
32
from bzrlib.tests import features
35
33
 
36
34
 
37
35
class TestDirExport(tests.TestCaseWithTransport):
48
46
    def test_empty(self):
49
47
        wt = self.make_branch_and_tree('.')
50
48
        export.export(wt, 'target', format="dir")
51
 
        self.assertEqual([], os.listdir("target"))
 
49
        self.assertEquals([], os.listdir("target"))
52
50
 
53
51
    def test_symlink(self):
54
52
        self.requireFeature(features.SymlinkFeature)
103
101
    def test_files_same_timestamp(self):
104
102
        builder = self.make_branch_builder('source')
105
103
        builder.start_series()
106
 
        builder.build_snapshot(None, [
 
104
        builder.build_snapshot(None, None, [
107
105
            ('add', ('', 'root-id', 'directory', '')),
108
106
            ('add', ('a', 'a-id', 'file', 'content\n'))])
109
 
        builder.build_snapshot(None, [
 
107
        builder.build_snapshot(None, None, [
110
108
            ('add', ('b', 'b-id', 'file', 'content\n'))])
111
109
        builder.finish_series()
112
110
        b = builder.get_branch()
133
131
        builder.start_series()
134
132
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
135
133
        a_time = time.mktime((1999, 12, 12, 0, 0, 0, 0, 0, 0))
136
 
        b_time = time.mktime((1980, 0o1, 0o1, 0, 0, 0, 0, 0, 0))
137
 
        builder.build_snapshot(None, [
 
134
        b_time = time.mktime((1980, 01, 01, 0, 0, 0, 0, 0, 0))
 
135
        builder.build_snapshot(None, None, [
138
136
            ('add', ('', 'root-id', 'directory', '')),
139
137
            ('add', ('a', 'a-id', 'file', 'content\n'))],
140
138
            timestamp=a_time)
141
 
        builder.build_snapshot(None, [
 
139
        builder.build_snapshot(None, None, [
142
140
            ('add', ('b', 'b-id', 'file', 'content\n'))],
143
141
            timestamp=b_time)
144
142
        builder.finish_series()
155
153
        builder = self.make_branch_builder('source')
156
154
        builder.start_series()
157
155
        foo_time = time.mktime((1999, 12, 12, 0, 0, 0, 0, 0, 0))
158
 
        builder.build_snapshot(None, [
 
156
        builder.build_snapshot(None, None, [
159
157
            ('add', ('', 'root-id', 'directory', '')),
160
158
            ('add', ('subdir', 'subdir-id', 'directory', '')),
161
159
            ('add', ('subdir/foo.txt', 'foo-id', 'file', 'content\n'))],
168
166
        export.export(tree, 'target', format='dir', subdir='subdir',
169
167
            per_file_timestamps=True)
170
168
        t = self.get_transport('target')
171
 
        self.assertEqual(foo_time, t.stat('foo.txt').st_mtime)
 
169
        self.assertEquals(foo_time, t.stat('foo.txt').st_mtime)
172
170
 
173
171
 
174
172
class TarExporterTests(tests.TestCaseWithTransport):
182
180
        wt.commit("1")
183
181
        export.export(wt, 'target.tar.xz', format="txz")
184
182
        tf = tarfile.open(fileobj=lzma.LZMAFile('target.tar.xz'))
185
 
        self.assertEqual(["target/a"], tf.getnames())
 
183
        self.assertEquals(["target/a"], tf.getnames())
186
184
 
187
185
    def test_lzma(self):
188
186
        self.requireFeature(features.lzma)
193
191
        wt.commit("1")
194
192
        export.export(wt, 'target.tar.lzma', format="tlzma")
195
193
        tf = tarfile.open(fileobj=lzma.LZMAFile('target.tar.lzma'))
196
 
        self.assertEqual(["target/a"], tf.getnames())
 
194
        self.assertEquals(["target/a"], tf.getnames())
197
195
 
198
196
    def test_tgz(self):
199
197
        wt = self.make_branch_and_tree('.')
202
200
        wt.commit("1")
203
201
        export.export(wt, 'target.tar.gz', format="tgz")
204
202
        tf = tarfile.open('target.tar.gz')
205
 
        self.assertEqual(["target/a"], tf.getnames())
 
203
        self.assertEquals(["target/a"], tf.getnames())
206
204
 
207
205
    def test_tgz_ignores_dest_path(self):
208
206
        # The target path should not be a part of the target file.
237
235
        wt.commit("1")
238
236
        export.export(wt, 'target.tar.bz2', format="tbz2")
239
237
        tf = tarfile.open('target.tar.bz2')
240
 
        self.assertEqual(["target/a"], tf.getnames())
 
238
        self.assertEquals(["target/a"], tf.getnames())
241
239
 
242
240
    def test_xz_stdout(self):
243
241
        wt = self.make_branch_and_tree('.')
249
247
        self.build_tree(['a'])
250
248
        wt.add(["a"])
251
249
        wt.commit("1", timestamp=42)
252
 
        target = BytesIO()
 
250
        target = StringIO()
253
251
        ball = tarfile.open(None, "w|", target)
254
252
        wt.lock_read()
255
253
        try:
261
259
        target.seek(0)
262
260
        ball2 = tarfile.open(None, "r", target)
263
261
        self.addCleanup(ball2.close)
264
 
        self.assertEqual(["bar/a"], ball2.getnames())
 
262
        self.assertEquals(["bar/a"], ball2.getnames())
265
263
 
266
264
 
267
265
class ZipExporterTests(tests.TestCaseWithTransport):
268
266
 
269
267
    def test_per_file_timestamps(self):
270
268
        tree = self.make_branch_and_tree('.')
271
 
        self.build_tree_contents([('har', b'foo')])
 
269
        self.build_tree_contents([('har', 'foo')])
272
270
        tree.add('har')
273
271
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
274
272
        timestamp = 347151600
277
275
            per_file_timestamps=True)
278
276
        zfile = zipfile.ZipFile('test.zip')
279
277
        info = zfile.getinfo("test/har")
280
 
        self.assertEqual(time.localtime(timestamp)[:6], info.date_time)
 
278
        self.assertEquals(time.localtime(timestamp)[:6], info.date_time)
281
279
 
282
280
 
283
281
class RootNameTests(tests.TestCase):
284
282
 
285
283
    def test_root_name(self):
286
 
        self.assertEqual('mytest', get_root_name('../mytest.tar'))
287
 
        self.assertEqual('mytar', get_root_name('mytar.tar'))
288
 
        self.assertEqual('mytar', get_root_name('mytar.tar.bz2'))
289
 
        self.assertEqual('tar.tar.tar', get_root_name('tar.tar.tar.tgz'))
290
 
        self.assertEqual('bzr-0.0.5', get_root_name('bzr-0.0.5.tar.gz'))
291
 
        self.assertEqual('bzr-0.0.5', get_root_name('bzr-0.0.5.zip'))
292
 
        self.assertEqual('bzr-0.0.5', get_root_name('bzr-0.0.5'))
293
 
        self.assertEqual('mytar', get_root_name('a/long/path/mytar.tgz'))
294
 
        self.assertEqual('other',
 
284
        self.assertEquals('mytest', get_root_name('../mytest.tar'))
 
285
        self.assertEquals('mytar', get_root_name('mytar.tar'))
 
286
        self.assertEquals('mytar', get_root_name('mytar.tar.bz2'))
 
287
        self.assertEquals('tar.tar.tar', get_root_name('tar.tar.tar.tgz'))
 
288
        self.assertEquals('bzr-0.0.5', get_root_name('bzr-0.0.5.tar.gz'))
 
289
        self.assertEquals('bzr-0.0.5', get_root_name('bzr-0.0.5.zip'))
 
290
        self.assertEquals('bzr-0.0.5', get_root_name('bzr-0.0.5'))
 
291
        self.assertEquals('mytar', get_root_name('a/long/path/mytar.tgz'))
 
292
        self.assertEquals('other',
295
293
            get_root_name('../parent/../dir/other.tbz2'))
296
 
        self.assertEqual('', get_root_name('-'))
 
294
        self.assertEquals('', get_root_name('-'))