21
from bzrlib.osutils import supports_executable, _fs_enc
22
from bzrlib.tests import SymlinkFeature, TestSkipped, TestNotApplicable
23
from bzrlib.tests.tree_implementations import TestCaseWithTree
26
class TestPathContentSummary(TestCaseWithTree):
26
from bzrlib.tests import tree_implementations
29
class TestPathContentSummary(tree_implementations.TestCaseWithTree):
28
31
def _convert_tree(self, tree):
29
result = TestCaseWithTree._convert_tree(self, tree)
32
result = tree_implementations.TestCaseWithTree._convert_tree(self, tree)
31
34
self.addCleanup(result.unlock)
34
37
def test_symlink_content_summary(self):
35
self.requireFeature(SymlinkFeature)
38
self.requireFeature(tests.SymlinkFeature)
36
39
tree = self.make_branch_and_tree('tree')
37
40
os.symlink('target', 'tree/path')
40
43
self.assertEqual(('symlink', None, None, 'target'), summary)
42
45
def test_unicode_symlink_content_summary(self):
43
self.requireFeature(SymlinkFeature)
46
self.requireFeature(tests.SymlinkFeature)
47
self.requireFeature(tests.UnicodeFilenameFeature)
44
48
tree = self.make_branch_and_tree('tree')
46
os.symlink('target', u'tree/\u03b2-path'.encode(_fs_enc))
49
'This platform does not support unicode file paths.')
49
os.symlink('target', u'tree/\u03b2-path'.encode(osutils._fs_enc))
51
50
tree.add([u'\u03b2-path'])
52
51
summary = self._convert_tree(tree).path_content_summary(u'\u03b2-path')
53
52
self.assertEqual(('symlink', None, None, 'target'), summary)
55
54
def test_unicode_symlink_target_summary(self):
56
self.requireFeature(SymlinkFeature)
55
self.requireFeature(tests.SymlinkFeature)
56
self.requireFeature(tests.UnicodeFilenameFeature)
57
57
tree = self.make_branch_and_tree('tree')
59
os.symlink(u'tree/\u03b2-path'.encode(_fs_enc), 'tree/link')
62
'This platform does not support unicode file paths.')
58
os.symlink(u'tree/\u03b2-path'.encode(osutils._fs_enc), 'tree/link')
65
60
summary = self._convert_tree(tree).path_content_summary('link')
66
61
self.assertEqual(('symlink', None, None, u'tree/\u03b2-path'), summary)
71
66
self.assertEqual(('missing', None, None, None), summary)
73
68
def test_file_content_summary_executable(self):
74
if not supports_executable():
75
raise TestNotApplicable()
69
if not osutils.supports_executable():
70
raise tests.TestNotApplicable()
76
71
tree = self.make_branch_and_tree('tree')
77
72
self.build_tree(['tree/path'])
99
94
# size must be known
100
95
self.assertEqual(22, summary[1])
102
if supports_executable:
97
if osutils.supports_executable:
103
98
self.assertEqual(False, summary[2])
105
100
self.assertEqual(None, summary[2])
119
114
subtree = self.make_branch_and_tree('tree/path')
120
115
tree.add(['path'])
121
116
if not tree.branch.repository._format.supports_tree_reference:
122
raise TestSkipped("Tree references not supported.")
117
raise tests.TestNotApplicable("Tree references not supported.")
123
118
summary = self._convert_tree(tree).path_content_summary('path')
124
119
self.assertEqual(4, len(summary))
125
120
self.assertEqual('tree-reference', summary[0])