OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 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 |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """Unit tests for the common.py file.""" |
| 8 |
| 9 import gyp.common |
| 10 import unittest |
| 11 |
| 12 |
| 13 class TestTopologicallySorted(unittest.TestCase): |
| 14 def test_Valid(self): |
| 15 """Test that sorting works on a valid graph with one possible order.""" |
| 16 graph = { |
| 17 'a': ['b', 'c'], |
| 18 'b': [], |
| 19 'c': ['d'], |
| 20 'd': ['b'], |
| 21 } |
| 22 def GetEdge(node): |
| 23 return tuple(graph[node]) |
| 24 self.assertEqual( |
| 25 gyp.common.TopologicallySorted(graph.keys(), GetEdge), |
| 26 ['a', 'c', 'd', 'b']) |
| 27 |
| 28 def test_Cycle(self): |
| 29 """Test that an exception is thrown on a cyclic graph.""" |
| 30 graph = { |
| 31 'a': ['b'], |
| 32 'b': ['c'], |
| 33 'c': ['d'], |
| 34 'd': ['a'], |
| 35 } |
| 36 def GetEdge(node): |
| 37 return tuple(graph[node]) |
| 38 self.assertRaises( |
| 39 gyp.common.CycleError, gyp.common.TopologicallySorted, |
| 40 graph.keys(), GetEdge) |
| 41 |
| 42 |
| 43 if __name__ == '__main__': |
| 44 unittest.main() |
OLD | NEW |