OLD | NEW |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 self.assertEqual( | 45 self.assertEqual( |
46 ptree.ToString(), | 46 ptree.ToString(), |
47 self.utf8 + '<manifest>\n' | 47 self.utf8 + '<manifest>\n' |
48 '<project name="foo" path="path/to/foo" workon="True" />\n' | 48 '<project name="foo" path="path/to/foo" workon="True" />\n' |
49 '</manifest>') | 49 '</manifest>') |
50 | 50 |
51 def testAddDup(self): | 51 def testAddDup(self): |
52 ptree = loman.LocalManifest('<manifest>\n</manifest>') | 52 ptree = loman.LocalManifest('<manifest>\n</manifest>') |
53 ptree.Parse() | 53 ptree.Parse() |
54 ptree.AddWorkonProject('foo', 'path/to/foo') | 54 ptree.AddWorkonProject('foo', 'path/to/foo') |
55 self.assertTrue(not ptree.AddWorkonProject('foo', 'path/to/foo')) | 55 self.assertTrue(ptree.AddWorkonProject('foo', 'path/to/foo')) |
56 self.assertTrue(not ptree.AddWorkonProject('foo', 'path/foo')) | 56 self.assertTrue(not ptree.AddWorkonProject('foo', 'path/foo')) |
57 self.assertTrue(not ptree.AddWorkonProject('foobar', 'path/to/foo')) | 57 self.assertTrue(not ptree.AddWorkonProject('foobar', 'path/to/foo')) |
58 | 58 |
59 class MainTest(unittest.TestCase): | 59 class MainTest(unittest.TestCase): |
60 | 60 |
61 def setUp(self): | 61 def setUp(self): |
62 self.utf8 = "<?xml version='1.0' encoding='UTF-8'?>\n" | 62 self.utf8 = "<?xml version='1.0' encoding='UTF-8'?>\n" |
63 self.tiny_manifest = '<manifest>\n</manifest>' | 63 self.tiny_manifest = '<manifest>\n</manifest>' |
64 self.stderr = sys.stderr | 64 self.stderr = sys.stderr |
65 sys.stderr = StringIO.StringIO() | 65 sys.stderr = StringIO.StringIO() |
(...skipping 29 matching lines...) Expand all Loading... |
95 '<project name="foo" path="path/to/foo" workon="True" />\n' | 95 '<project name="foo" path="path/to/foo" workon="True" />\n' |
96 '</manifest>\n') | 96 '</manifest>\n') |
97 | 97 |
98 def testAddDup(self): | 98 def testAddDup(self): |
99 temp = tempfile.NamedTemporaryFile('w') | 99 temp = tempfile.NamedTemporaryFile('w') |
100 print >> temp, '<manifest>\n</manifest>' | 100 print >> temp, '<manifest>\n</manifest>' |
101 temp.flush() | 101 temp.flush() |
102 os.fsync(temp.fileno()) | 102 os.fsync(temp.fileno()) |
103 loman.main(['loman', 'add', '--workon', '-f', | 103 loman.main(['loman', 'add', '--workon', '-f', |
104 temp.name, 'foo', 'path/to/foo']) | 104 temp.name, 'foo', 'path/to/foo']) |
| 105 loman.main(['loman', 'add', '--workon', '-f', |
| 106 temp.name, 'foo', 'path/to/foo']) |
105 self.assertRaises(SystemExit, loman.main, | 107 self.assertRaises(SystemExit, loman.main, |
106 ['loman', 'add', '--workon', '-f', | 108 ['loman', 'add', '--workon', '-f', |
107 temp.name, 'foo', 'path/to/foo']) | 109 temp.name, 'foo', 'path/foo']) |
108 | 110 |
109 | 111 |
110 if __name__ == '__main__': | 112 if __name__ == '__main__': |
111 unittest.main() | 113 unittest.main() |
OLD | NEW |