~bzr-pqm/bzr/bzr.dev

5809.3.3 by Aaron Bentley
Test directories.
1
# Copyright (C) 2011 Canonical Ltd
5809.3.1 by Aaron Bentley
Switch to iter_entries_by_dir.
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
5809.3.5 by Aaron Bentley
Remove unused code.
17
import os
5809.3.3 by Aaron Bentley
Test directories.
18
import tarfile
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
19
import zipfile
5809.3.1 by Aaron Bentley
Switch to iter_entries_by_dir.
20
21
from bzrlib.export import export
5809.3.9 by Aaron Bentley
Test exporting directories.
22
from bzrlib import osutils
5809.3.5 by Aaron Bentley
Remove unused code.
23
from bzrlib import tests
5809.3.1 by Aaron Bentley
Switch to iter_entries_by_dir.
24
from bzrlib.tests.per_tree import TestCaseWithTree
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
25
from bzrlib.tests import (
26
    features,
27
    )
5809.3.1 by Aaron Bentley
Switch to iter_entries_by_dir.
28
29
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
30
class ExportTest(object):
5809.3.1 by Aaron Bentley
Switch to iter_entries_by_dir.
31
5809.3.9 by Aaron Bentley
Test exporting directories.
32
    def prepare_export(self):
5809.3.1 by Aaron Bentley
Switch to iter_entries_by_dir.
33
        work_a = self.make_branch_and_tree('wta')
5809.3.3 by Aaron Bentley
Test directories.
34
        self.build_tree_contents(
35
            [('wta/file', 'a\nb\nc\nd\n'), ('wta/dir', '')])
5809.3.2 by Aaron Bentley
Support PreviewTree.has_filename.
36
        work_a.add('file', 'file-id')
5809.3.3 by Aaron Bentley
Test directories.
37
        work_a.add('dir', 'dir-id')
5809.3.2 by Aaron Bentley
Support PreviewTree.has_filename.
38
        work_a.commit('add file')
5809.3.3 by Aaron Bentley
Test directories.
39
        tree_a = self.workingtree_to_test_tree(work_a)
5809.3.9 by Aaron Bentley
Test exporting directories.
40
        export(tree_a, 'output', self.exporter)
5809.3.4 by Aaron Bentley
Add symlink testing.
41
5809.3.9 by Aaron Bentley
Test exporting directories.
42
    def prepare_symlink_export(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
43
        self.requireFeature(features.SymlinkFeature)
5809.3.4 by Aaron Bentley
Add symlink testing.
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)
5809.3.9 by Aaron Bentley
Test exporting directories.
49
        export(tree_a, 'output', self.exporter)
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
50
51
    def test_export(self):
5809.3.9 by Aaron Bentley
Test exporting directories.
52
        self.prepare_export()
53
        names = self.get_export_names()
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
54
        self.assertIn('output/file', names)
55
        self.assertIn('output/dir', names)
56
57
    def test_export_symlink(self):
5809.3.9 by Aaron Bentley
Test exporting directories.
58
        self.prepare_symlink_export()
59
        names = self.get_export_names()
5809.3.4 by Aaron Bentley
Add symlink testing.
60
        self.assertIn('output/link', names)
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
61
62
63
class TestTar(ExportTest, TestCaseWithTree):
64
5809.3.9 by Aaron Bentley
Test exporting directories.
65
    exporter = 'tar'
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
66
5809.3.9 by Aaron Bentley
Test exporting directories.
67
    def get_export_names(self):
5809.3.12 by Vincent Ladeuil
Avoid using 'with' until we drop python2.4/2.5 compatibility.
68
        tf = tarfile.open('output')
69
        try:
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
70
            return tf.getnames()
5809.3.12 by Vincent Ladeuil
Avoid using 'with' until we drop python2.4/2.5 compatibility.
71
        finally:
72
            tf.close()
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
73
74
75
class TestZip(ExportTest, TestCaseWithTree):
76
5809.3.9 by Aaron Bentley
Test exporting directories.
77
    exporter = 'zip'
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
78
5809.3.9 by Aaron Bentley
Test exporting directories.
79
    def get_export_names(self):
5809.3.12 by Vincent Ladeuil
Avoid using 'with' until we drop python2.4/2.5 compatibility.
80
        zf = zipfile.ZipFile('output')
81
        try:
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
82
            return zf.namelist()
5809.3.12 by Vincent Ladeuil
Avoid using 'with' until we drop python2.4/2.5 compatibility.
83
        finally:
84
            zf.close()
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
85
86
    def test_export_symlink(self):
5809.3.9 by Aaron Bentley
Test exporting directories.
87
        self.prepare_symlink_export()
88
        names = self.get_export_names()
5809.3.8 by Aaron Bentley
Test zip files with all tree types.
89
        self.assertIn('output/link.lnk', names)
5809.3.9 by Aaron Bentley
Test exporting directories.
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')]