source: trip-planner-front/node_modules/node-gyp/gyp/pylib/gyp/common_test.py@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
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
9import gyp.common
10import unittest
11import sys
12
13
14class TestTopologicallySorted(unittest.TestCase):
15 def test_Valid(self):
16 """Test that sorting works on a valid graph with one possible order."""
17 graph = {
18 "a": ["b", "c"],
19 "b": [],
20 "c": ["d"],
21 "d": ["b"],
22 }
23
24 def GetEdge(node):
25 return tuple(graph[node])
26
27 self.assertEqual(
28 gyp.common.TopologicallySorted(graph.keys(), GetEdge), ["a", "c", "d", "b"]
29 )
30
31 def test_Cycle(self):
32 """Test that an exception is thrown on a cyclic graph."""
33 graph = {
34 "a": ["b"],
35 "b": ["c"],
36 "c": ["d"],
37 "d": ["a"],
38 }
39
40 def GetEdge(node):
41 return tuple(graph[node])
42
43 self.assertRaises(
44 gyp.common.CycleError, gyp.common.TopologicallySorted, graph.keys(), GetEdge
45 )
46
47
48class TestGetFlavor(unittest.TestCase):
49 """Test that gyp.common.GetFlavor works as intended"""
50
51 original_platform = ""
52
53 def setUp(self):
54 self.original_platform = sys.platform
55
56 def tearDown(self):
57 sys.platform = self.original_platform
58
59 def assertFlavor(self, expected, argument, param):
60 sys.platform = argument
61 self.assertEqual(expected, gyp.common.GetFlavor(param))
62
63 def test_platform_default(self):
64 self.assertFlavor("freebsd", "freebsd9", {})
65 self.assertFlavor("freebsd", "freebsd10", {})
66 self.assertFlavor("openbsd", "openbsd5", {})
67 self.assertFlavor("solaris", "sunos5", {})
68 self.assertFlavor("solaris", "sunos", {})
69 self.assertFlavor("linux", "linux2", {})
70 self.assertFlavor("linux", "linux3", {})
71 self.assertFlavor("linux", "linux", {})
72
73 def test_param(self):
74 self.assertFlavor("foobar", "linux2", {"flavor": "foobar"})
75
76
77if __name__ == "__main__":
78 unittest.main()
Note: See TracBrowser for help on using the repository browser.