autoninja_test.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2022 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. import multiprocessing
  6. import os
  7. import os.path
  8. import sys
  9. import unittest
  10. import unittest.mock
  11. ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  12. sys.path.insert(0, ROOT_DIR)
  13. import autoninja
  14. class AutoninjaTest(unittest.TestCase):
  15. def test_autoninja(self):
  16. autoninja.main([])
  17. def test_autoninja_goma(self):
  18. with unittest.mock.patch(
  19. 'os.path.exists',
  20. return_value=True) as mock_exists, unittest.mock.patch(
  21. 'autoninja.open', unittest.mock.mock_open(
  22. read_data='use_goma=true')) as mock_open, unittest.mock.patch(
  23. 'subprocess.call', return_value=0):
  24. args = autoninja.main([]).split()
  25. mock_exists.assert_called()
  26. mock_open.assert_called_once()
  27. self.assertIn('-j', args)
  28. parallel_j = int(args[args.index('-j') + 1])
  29. self.assertGreater(parallel_j, multiprocessing.cpu_count())
  30. if __name__ == '__main__':
  31. unittest.main()