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

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

Issue 2259443003: Capture All Groups in the Field Trial For Testing Studies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR Feedback and Change NOTREACHED() to DLOG(ERROR) Created 4 years, 4 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
1 # Copyright 2015 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import unittest
6 6
7 import fieldtrial_to_struct 7 import fieldtrial_to_struct
8 import os 8 import os
9 9
10 10
11 class FieldTrialToStruct(unittest.TestCase): 11 class FieldTrialToStruct(unittest.TestCase):
12 12
13 def test_FieldTrialToDescription(self): 13 def test_FieldTrialToDescription(self):
14 config = { 14 config = {
15 'Study1': [ 15 'Study1': [
16 { 16 {
17 'group_name': 'Group1', 17 'group_name': 'Group1',
18 'params': { 18 'params': {
19 'x': '1', 19 'x': '1',
20 'y': '2' 20 'y': '2'
21 }, 21 },
22 'enable_features': ['A', 'B'], 22 'enable_features': ['A', 'B'],
23 'disable_features': ['C'] 23 'disable_features': ['C']
24 },
25 {
26 'group_name': 'Group2',
27 'params': {
28 'x': '3',
29 'y': '4'
30 },
31 'enable_features': ['D', 'E'],
32 'disable_features': ['F']
24 } 33 }
25 ], 34 ],
26 'Study2': [{'group_name': 'OtherGroup'}] 35 'Study2': [{'group_name': 'OtherGroup'}]
27 } 36 }
28 result = fieldtrial_to_struct._FieldTrialConfigToDescription(config) 37 result = fieldtrial_to_struct._FieldTrialConfigToDescription(config)
29 expected = { 38 expected = {
30 'elements': { 39 'elements': {
31 'kFieldTrialConfig': { 40 'kFieldTrialConfig': {
32 'groups': [ 41 'studies': [
33 { 42 {
34 'study': 'Study1', 43 'name': 'Study1',
35 'group_name': 'Group1', 44 'groups': [
36 'params': [ 45 {
37 {'key': 'x', 'value': '1'}, 46 'name': 'Group1',
38 {'key': 'y', 'value': '2'} 47 'params': [
48 {'key': 'x', 'value': '1'},
49 {'key': 'y', 'value': '2'}
50 ],
51 'enable_features': ['A', 'B'],
52 'disable_features': ['C']
53 },
54 {
55 'name': 'Group2',
56 'params': [
57 {'key': 'x', 'value': '3'},
58 {'key': 'y', 'value': '4'}
59 ],
60 'enable_features': ['D', 'E'],
61 'disable_features': ['F']
62 },
39 ], 63 ],
40 'enable_features': ['A',
41 'B'],
42 'disable_features': ['C']
43 }, 64 },
44 { 65 {
45 'study': 'Study2', 66 'name': 'Study2',
46 'group_name': 'OtherGroup' 67 'groups': [{'name': 'OtherGroup'}]
47 } 68 },
48 ] 69 ]
49 } 70 }
50 } 71 }
51 } 72 }
52 self.maxDiff = None 73 self.maxDiff = None
53 self.assertEqual(expected, result) 74 self.assertEqual(expected, result)
54 75
55 def test_FieldTrialToStructMain(self): 76 def test_FieldTrialToStructMain(self):
56 schema = ( 77 schema = (
57 '../../chrome/common/variations/fieldtrial_testing_config_schema.json') 78 '../../chrome/common/variations/fieldtrial_testing_config_schema.json')
58 test_ouput_filename = 'test_ouput' 79 test_output_filename = 'test_output'
59 fieldtrial_to_struct.main([ 80 fieldtrial_to_struct.main([
60 '--schema=' + schema, 81 '--schema=' + schema,
61 '--output=' + test_ouput_filename, 82 '--output=' + test_output_filename,
62 '--year=2015', 83 '--year=2015',
63 'unittest_data/test_config.json' 84 'unittest_data/test_config.json'
64 ]) 85 ])
65 header_filename = test_ouput_filename + '.h' 86 header_filename = test_output_filename + '.h'
66 with open(header_filename, 'r') as header: 87 with open(header_filename, 'r') as header:
67 test_header = header.read() 88 test_header = header.read()
68 with open('unittest_data/expected_output.h', 'r') as expected: 89 with open('unittest_data/expected_output.h', 'r') as expected:
69 expected_header = expected.read() 90 expected_header = expected.read()
70 self.assertEqual(expected_header, test_header) 91 self.assertEqual(expected_header, test_header)
71 os.unlink(header_filename) 92 os.unlink(header_filename)
72 93
73 cc_filename = test_ouput_filename + '.cc' 94 cc_filename = test_output_filename + '.cc'
74 with open(cc_filename, 'r') as cc: 95 with open(cc_filename, 'r') as cc:
75 test_cc = cc.read() 96 test_cc = cc.read()
76 with open('unittest_data/expected_output.cc', 'r') as expected: 97 with open('unittest_data/expected_output.cc', 'r') as expected:
77 expected_cc = expected.read() 98 expected_cc = expected.read()
78 self.assertEqual(expected_cc, test_cc) 99 self.assertEqual(expected_cc, test_cc)
79 os.unlink(cc_filename) 100 os.unlink(cc_filename)
80 101
81 if __name__ == '__main__': 102 if __name__ == '__main__':
82 unittest.main() 103 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698