1
# Copyright (C) 2011 Canonical Ltd
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.
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.
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
21
from bzrlib.export import export
22
from bzrlib import osutils
23
from bzrlib import tests
24
from bzrlib.tests.per_tree import TestCaseWithTree
27
class ExportTest(object):
29
def prepare_export(self):
30
work_a = self.make_branch_and_tree('wta')
31
self.build_tree_contents(
32
[('wta/file', 'a\nb\nc\nd\n'), ('wta/dir', '')])
33
work_a.add('file', 'file-id')
34
work_a.add('dir', 'dir-id')
35
work_a.commit('add file')
36
tree_a = self.workingtree_to_test_tree(work_a)
37
export(tree_a, 'output', self.exporter)
39
def prepare_symlink_export(self):
40
self.requireFeature(tests.SymlinkFeature)
41
work_a = self.make_branch_and_tree('wta')
42
os.symlink('target', 'wta/link')
43
work_a.add('link', 'link-id')
44
work_a.commit('add link')
45
tree_a = self.workingtree_to_test_tree(work_a)
46
export(tree_a, 'output', self.exporter)
48
def test_export(self):
50
names = self.get_export_names()
51
self.assertIn('output/file', names)
52
self.assertIn('output/dir', names)
54
def test_export_symlink(self):
55
self.prepare_symlink_export()
56
names = self.get_export_names()
57
self.assertIn('output/link', names)
60
class TestTar(ExportTest, TestCaseWithTree):
64
def get_export_names(self):
65
tf = tarfile.open('output')
72
class TestZip(ExportTest, TestCaseWithTree):
76
def get_export_names(self):
77
zf = zipfile.ZipFile('output')
83
def test_export_symlink(self):
84
self.prepare_symlink_export()
85
names = self.get_export_names()
86
self.assertIn('output/link.lnk', names)
89
class TestDir(ExportTest, TestCaseWithTree):
93
def get_export_names(self):
94
return [osutils.pathjoin('output', name)
95
for name in os.listdir('output')]