build_utils_test.py (1433B)
1 #!/usr/bin/env python3 2 # Copyright 2018 The Chromium Authors 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 import collections 7 import os 8 import sys 9 import unittest 10 11 sys.path.insert( 12 0, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))) 13 from util import build_utils 14 15 _DEPS = collections.OrderedDict() 16 _DEPS['a'] = [] 17 _DEPS['b'] = [] 18 _DEPS['c'] = ['a'] 19 _DEPS['d'] = ['a'] 20 _DEPS['e'] = ['f'] 21 _DEPS['f'] = ['a', 'd'] 22 _DEPS['g'] = [] 23 _DEPS['h'] = ['d', 'b', 'f'] 24 _DEPS['i'] = ['f'] 25 26 27 class BuildUtilsTest(unittest.TestCase): 28 def testGetSortedTransitiveDependencies_all(self): 29 TOP = _DEPS.keys() 30 EXPECTED = ['a', 'b', 'c', 'd', 'f', 'e', 'g', 'h', 'i'] 31 actual = build_utils.GetSortedTransitiveDependencies(TOP, _DEPS.get) 32 self.assertEqual(EXPECTED, actual) 33 34 def testGetSortedTransitiveDependencies_leaves(self): 35 TOP = ['c', 'e', 'g', 'h', 'i'] 36 EXPECTED = ['a', 'c', 'd', 'f', 'e', 'g', 'b', 'h', 'i'] 37 actual = build_utils.GetSortedTransitiveDependencies(TOP, _DEPS.get) 38 self.assertEqual(EXPECTED, actual) 39 40 def testGetSortedTransitiveDependencies_leavesReverse(self): 41 TOP = ['i', 'h', 'g', 'e', 'c'] 42 EXPECTED = ['a', 'd', 'f', 'i', 'b', 'h', 'g', 'e', 'c'] 43 actual = build_utils.GetSortedTransitiveDependencies(TOP, _DEPS.get) 44 self.assertEqual(EXPECTED, actual) 45 46 47 if __name__ == '__main__': 48 unittest.main()