gclient_eval: Handle non-string variables.

Bug: 877902
Change-Id: I77a1f213318d1e09ae050c2ea0113b2976bd259e
Reviewed-on: https://chromium-review.googlesource.com/1191928
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
This commit is contained in:
Edward Lemur
2018-08-28 00:54:45 +00:00
committed by Commit Bot
parent f57841b78b
commit 5cc2afd9b8
2 changed files with 23 additions and 1 deletions

View File

@@ -602,7 +602,9 @@ def RenderDEPSFile(gclient_dict):
def _UpdateAstString(tokens, node, value):
position = node.lineno, node.col_offset
quote_char = tokens[position][1][0]
quote_char = ''
if isinstance(node, ast.Str):
quote_char = tokens[position][1][0]
tokens[position][1] = quote_char + value + quote_char
node.s = value

View File

@@ -325,6 +325,26 @@ class VarTest(unittest.TestCase):
'}',
]))
def test_gets_and_sets_var_non_string(self):
local_scope = gclient_eval.Exec('\n'.join([
'vars = {',
' "foo": True,',
'}',
]))
result = gclient_eval.GetVar(local_scope, 'foo')
self.assertEqual(result, True)
gclient_eval.SetVar(local_scope, 'foo', 'False')
result = gclient_eval.RenderDEPSFile(local_scope)
self.assertEqual(result, '\n'.join([
'vars = {',
' "foo": False,',
'}',
]))
def test_add_preserves_formatting(self):
before = [
'# Copyright stuff',