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.
7 """Unit tests for the common.py file."""
14 class TestTopologicallySorted(unittest.TestCase):
16 """Test that sorting works on a valid graph with one possible order."""
24 return tuple(graph[node])
26 gyp.common.TopologicallySorted(graph.keys(), GetEdge),
30 """Test that an exception is thrown on a cyclic graph."""
38 return tuple(graph[node])
40 gyp.common.CycleError, gyp.common.TopologicallySorted,
41 graph.keys(), GetEdge)
44 class TestGetFlavor(unittest.TestCase):
45 """Test that gyp.common.GetFlavor works as intended"""
46 original_platform = ''
49 self.original_platform = sys.platform
52 sys.platform = self.original_platform
54 def assertFlavor(self, expected, argument, param):
55 sys.platform = argument
56 self.assertEqual(expected, gyp.common.GetFlavor(param))
58 def test_platform_default(self):
59 self.assertFlavor('freebsd', 'freebsd9' , {})
60 self.assertFlavor('freebsd', 'freebsd10', {})
61 self.assertFlavor('openbsd', 'openbsd5' , {})
62 self.assertFlavor('solaris', 'sunos5' , {});
63 self.assertFlavor('solaris', 'sunos' , {});
64 self.assertFlavor('linux' , 'linux2' , {});
65 self.assertFlavor('linux' , 'linux3' , {});
68 self.assertFlavor('foobar', 'linux2' , {'flavor': 'foobar'})
71 if __name__ == '__main__':