Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: bin/loman_unittest.py

Issue 3400019: loman: Add support for adding elements from default.xml (Closed) Base URL: http://git.chromium.org/git/crosutils.git
Patch Set: Fixed. Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bin/loman.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Unittests for loman.""" 7 """Unittests for loman."""
8 8
9 import os 9 import os
10 import StringIO 10 import StringIO
(...skipping 20 matching lines...) Expand all
31 def testParse(self): 31 def testParse(self):
32 ptree = loman.LocalManifest(self.tiny_manifest) 32 ptree = loman.LocalManifest(self.tiny_manifest)
33 ptree.Parse() 33 ptree.Parse()
34 self.assertEqual(ptree.ToString(), self.utf8 + self.tiny_manifest) 34 self.assertEqual(ptree.ToString(), self.utf8 + self.tiny_manifest)
35 35
36 def testUTF8Parse(self): 36 def testUTF8Parse(self):
37 ptree = loman.LocalManifest(self.utf8 + self.tiny_manifest) 37 ptree = loman.LocalManifest(self.utf8 + self.tiny_manifest)
38 ptree.Parse() 38 ptree.Parse()
39 self.assertEqual(ptree.ToString(), self.utf8 + self.tiny_manifest) 39 self.assertEqual(ptree.ToString(), self.utf8 + self.tiny_manifest)
40 40
41 def testGetProject(self):
42 ptree = loman.LocalManifest('<manifest>\n</manifest>')
43 ptree.Parse()
44 ptree.AddProject('foo', 'path/to/foo')
45 project = ptree.GetProject('foo')
46 self.assertEqual(project.attrib['name'], 'foo')
47
41 def testAddNew(self): 48 def testAddNew(self):
42 ptree = loman.LocalManifest('<manifest>\n</manifest>') 49 ptree = loman.LocalManifest('<manifest>\n</manifest>')
43 ptree.Parse() 50 ptree.Parse()
44 self.assertTrue(ptree.AddWorkonProject('foo', 'path/to/foo')) 51 self.assertTrue(ptree.AddWorkonProject('foo', 'path/to/foo'))
45 self.assertEqual( 52 self.assertEqual(
46 ptree.ToString(), 53 ptree.ToString(),
47 self.utf8 + '<manifest>\n' 54 self.utf8 + '<manifest>\n'
48 '<project name="foo" path="path/to/foo" workon="True" />\n' 55 '<project name="foo" path="path/to/foo" workon="True" />\n'
49 '</manifest>') 56 '</manifest>')
50 57
58 def testAddNewElement(self):
59 dtree = loman.LocalManifest('<manifest>\n</manifest>')
60 dtree.Parse()
61 dtree.AddProject('foo', 'path/to/foo')
62 ptree = loman.LocalManifest('<manifest>\n</manifest>')
63 ptree.Parse()
64 ptree.AddWorkonProjectElement(dtree.GetProject('foo'))
65 self.assertEqual(
66 ptree.ToString(),
67 self.utf8 + '<manifest>\n'
68 '<project name="foo" path="path/to/foo" workon="True" />\n'
69 '</manifest>')
70
51 def testAddDup(self): 71 def testAddDup(self):
52 ptree = loman.LocalManifest('<manifest>\n</manifest>') 72 ptree = loman.LocalManifest('<manifest>\n</manifest>')
53 ptree.Parse() 73 ptree.Parse()
54 ptree.AddWorkonProject('foo', 'path/to/foo') 74 ptree.AddWorkonProject('foo', 'path/to/foo')
55 self.assertTrue(ptree.AddWorkonProject('foo', 'path/to/foo')) 75 self.assertTrue(ptree.AddWorkonProject('foo', 'path/to/foo'))
56 self.assertTrue(not ptree.AddWorkonProject('foo', 'path/foo')) 76 self.assertTrue(not ptree.AddWorkonProject('foo', 'path/foo'))
57 self.assertTrue(not ptree.AddWorkonProject('foobar', 'path/to/foo')) 77 self.assertTrue(not ptree.AddWorkonProject('foobar', 'path/to/foo'))
58 78
59 class MainTest(unittest.TestCase): 79 class MainTest(unittest.TestCase):
60 80
(...skipping 15 matching lines...) Expand all
76 err_msg = 'Adding of non-workon projects is currently unsupported.\n' 96 err_msg = 'Adding of non-workon projects is currently unsupported.\n'
77 self.assertRaises(SystemExit, loman.main, ['loman', 'add', 'foo', 'path']) 97 self.assertRaises(SystemExit, loman.main, ['loman', 'add', 'foo', 'path'])
78 self.assertTrue(sys.stderr.getvalue().endswith(err_msg)) 98 self.assertTrue(sys.stderr.getvalue().endswith(err_msg))
79 99
80 def testBadCommand(self): 100 def testBadCommand(self):
81 err_msg = 'Unsupported command: bad.\n' 101 err_msg = 'Unsupported command: bad.\n'
82 self.assertRaises(SystemExit, loman.main, ['loman', 'bad', 'foo', 'path']) 102 self.assertRaises(SystemExit, loman.main, ['loman', 'bad', 'foo', 'path'])
83 self.assertTrue(sys.stderr.getvalue().endswith(err_msg)) 103 self.assertTrue(sys.stderr.getvalue().endswith(err_msg))
84 104
85 def testSimpleAdd(self): 105 def testSimpleAdd(self):
106 default = tempfile.NamedTemporaryFile('w')
107 print >> default, '<manifest>\n' \
108 '<project name="foo" path="path/to/foo" />\n' \
109 '</manifest>\n'
110 default.flush()
111 os.fsync(default.fileno())
86 temp = tempfile.NamedTemporaryFile('w') 112 temp = tempfile.NamedTemporaryFile('w')
87 print >> temp, '<manifest>\n</manifest>' 113 print >> temp, '<manifest>\n</manifest>'
88 temp.flush() 114 temp.flush()
89 os.fsync(temp.fileno()) 115 os.fsync(temp.fileno())
90 loman.main(['loman', 'add', '--workon', '-f', 116 loman.main(['loman', 'add', '--workon', '-f', temp.name,
91 temp.name, 'foo', 'path/to/foo']) 117 '-d', default.name, 'foo'])
92 self.assertEqual( 118 self.assertEqual(
93 open(temp.name, 'r').read(), 119 open(temp.name, 'r').read(),
94 self.utf8 + '<manifest>\n' 120 self.utf8 + '<manifest>\n'
95 '<project name="foo" path="path/to/foo" workon="True" />\n' 121 '<project name="foo" path="path/to/foo" workon="True" />\n'
96 '</manifest>\n') 122 '</manifest>\n')
97 123
98 def testAddDup(self): 124 def testIgnoredPath(self):
125 default = tempfile.NamedTemporaryFile('w')
126 print >> default, '<manifest>\n' \
127 '<project name="foo" path="path/to/foo" />\n' \
128 '</manifest>\n'
129 default.flush()
130 os.fsync(default.fileno())
99 temp = tempfile.NamedTemporaryFile('w') 131 temp = tempfile.NamedTemporaryFile('w')
100 print >> temp, '<manifest>\n</manifest>' 132 print >> temp, '<manifest>\n</manifest>'
101 temp.flush() 133 temp.flush()
102 os.fsync(temp.fileno()) 134 os.fsync(temp.fileno())
103 loman.main(['loman', 'add', '--workon', '-f', 135 loman.main(['loman', 'add', '--workon', '-f', temp.name,
104 temp.name, 'foo', 'path/to/foo']) 136 '-d', default.name, 'foo'])
105 loman.main(['loman', 'add', '--workon', '-f', 137
106 temp.name, 'foo', 'path/to/foo']) 138 def testAddDup(self):
139 default = tempfile.NamedTemporaryFile('w')
140 print >> default, '<manifest>\n' \
141 '<project name="foo" path="path/to/foo" />\n' \
142 '</manifest>\n'
143 default.flush()
144 os.fsync(default.fileno())
145 temp = tempfile.NamedTemporaryFile('w')
146 print >> temp, '<manifest>\n' \
147 '<project name="foo" path="bad/path/to/foo" />\n' \
148 '</manifest>\n'
149 temp.flush()
150 os.fsync(temp.fileno())
107 self.assertRaises(SystemExit, loman.main, 151 self.assertRaises(SystemExit, loman.main,
108 ['loman', 'add', '--workon', '-f', 152 ['loman', 'add', '--workon', '-f', temp.name,
109 temp.name, 'foo', 'path/foo']) 153 '-d', default.name, 'foo'])
154
155 def testAddNonexistant(self):
156 default = tempfile.NamedTemporaryFile('w')
157 print >> default, '<manifest>\n' \
158 '<project name="foo" path="path/to/foo" />\n' \
159 '</manifest>\n'
160 default.flush()
161 os.fsync(default.fileno())
162 temp = tempfile.NamedTemporaryFile('w')
163 print >> temp, '<manifest>\n</manifest>'
164 temp.flush()
165 os.fsync(temp.fileno())
166 self.assertRaises(SystemExit, loman.main,
167 ['loman', 'add', '--workon', '-f', temp.name,
168 '-d', default.name, 'bar'])
110 169
111 170
112 if __name__ == '__main__': 171 if __name__ == '__main__':
113 unittest.main() 172 unittest.main()
OLDNEW
« no previous file with comments | « bin/loman.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698