~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2011, 2016 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
21
21
from StringIO import StringIO
22
22
import os
23
23
import stat
24
 
import sys
25
24
import tarfile
26
25
import time
27
26
import zipfile
29
28
 
30
29
from bzrlib import (
31
30
    export,
32
 
    osutils,
33
 
    tests,
34
 
    )
35
 
from bzrlib.tests import TestCaseWithTransport
 
31
    )
 
32
from bzrlib.tests import (
 
33
    features,
 
34
    TestCaseWithTransport,
 
35
    )
 
36
from bzrlib.tests.matchers import ContainsNoVfsCalls
36
37
 
37
38
 
38
39
class TestExport(TestCaseWithTransport):
98
99
                         sorted(ball.getnames()))
99
100
 
100
101
    def test_tar_export_unicode_filename(self):
101
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
102
        self.requireFeature(features.UnicodeFilenameFeature)
102
103
        tree = self.make_branch_and_tree('tar')
103
104
        # FIXME: using fname = u'\xe5.txt' below triggers a bug revealed since
104
105
        # bzr.dev revno 4216 but more related to OSX/working trees/unicode than
116
117
 
117
118
    def test_tar_export_unicode_basedir(self):
118
119
        """Test for bug #413406"""
119
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
120
        self.requireFeature(features.UnicodeFilenameFeature)
120
121
        basedir = u'\N{euro sign}'
121
122
        os.mkdir(basedir)
122
123
        self.run_bzr(['init', basedir])
191
192
    def test_tbz2_export(self):
192
193
        self.run_tar_export_disk_and_stdout('tbz2', 'bz2')
193
194
 
194
 
    # TODO: test_xz_export, I don't have pylzma working here to test it.
195
 
 
196
195
    def test_zip_export_unicode(self):
197
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
196
        self.requireFeature(features.UnicodeFilenameFeature)
198
197
        tree = self.make_branch_and_tree('zip')
199
198
        fname = u'\N{Euro Sign}.txt'
200
199
        self.build_tree(['zip/' + fname])
385
384
        tree.commit('setup', timestamp=315532800)
386
385
        self.run_bzr('export --per-file-timestamps t branch')
387
386
        har_st = os.stat('t/har')
388
 
        self.assertEquals(315532800, har_st.st_mtime)
 
387
        self.assertEqual(315532800, har_st.st_mtime)
389
388
 
390
389
    def test_dir_export_partial_tree_per_file_timestamps(self):
391
390
        tree = self.example_branch()
395
394
        tree.commit('setup', timestamp=315532800)
396
395
        self.run_bzr('export --per-file-timestamps tpart branch/subdir')
397
396
        foo_st = os.stat('tpart/foo.txt')
398
 
        self.assertEquals(315532800, foo_st.st_mtime)
 
397
        self.assertEqual(315532800, foo_st.st_mtime)
399
398
 
400
399
    def test_export_directory(self):
401
400
        """Test --directory option"""
404
403
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('latest')))
405
404
        self.check_file_contents('latest/goodbye', 'baz')
406
405
 
 
406
    def test_export_uncommitted(self):
 
407
        """Test --uncommitted option"""
 
408
        self.example_branch()
 
409
        os.chdir('branch')
 
410
        self.build_tree_contents([('goodbye', 'uncommitted data')])
 
411
        self.run_bzr(['export', '--uncommitted', 'latest'])
 
412
        self.check_file_contents('latest/goodbye', 'uncommitted data')
 
413
 
 
414
    def test_export_uncommitted_no_tree(self):
 
415
        """Test --uncommitted option only works with a working tree."""
 
416
        tree = self.example_branch()
 
417
        tree.bzrdir.destroy_workingtree()
 
418
        os.chdir('branch')
 
419
        self.run_bzr_error(
 
420
            ['bzr: ERROR: --uncommitted requires a working tree'],
 
421
            'export --uncommitted latest')
 
422
 
407
423
    def test_zip_export_per_file_timestamps(self):
408
424
        tree = self.example_branch()
409
425
        self.build_tree_contents([('branch/har', 'foo')])
414
430
        self.run_bzr('export --per-file-timestamps test.zip branch')
415
431
        zfile = zipfile.ZipFile('test.zip')
416
432
        info = zfile.getinfo("test/har")
417
 
        self.assertEquals(time.localtime(timestamp)[:6], info.date_time)
 
433
        self.assertEqual(time.localtime(timestamp)[:6], info.date_time)
 
434
 
 
435
 
 
436
class TestSmartServerExport(TestCaseWithTransport):
 
437
 
 
438
    def test_simple_export(self):
 
439
        self.setup_smart_server_with_call_log()
 
440
        t = self.make_branch_and_tree('branch')
 
441
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
442
        t.add("foo")
 
443
        t.commit("message")
 
444
        self.reset_smart_call_log()
 
445
        out, err = self.run_bzr(['export', "foo.tar.gz", self.get_url('branch')])
 
446
        # This figure represent the amount of work to perform this use case. It
 
447
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
448
        # being too low. If rpc_count increases, more network roundtrips have
 
449
        # become necessary for this use case. Please do not adjust this number
 
450
        # upwards without agreement from bzr's network support maintainers.
 
451
        self.assertLength(7, self.hpss_calls)
 
452
        self.assertLength(1, self.hpss_connections)
 
453
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)