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

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 +x file permission 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
« no previous file with comments | « tools/variations/fieldtrial_to_struct.py ('k') | tools/variations/fieldtrial_util.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '--year=2015',
57 'unittest_data/test_config.json'
58 ])
59 header_filename = test_ouput_filename + '.h'
60 with open(header_filename, 'r') as header:
61 test_header = header.read()
62 with open('unittest_data/expected_output.h', 'r') as expected:
63 expected_header = expected.read()
64 self.assertEqual(expected_header, test_header)
65 os.unlink(header_filename)
66
67 cc_filename = test_ouput_filename + '.cc'
68 with open(cc_filename, 'r') as cc:
69 test_cc = cc.read()
70 with open('unittest_data/expected_output.cc', 'r') as expected:
71 expected_cc = expected.read()
72 self.assertEqual(expected_cc, test_cc)
73 os.unlink(cc_filename)
74
75 if __name__ == '__main__':
76 unittest.main()
OLDNEW
« no previous file with comments | « tools/variations/fieldtrial_to_struct.py ('k') | tools/variations/fieldtrial_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698