Merge lp://staging/~doxxx/bzr-xmloutput/test-ls-xml into lp://staging/bzr-xmloutput

Proposed by Gordon Tyler
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: not available
Merged at revision: not available
Proposed branch: lp://staging/~doxxx/bzr-xmloutput/test-ls-xml
Merge into: lp://staging/bzr-xmloutput
Prerequisite: lp://staging/~doxxx/bzr-xmloutput/482901
Diff against target: 340 lines (+307/-1)
3 files modified
tests/__init__.py (+1/-0)
tests/test_ls_xml.py (+300/-0)
tests/test_version_xml.py (+6/-1)
To merge this branch: bzr merge lp://staging/~doxxx/bzr-xmloutput/test-ls-xml
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+14892@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Gordon Tyler (doxxx) wrote :

Adds tests for the xmlls command that mirror the tests of the bzr ls command.

lp:~doxxx/bzr-xmloutput/482901 is required to fix two failures in the test which are related to bug #482901.

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Thanks a *LOT* for porting the tests

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/__init__.py'
2--- tests/__init__.py 2009-03-26 17:41:38 +0000
3+++ tests/__init__.py 2009-11-15 20:40:25 +0000
4@@ -25,6 +25,7 @@
5
6 def load_tests(basic_tests, module, loader):
7 testmod_names = [
8+ 'test_ls_xml',
9 'test_version_xml',
10 'test_status_xml',
11 'test_log_xml',
12
13=== added file 'tests/test_ls_xml.py'
14--- tests/test_ls_xml.py 1970-01-01 00:00:00 +0000
15+++ tests/test_ls_xml.py 2009-11-15 20:40:25 +0000
16@@ -0,0 +1,300 @@
17+# Copyright (C) 2006 Canonical Ltd
18+#
19+# This program is free software; you can redistribute it and/or modify
20+# it under the terms of the GNU General Public License as published by
21+# the Free Software Foundation; either version 2 of the License, or
22+# (at your option) any later version.
23+#
24+# This program is distributed in the hope that it will be useful,
25+# but WITHOUT ANY WARRANTY; without even the implied warranty of
26+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+# GNU General Public License for more details.
28+#
29+# You should have received a copy of the GNU General Public License
30+# along with this program; if not, write to the Free Software
31+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32+
33+"""Blackbox tests of 'bzr xmlls'"""
34+
35+import os
36+
37+from bzrlib import ignores
38+from bzrlib.tests import TestCaseWithTransport
39+from bzrlib.trace import mutter
40+from bzrlib.xml_serializer import elementtree as elementtree
41+fromstring = elementtree.ElementTree.fromstring
42+
43+
44+class TestLSXML(TestCaseWithTransport):
45+
46+ def setUp(self):
47+ super(TestLSXML, self).setUp()
48+
49+ # Create a simple branch that can be used in testing
50+ ignores._set_user_ignores(['user-ignore'])
51+
52+ self.wt = self.make_branch_and_tree('.')
53+ self.build_tree_contents([
54+ ('.bzrignore', '*.pyo\n'),
55+ ('a', 'hello\n'),
56+ ])
57+
58+ def run_xmlls(self, args=None):
59+ command = 'xmlls'
60+ if args:
61+ command += ' ' + args
62+ out, err = self.run_bzr(command)
63+ self.assertEqual('', err)
64+ # parse the output and convert it into more usable structure:
65+ # [ { 'kind': 'file, 'path': 'foo', ... }, ... ]
66+ lst = fromstring(out)
67+ items = []
68+ for item_elem in lst.findall('item'):
69+ item = {}
70+ for attr in item_elem.getchildren():
71+ item[attr.tag] = attr.text
72+ items.append(item)
73+ return items
74+
75+ #def test_lsxml_null_verbose(self):
76+ # # Can't supply both
77+ # self.run_bzr_error(['Cannot set both --verbose and --null'],
78+ # 'xmlls --verbose --null')
79+
80+ def test_lsxml_basic(self):
81+ """Test the abilities of 'bzr xmlls'"""
82+ expected_items = [{'kind': 'file',
83+ 'path': '.bzrignore',
84+ 'status_kind': 'unknown'},
85+ {'kind': 'file',
86+ 'path': 'a',
87+ 'status_kind': 'unknown'}]
88+ self.assertEquals(expected_items, self.run_xmlls())
89+ self.assertEquals(expected_items, self.run_xmlls('--unknown'))
90+ self.assertEquals([], self.run_xmlls('--ignored'))
91+ self.assertEquals([], self.run_xmlls('--versioned'))
92+ self.assertEquals([], self.run_xmlls('-V'))
93+ self.assertEquals(expected_items,
94+ self.run_xmlls('--unknown --ignored --version'))
95+ self.assertEquals(expected_items,
96+ self.run_xmlls('--unknown --ignored -V'))
97+ self.assertEquals([], self.run_xmlls('--ignored -V'))
98+
99+ def test_lsxml_added(self):
100+ self.wt.add(['a'], ['a-id'])
101+ expected_items = [{'kind': 'file',
102+ 'path': '.bzrignore',
103+ 'status_kind': 'unknown'},
104+ {'id': 'a-id',
105+ 'kind': 'file',
106+ 'path': 'a',
107+ 'status_kind': 'versioned'}]
108+ self.assertEquals(expected_items, self.run_xmlls())
109+
110+ self.wt.commit('add')
111+ self.build_tree(['subdir/'])
112+ expected_items = [{'kind': 'file',
113+ 'path': '.bzrignore',
114+ 'status_kind': 'unknown'},
115+ {'id': 'a-id',
116+ 'kind': 'file',
117+ 'path': 'a',
118+ 'status_kind': 'versioned'},
119+ {'kind': 'directory',
120+ 'path': 'subdir',
121+ 'status_kind': 'unknown'}]
122+ self.assertEquals(expected_items, self.run_xmlls())
123+
124+ self.build_tree(['subdir/b'])
125+ self.wt.add(['subdir/', 'subdir/b', '.bzrignore'],
126+ ['subdir-id', 'subdirb-id', 'bzrignore-id'])
127+ expected_items = [{'id': 'bzrignore-id',
128+ 'kind': 'file',
129+ 'path': '.bzrignore',
130+ 'status_kind': 'versioned'},
131+ {'id': 'a-id',
132+ 'kind': 'file',
133+ 'path': 'a',
134+ 'status_kind': 'versioned'},
135+ {'id': 'subdir-id',
136+ 'kind': 'directory',
137+ 'path': 'subdir',
138+ 'status_kind': 'versioned'},
139+ {'id': 'subdirb-id',
140+ 'kind': 'file',
141+ 'path': 'subdir/b',
142+ 'status_kind': 'versioned'}]
143+ self.assertEquals(expected_items, self.run_xmlls())
144+
145+ def test_lsxml_non_recursive(self):
146+ self.build_tree(['subdir/', 'subdir/b'])
147+ self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'],
148+ ['a-id', 'subdir-id', 'subdirb-id', 'bzrignore-id'])
149+ expected_items = [{'id': 'bzrignore-id',
150+ 'kind': 'file',
151+ 'path': '.bzrignore',
152+ 'status_kind': 'versioned'},
153+ {'id': 'a-id',
154+ 'kind': 'file',
155+ 'path': 'a',
156+ 'status_kind': 'versioned'},
157+ {'id': 'subdir-id',
158+ 'kind': 'directory',
159+ 'path': 'subdir',
160+ 'status_kind': 'versioned'}]
161+ self.assertEquals(expected_items, self.run_xmlls('--non-recursive'))
162+
163+ # Check what happens in a sub-directory
164+ os.chdir('subdir')
165+ expcted_items = [{'id': 'subdirb-id',
166+ 'kind': 'file',
167+ 'path': 'b',
168+ 'status_kind': 'versioned'}]
169+ self.assertEquals(expcted_items, self.run_xmlls())
170+ expcted_items = [{'id': 'subdirb-id',
171+ 'kind': 'file',
172+ 'path': 'subdir/b',
173+ 'status_kind': 'versioned'}]
174+ self.assertEquals(expcted_items, self.run_xmlls('--from-root'))
175+ expected_items = [{'id': 'subdirb-id',
176+ 'kind': 'file',
177+ 'path': 'subdir/b',
178+ 'status_kind': 'versioned'}]
179+ self.assertEquals(expected_items,
180+ self.run_xmlls('--from-root --non-recursive'))
181+
182+ def test_lsxml_path(self):
183+ """If a path is specified, files are listed with that prefix"""
184+ self.build_tree(['subdir/', 'subdir/b'])
185+ self.wt.add(['subdir', 'subdir/b'], ['subdir-id', 'subdirb-id'])
186+ expected_items = [{'id': 'subdirb-id',
187+ 'kind': 'file',
188+ 'path': 'subdir/b',
189+ 'status_kind': 'versioned'}]
190+ self.assertEquals(expected_items, self.run_xmlls('subdir'))
191+
192+ # Check what happens in a sub-directory, referring to parent
193+ os.chdir('subdir')
194+ expected_items = [{'kind': 'file',
195+ 'path': '../.bzrignore',
196+ 'status_kind': 'unknown'},
197+ {'kind': 'file',
198+ 'path': '../a',
199+ 'status_kind': 'unknown'},
200+ {'id': 'subdir-id',
201+ 'kind': 'directory',
202+ 'path': '../subdir',
203+ 'status_kind': 'versioned'},
204+ {'id': 'subdirb-id',
205+ 'kind': 'file',
206+ 'path': '../subdir/b',
207+ 'status_kind': 'versioned'}]
208+ self.assertEquals(expected_items, self.run_xmlls('..'))
209+ self.run_bzr_error(['cannot specify both --from-root and PATH'],
210+ 'xmlls --from-root ..')
211+
212+ def test_lsxml_revision(self):
213+ self.wt.add(['a'], ['a-id'])
214+ self.wt.commit('add')
215+
216+ self.build_tree(['subdir/'])
217+
218+ # Check what happens when we supply a specific revision
219+ expected_items = [{'id': 'a-id',
220+ 'kind': 'file',
221+ 'path': 'a',
222+ 'status_kind': 'versioned'}]
223+ self.assertEquals(expected_items, self.run_xmlls('--revision 1'))
224+
225+ os.chdir('subdir')
226+ self.assertEquals([], self.run_xmlls('--revision 1'))
227+
228+ def test_lsxml_branch(self):
229+ """If a branch is specified, files are listed from it"""
230+ self.build_tree(['subdir/', 'subdir/b'])
231+ self.wt.add(['subdir', 'subdir/b'], ['subdir-id', 'subdirb-id'])
232+ self.wt.commit('committing')
233+ branch = self.make_branch('branchdir')
234+ branch.pull(self.wt.branch)
235+ expected_items = [{'id': 'subdir-id',
236+ 'kind': 'directory',
237+ 'path': 'branchdir/subdir',
238+ 'status_kind': 'versioned'},
239+ {'id': 'subdirb-id',
240+ 'kind': 'file',
241+ 'path': 'branchdir/subdir/b',
242+ 'status_kind': 'versioned'}]
243+ self.assertEquals(expected_items, self.run_xmlls('branchdir'))
244+ self.assertEquals(expected_items,
245+ self.run_xmlls('branchdir --revision 1'))
246+
247+ def test_lsxml_ignored(self):
248+ # Now try to do ignored files.
249+ self.wt.add(['a', '.bzrignore'], ['a-id', 'bzrignore-id'])
250+ self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
251+ expected_items = [{'id': 'bzrignore-id',
252+ 'kind': 'file',
253+ 'path': '.bzrignore',
254+ 'status_kind': 'versioned'},
255+ {'id': 'a-id',
256+ 'kind': 'file',
257+ 'path': 'a',
258+ 'status_kind': 'versioned'},
259+ {'kind': 'file',
260+ 'path': 'blah.py',
261+ 'status_kind': 'unknown'},
262+ {'kind': 'file',
263+ 'path': 'blah.pyo',
264+ 'status_kind': 'ignored'},
265+ {'kind': 'file',
266+ 'path': 'user-ignore',
267+ 'status_kind': 'ignored'}]
268+ self.assertEquals(expected_items, self.run_xmlls())
269+ expected_items = [{'kind': 'file',
270+ 'path': 'blah.pyo',
271+ 'pattern': '*.pyo',
272+ 'status_kind': 'ignored'},
273+ {'kind': 'file',
274+ 'path': 'user-ignore',
275+ 'pattern': 'user-ignore',
276+ 'status_kind': 'ignored'}]
277+ self.assertEquals(expected_items, self.run_xmlls('--ignored'))
278+ expected_items = [{'kind': 'file',
279+ 'path': 'blah.py',
280+ 'status_kind': 'unknown'}]
281+ self.assertEquals(expected_items, self.run_xmlls('--unknown'))
282+ expected_items = [{'id': 'bzrignore-id',
283+ 'kind': 'file',
284+ 'path': '.bzrignore',
285+ 'status_kind': 'versioned'},
286+ {'id': 'a-id',
287+ 'kind': 'file',
288+ 'path': 'a',
289+ 'status_kind': 'versioned'}]
290+ self.assertEquals(expected_items, self.run_xmlls('--versioned'))
291+
292+ def test_lsxml_kinds(self):
293+ self.build_tree(['subdir/'])
294+ expected_items = [{'kind': 'file',
295+ 'path': '.bzrignore',
296+ 'status_kind': 'unknown'},
297+ {'kind': 'file',
298+ 'path': 'a',
299+ 'status_kind': 'unknown'}]
300+ self.assertEquals(expected_items, self.run_xmlls('--kind=file'))
301+ expected_items = [{'kind': 'directory',
302+ 'path': 'subdir',
303+ 'status_kind': 'unknown'}]
304+ self.assertEquals(expected_items, self.run_xmlls('--kind=directory'))
305+ self.assertEquals([], self.run_xmlls('--kind=symlink'))
306+ self.run_bzr_error(['invalid kind specified'], 'xmlls --kind=pile')
307+
308+ def test_lsxml_path_nonrecursive(self):
309+ expected_items = [{'kind': 'file',
310+ 'path': '%s/.bzrignore' % self.test_dir,
311+ 'status_kind': 'unknown'},
312+ {'kind': 'file',
313+ 'path': '%s/a' % self.test_dir,
314+ 'status_kind': 'unknown'}]
315+ self.assertEquals(expected_items,
316+ self.run_xmlls('%s --non-recursive' % self.test_dir))
317
318=== modified file 'tests/test_version_xml.py'
319--- tests/test_version_xml.py 2009-09-23 03:29:47 +0000
320+++ tests/test_version_xml.py 2009-11-15 20:40:25 +0000
321@@ -16,6 +16,8 @@
322
323 """Black-box tests for bzr version."""
324
325+import sys
326+
327 import bzrlib
328 from bzrlib import osutils, trace
329 from bzrlib.tests import (
330@@ -40,7 +42,10 @@
331 self.assertEquals(1, len(versionElem.findall('bazaar/configuration')))
332 self.assertEquals(1, len(versionElem.findall('bazaar/log_file')))
333 self.assertEquals(1, len(versionElem.findall('bazaar/copyright')))
334- self.assertEquals(1, len(versionElem.findall('python/executable')))
335+ if sys.platform == "win32":
336+ self.assertEquals(1, len(versionElem.findall('python/dll')))
337+ else:
338+ self.assertEquals(1, len(versionElem.findall('python/executable')))
339 self.assertEquals(1, len(versionElem.findall('python/version')))
340 self.assertEquals(1, len(versionElem.findall('python/standard_library')))
341

Subscribers

People subscribed via source and target branches

to all changes: