~bzr-pqm/bzr/bzr.dev

« 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:
28
28
    tests,
29
29
    )
30
30
from bzrlib.export import get_root_name
31
 
from bzrlib.export.tar_exporter import export_tarball
 
31
from bzrlib.export.tar_exporter import export_tarball_generator
32
32
from bzrlib.tests import features
33
33
 
34
34
 
49
49
        self.assertEquals([], os.listdir("target"))
50
50
 
51
51
    def test_symlink(self):
52
 
        self.requireFeature(tests.SymlinkFeature)
 
52
        self.requireFeature(features.SymlinkFeature)
53
53
        wt = self.make_branch_and_tree('.')
54
54
        os.symlink('source', 'link')
55
55
        wt.add(['link'])
67
67
        self.assertPathExists('target/b')
68
68
        self.assertPathExists('target/b/c')
69
69
 
 
70
    def test_empty_subdir(self):
 
71
        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
 
72
        wt = self.make_branch_and_tree('source')
 
73
        wt.add(['a', 'b', 'b/c'])
 
74
        wt.commit('1')
 
75
        self.build_tree(['target/'])
 
76
        export.export(wt, 'target', format="dir", subdir='')
 
77
        self.assertPathExists('target/a')
 
78
        self.assertPathExists('target/b')
 
79
        self.assertPathExists('target/b/c')
 
80
 
70
81
    def test_to_existing_nonempty_dir_fail(self):
71
82
        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
72
83
        wt = self.make_branch_and_tree('source')
73
84
        wt.add(['a', 'b', 'b/c'])
74
85
        wt.commit('1')
75
86
        self.build_tree(['target/', 'target/foo'])
76
 
        self.assertRaises(errors.BzrError, export.export, wt, 'target', format="dir")
 
87
        self.assertRaises(errors.BzrError,
 
88
            export.export, wt, 'target', format="dir")
77
89
 
78
90
    def test_existing_single_file(self):
79
 
        self.build_tree(['dir1/', 'dir1/dir2/', 'dir1/first', 'dir1/dir2/second'])
 
91
        self.build_tree([
 
92
            'dir1/', 'dir1/dir2/', 'dir1/first', 'dir1/dir2/second'])
80
93
        wtree = self.make_branch_and_tree('dir1')
81
94
        wtree.add(['dir2', 'first', 'dir2/second'])
82
95
        wtree.commit('1')
99
112
        self.addCleanup(b.unlock)
100
113
        tree = b.basis_tree()
101
114
        orig_iter_files_bytes = tree.iter_files_bytes
 
115
 
102
116
        # Make iter_files_bytes slower, so we provoke mtime skew
103
117
        def iter_files_bytes(to_fetch):
104
118
            for thing in orig_iter_files_bytes(to_fetch):
135
149
        self.assertEqual(a_time, t.stat('a').st_mtime)
136
150
        self.assertEqual(b_time, t.stat('b').st_mtime)
137
151
 
 
152
    def test_subdir_files_per_timestamps(self):
 
153
        builder = self.make_branch_builder('source')
 
154
        builder.start_series()
 
155
        foo_time = time.mktime((1999, 12, 12, 0, 0, 0, 0, 0, 0))
 
156
        builder.build_snapshot(None, None, [
 
157
            ('add', ('', 'root-id', 'directory', '')),
 
158
            ('add', ('subdir', 'subdir-id', 'directory', '')),
 
159
            ('add', ('subdir/foo.txt', 'foo-id', 'file', 'content\n'))],
 
160
            timestamp=foo_time)
 
161
        builder.finish_series()
 
162
        b = builder.get_branch()
 
163
        b.lock_read()
 
164
        self.addCleanup(b.unlock)
 
165
        tree = b.basis_tree()
 
166
        export.export(tree, 'target', format='dir', subdir='subdir',
 
167
            per_file_timestamps=True)
 
168
        t = self.get_transport('target')
 
169
        self.assertEquals(foo_time, t.stat('foo.txt').st_mtime)
 
170
 
138
171
 
139
172
class TarExporterTests(tests.TestCaseWithTransport):
140
173
 
209
242
        self.assertRaises(errors.BzrError, export.export, wt, '-',
210
243
            format="txz")
211
244
 
212
 
    def test_export_tarball(self):
 
245
    def test_export_tarball_generator(self):
213
246
        wt = self.make_branch_and_tree('.')
214
247
        self.build_tree(['a'])
215
248
        wt.add(["a"])
218
251
        ball = tarfile.open(None, "w|", target)
219
252
        wt.lock_read()
220
253
        try:
221
 
            export_tarball(wt, ball, "bar")
 
254
            for _ in export_tarball_generator(wt, ball, "bar"):
 
255
                pass
222
256
        finally:
223
257
            wt.unlock()
224
 
        self.assertEquals(["bar/a"], ball.getnames())
225
 
        ball.close()
 
258
        # Ball should now be closed.
 
259
        target.seek(0)
 
260
        ball2 = tarfile.open(None, "r", target)
 
261
        self.addCleanup(ball2.close)
 
262
        self.assertEquals(["bar/a"], ball2.getnames())
226
263
 
227
264
 
228
265
class ZipExporterTests(tests.TestCaseWithTransport):