update_sdk_tests.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #! /usr/bin/env python
  2. #
  3. # Copyright 2018 The Chromium Authors. All rights reserved.
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. import os
  7. import shutil
  8. import tempfile
  9. import unittest
  10. import update_sdk
  11. class ChangeVersionInGNITests(unittest.TestCase):
  12. def setUp(self):
  13. super(ChangeVersionInGNITests, self).setUp()
  14. self._temp_dir = tempfile.mkdtemp()
  15. self._gni_file_path = os.path.join(self._temp_dir, 'test_file.gni')
  16. def tearDown(self):
  17. shutil.rmtree(self._temp_dir)
  18. super(ChangeVersionInGNITests, self).tearDown()
  19. def testBasic(self):
  20. with open(self._gni_file_path, 'w') as gni_file:
  21. gni_file.write('sample_gn_version_var = "1.2.3.4"')
  22. package = 'sample_package'
  23. arg_version = '2.3.4.5'
  24. gn_args_dict = {package: 'sample_gn_version_var'}
  25. update_sdk.ChangeVersionInGNI(package, arg_version, gn_args_dict,
  26. self._gni_file_path, False)
  27. with open(self._gni_file_path, 'r') as gni_file:
  28. self.assertEqual('sample_gn_version_var = "2.3.4.5"',
  29. gni_file.read().strip())
  30. def testNoQuotes(self):
  31. with open(self._gni_file_path, 'w') as gni_file:
  32. gni_file.write('sample_gn_version_var = 1234')
  33. package = 'sample_package'
  34. arg_version = '2345'
  35. gn_args_dict = {package: 'sample_gn_version_var'}
  36. update_sdk.ChangeVersionInGNI(package, arg_version, gn_args_dict,
  37. self._gni_file_path, False)
  38. with open(self._gni_file_path, 'r') as gni_file:
  39. self.assertEqual('sample_gn_version_var = 2345', gni_file.read().strip())
  40. if __name__ == '__main__':
  41. unittest.main()