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 7import os 8import shutil 9import tempfile 10import unittest 11 12import update_sdk 13 14 15class ChangeVersionInGNITests(unittest.TestCase): 16 17 def setUp(self): 18 super(ChangeVersionInGNITests, self).setUp() 19 self._temp_dir = tempfile.mkdtemp() 20 self._gni_file_path = os.path.join(self._temp_dir, 'test_file.gni') 21 22 def tearDown(self): 23 shutil.rmtree(self._temp_dir) 24 super(ChangeVersionInGNITests, self).tearDown() 25 26 def testBasic(self): 27 with open(self._gni_file_path, 'w') as gni_file: 28 gni_file.write('sample_gn_version_var = "1.2.3.4"') 29 package = 'sample_package' 30 arg_version = '2.3.4.5' 31 gn_args_dict = {package: 'sample_gn_version_var'} 32 update_sdk.ChangeVersionInGNI(package, arg_version, gn_args_dict, 33 self._gni_file_path, False) 34 with open(self._gni_file_path, 'r') as gni_file: 35 self.assertEqual('sample_gn_version_var = "2.3.4.5"', 36 gni_file.read().strip()) 37 38 def testNoQuotes(self): 39 with open(self._gni_file_path, 'w') as gni_file: 40 gni_file.write('sample_gn_version_var = 1234') 41 package = 'sample_package' 42 arg_version = '2345' 43 gn_args_dict = {package: 'sample_gn_version_var'} 44 update_sdk.ChangeVersionInGNI(package, arg_version, gn_args_dict, 45 self._gni_file_path, False) 46 with open(self._gni_file_path, 'r') as gni_file: 47 self.assertEqual('sample_gn_version_var = 2345', gni_file.read().strip()) 48 49 50if __name__ == '__main__': 51 unittest.main() 52