OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 Google Inc. All rights reserved. | 3 # Copyright (c) 2012 Google Inc. 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 """Unit tests for the common.py file.""" | 7 """Unit tests for the common.py file.""" |
8 | 8 |
9 import gyp.common | 9 import gyp.common |
10 import unittest | 10 import unittest |
| 11 import sys |
11 | 12 |
12 | 13 |
13 class TestTopologicallySorted(unittest.TestCase): | 14 class TestTopologicallySorted(unittest.TestCase): |
14 def test_Valid(self): | 15 def test_Valid(self): |
15 """Test that sorting works on a valid graph with one possible order.""" | 16 """Test that sorting works on a valid graph with one possible order.""" |
16 graph = { | 17 graph = { |
17 'a': ['b', 'c'], | 18 'a': ['b', 'c'], |
18 'b': [], | 19 'b': [], |
19 'c': ['d'], | 20 'c': ['d'], |
20 'd': ['b'], | 21 'd': ['b'], |
(...skipping 12 matching lines...) Expand all Loading... |
33 'c': ['d'], | 34 'c': ['d'], |
34 'd': ['a'], | 35 'd': ['a'], |
35 } | 36 } |
36 def GetEdge(node): | 37 def GetEdge(node): |
37 return tuple(graph[node]) | 38 return tuple(graph[node]) |
38 self.assertRaises( | 39 self.assertRaises( |
39 gyp.common.CycleError, gyp.common.TopologicallySorted, | 40 gyp.common.CycleError, gyp.common.TopologicallySorted, |
40 graph.keys(), GetEdge) | 41 graph.keys(), GetEdge) |
41 | 42 |
42 | 43 |
| 44 class TestGetFlavor(unittest.TestCase): |
| 45 """Test that gyp.common.GetFlavor works as intended""" |
| 46 original_platform = '' |
| 47 |
| 48 def setUp(self): |
| 49 self.original_platform = sys.platform |
| 50 |
| 51 def tearDown(self): |
| 52 sys.platform = self.original_platform |
| 53 |
| 54 def assertFlavor(self, expected, argument, param): |
| 55 sys.platform = argument |
| 56 self.assertEqual(expected, gyp.common.GetFlavor(param)) |
| 57 |
| 58 def test_platform_default(self): |
| 59 self.assertFlavor('freebsd', 'freebsd9' , {}) |
| 60 self.assertFlavor('freebsd', 'freebsd10', {}) |
| 61 self.assertFlavor('solaris', 'sunos5' , {}); |
| 62 self.assertFlavor('solaris', 'sunos' , {}); |
| 63 self.assertFlavor('linux' , 'linux2' , {}); |
| 64 self.assertFlavor('linux' , 'linux3' , {}); |
| 65 |
| 66 def test_param(self): |
| 67 self.assertFlavor('foobar', 'linux2' , {'flavor': 'foobar'}) |
| 68 |
| 69 |
43 if __name__ == '__main__': | 70 if __name__ == '__main__': |
44 unittest.main() | 71 unittest.main() |
OLD | NEW |