Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: tools/variations/fieldtrial_to_struct_unittest.py

Issue 1209743002: Generate a static struct from fieldtrial_testing_config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@codegen_nested_structs
Patch Set: add another unittest Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015 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
5 import unittest
6
7 import fieldtrial_to_struct
8 import os
9
10
11 class FieldTrialToStruct(unittest.TestCase):
12
13 def test_FieldTrialToDescription(self):
14 config = {
15 'Study1': [
16 {
17 'group_name': 'Group1',
18 'params': {
19 'x': '1',
20 'y': '2'
21 }
22 }
23 ],
24 'Study2': [{'group_name': 'OtherGroup'}]
25 }
26 result = fieldtrial_to_struct._FieldTrialConfigToDescription(config)
27 expected = {
28 'elements': {
29 'kFieldTrialConfig': {
30 'groups': [
31 {
32 'study': 'Study1',
33 'group_name': 'Group1',
34 'params': [
35 {'key': 'x', 'value': '1'},
36 {'key': 'y', 'value': '2'}
37 ]
38 },
39 {
40 'study': 'Study2',
41 'group_name': 'OtherGroup'
42 }
43 ]
44 }
45 }
46 }
47 self.assertEqual(expected, result)
48
49 def test_FieldTrialToStructMain(self):
50 schema = (
51 '../../chrome/common/variations/fieldtrial_testing_config_schema.json')
52 test_ouput_filename = 'test_ouput'
53 fieldtrial_to_struct.main([
54 '--schema=' + schema,
55 '--output=' + test_ouput_filename,
56 'unittest_data/test_config.json'
57 ])
58 header_filename = test_ouput_filename + '.h'
59 with open(header_filename, 'r') as header:
60 test_header = header.read()
61 with open('unittest_data/expected_output.h', 'r') as expected:
62 expected_header = expected.read()
63 self.assertEqual(expected_header, test_header)
64 os.unlink(header_filename)
65
66 cc_filename = test_ouput_filename + '.cc'
67 with open(cc_filename, 'r') as cc:
68 test_cc = cc.read()
69 with open('unittest_data/expected_output.cc', 'r') as expected:
70 expected_cc = expected.read()
71 self.assertEqual(expected_cc, test_cc)
72 os.unlink(cc_filename)
73
74 if __name__ == '__main__':
75 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698