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