licenses_test.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. # Copyright (c) 2017 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. """Unit tests for //tools/licenses.py.
  6. """
  7. import os
  8. import sys
  9. import unittest
  10. REPOSITORY_ROOT = os.path.abspath(os.path.join(
  11. os.path.dirname(__file__), '..', '..'))
  12. sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools'))
  13. import licenses
  14. class LicensesTest(unittest.TestCase):
  15. def test_get_third_party_deps_from_gn_deps_output(self):
  16. def construct_absolute_path(path):
  17. return os.path.join(REPOSITORY_ROOT, *path.split('/')).replace(
  18. os.sep, '/')
  19. prune_path = next(iter(licenses.PRUNE_PATHS))
  20. gn_deps = [
  21. construct_absolute_path('net/BUILD.gn'),
  22. construct_absolute_path('third_party/zlib/BUILD.gn'),
  23. construct_absolute_path('third_party/cld_3/src/src/BUILD.gn'),
  24. construct_absolute_path(prune_path + '/BUILD.gn'),
  25. ]
  26. third_party_deps = licenses.GetThirdPartyDepsFromGNDepsOutput(
  27. '\n'.join(gn_deps), None)
  28. # 'net' is not in the output because it's not a third_party dependency.
  29. #
  30. # It must return the direct sub-directory of "third_party". So it should
  31. # return 'third_party/cld_3', not 'third_party/cld_3/src/src'.
  32. assert third_party_deps == set([
  33. os.path.join('third_party', 'zlib'),
  34. os.path.join('third_party', 'cld_3'),
  35. ])
  36. if __name__ == '__main__':
  37. unittest.main()