gclient_eval: use ordered dict

This is a step towards implementing conditions.

Bug: 570091
Change-Id: I99467033082d96021854c23dcff3fc2b56f995b4
Reviewed-on: https://chromium-review.googlesource.com/517107
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Paweł Hajdan Jr. <phajdan.jr@chromium.org>
changes/07/517107/3
Paweł Hajdan, Jr 9 years ago committed by Commit Bot
parent b760dceea3
commit 7cf96a4b4b

@ -3,6 +3,7 @@
# found in the LICENSE file.
import ast
import collections
from third_party import schema
@ -115,8 +116,9 @@ def _gclient_eval(node_or_string, global_scope, filename='<unknown>'):
elif isinstance(node, ast.List):
return list(map(_convert, node.elts))
elif isinstance(node, ast.Dict):
return dict((_convert(k), _convert(v))
for k, v in zip(node.keys, node.values))
return collections.OrderedDict(
(_convert(k), _convert(v))
for k, v in zip(node.keys, node.values))
elif isinstance(node, ast.Name):
if node.id not in _allowed_names:
raise ValueError(

@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import itertools
import logging
import os
import sys
@ -58,6 +59,13 @@ class GClientEvalTest(unittest.TestCase):
self.assertIn(
'unexpected AST node: <_ast.ListComp object', str(cm.exception))
def test_dict_ordered(self):
for test_case in itertools.permutations(range(4)):
input_data = ['{'] + ['"%s": "%s",' % (n, n) for n in test_case] + ['}']
expected = [(str(n), str(n)) for n in test_case]
result = gclient_eval._gclient_eval(''.join(input_data), {})
self.assertEqual(expected, result.items())
class GClientExecTest(unittest.TestCase):
def test_basic(self):

Loading…
Cancel
Save