~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil, Patch Queue Manager, Jelmer Vernooij
  • Date: 2017-01-17 16:20:41 UTC
  • mfrom: (6619.1.2 trunk)
  • Revision ID: tarmac-20170117162041-oo62uk1qsmgc9j31
Merge 2.7 into trunk including fixes for bugs #1622039, #1644003, #1579093 and #1645017. [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2011 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
import os
 
18
import tarfile
 
19
import zipfile
 
20
 
 
21
from bzrlib.export import export
 
22
from bzrlib import osutils
 
23
from bzrlib import tests
 
24
from bzrlib.tests.per_tree import TestCaseWithTree
 
25
from bzrlib.tests import (
 
26
    features,
 
27
    )
 
28
 
 
29
 
 
30
class ExportTest(object):
 
31
 
 
32
    def prepare_export(self):
 
33
        work_a = self.make_branch_and_tree('wta')
 
34
        self.build_tree_contents(
 
35
            [('wta/file', 'a\nb\nc\nd\n'), ('wta/dir', '')])
 
36
        work_a.add('file', 'file-id')
 
37
        work_a.add('dir', 'dir-id')
 
38
        work_a.commit('add file')
 
39
        tree_a = self.workingtree_to_test_tree(work_a)
 
40
        export(tree_a, 'output', self.exporter)
 
41
 
 
42
    def prepare_symlink_export(self):
 
43
        self.requireFeature(features.SymlinkFeature)
 
44
        work_a = self.make_branch_and_tree('wta')
 
45
        os.symlink('target', 'wta/link')
 
46
        work_a.add('link', 'link-id')
 
47
        work_a.commit('add link')
 
48
        tree_a = self.workingtree_to_test_tree(work_a)
 
49
        export(tree_a, 'output', self.exporter)
 
50
 
 
51
    def test_export(self):
 
52
        self.prepare_export()
 
53
        names = self.get_export_names()
 
54
        self.assertIn('output/file', names)
 
55
        self.assertIn('output/dir', names)
 
56
 
 
57
    def test_export_symlink(self):
 
58
        self.prepare_symlink_export()
 
59
        names = self.get_export_names()
 
60
        self.assertIn('output/link', names)
 
61
 
 
62
 
 
63
class TestTar(ExportTest, TestCaseWithTree):
 
64
 
 
65
    exporter = 'tar'
 
66
 
 
67
    def get_export_names(self):
 
68
        tf = tarfile.open('output')
 
69
        try:
 
70
            return tf.getnames()
 
71
        finally:
 
72
            tf.close()
 
73
 
 
74
 
 
75
class TestZip(ExportTest, TestCaseWithTree):
 
76
 
 
77
    exporter = 'zip'
 
78
 
 
79
    def get_export_names(self):
 
80
        zf = zipfile.ZipFile('output')
 
81
        try:
 
82
            return zf.namelist()
 
83
        finally:
 
84
            zf.close()
 
85
 
 
86
    def test_export_symlink(self):
 
87
        self.prepare_symlink_export()
 
88
        names = self.get_export_names()
 
89
        self.assertIn('output/link.lnk', names)
 
90
 
 
91
 
 
92
class TestDir(ExportTest, TestCaseWithTree):
 
93
 
 
94
    exporter = 'dir'
 
95
 
 
96
    def get_export_names(self):
 
97
        return [osutils.pathjoin('output', name)
 
98
                for name in os.listdir('output')]