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
25
from bzrlib.tests import (
30
class ExportTest(object):
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)
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)
51
def test_export(self):
53
names = self.get_export_names()
54
self.assertIn('output/file', names)
55
self.assertIn('output/dir', names)
57
def test_export_symlink(self):
58
self.prepare_symlink_export()
59
names = self.get_export_names()
60
self.assertIn('output/link', names)
63
class TestTar(ExportTest, TestCaseWithTree):
67
def get_export_names(self):
68
tf = tarfile.open('output')
75
class TestZip(ExportTest, TestCaseWithTree):
79
def get_export_names(self):
80
zf = zipfile.ZipFile('output')
86
def test_export_symlink(self):
87
self.prepare_symlink_export()
88
names = self.get_export_names()
89
self.assertIn('output/link.lnk', names)
92
class TestDir(ExportTest, TestCaseWithTree):
96
def get_export_names(self):
97
return [osutils.pathjoin('output', name)
98
for name in os.listdir('output')]