common_merge_script_tests.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright 2018 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import json
  5. import os
  6. import shutil
  7. import tempfile
  8. import unittest
  9. class CommandLineTest(unittest.TestCase):
  10. # pylint: disable=super-with-arguments
  11. def __init__(self, methodName, module):
  12. super(CommandLineTest, self).__init__(methodName)
  13. self._module = module
  14. # pylint: disable=super-with-arguments
  15. def setUp(self):
  16. self.temp_dir = tempfile.mkdtemp(prefix='common_merge_script_tests')
  17. def tearDown(self):
  18. shutil.rmtree(self.temp_dir)
  19. def test_accepts_task_output_dir(self):
  20. task_output_dir = os.path.join(self.temp_dir, 'task_output_dir')
  21. shard0_dir = os.path.join(task_output_dir, '0')
  22. os.makedirs(shard0_dir)
  23. summary_json = os.path.join(task_output_dir, 'summary.json')
  24. with open(summary_json, 'w') as summary_file:
  25. summary_contents = {
  26. u'shards': [
  27. {
  28. u'state': u'COMPLETED',
  29. },
  30. ],
  31. }
  32. json.dump(summary_contents, summary_file)
  33. shard0_json = os.path.join(shard0_dir, 'output.json')
  34. with open(shard0_json, 'w') as shard0_file:
  35. json.dump({}, shard0_file)
  36. output_json = os.path.join(self.temp_dir, 'merged.json')
  37. raw_args = [
  38. '--task-output-dir', task_output_dir,
  39. '--summary-json', summary_json,
  40. '--output-json', output_json,
  41. shard0_json,
  42. ]
  43. self.assertEqual(0, self._module.main(raw_args))