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.
7 import fieldtrial_to_struct
11 class FieldTrialToStruct(unittest
.TestCase
):
13 def test_FieldTrialToDescription(self
):
17 'group_name': 'Group1',
24 'Study2': [{'group_name': 'OtherGroup'}]
26 result
= fieldtrial_to_struct
._FieldTrialConfigToDescription
(config
)
29 'kFieldTrialConfig': {
33 'group_name': 'Group1',
35 {'key': 'x', 'value': '1'},
36 {'key': 'y', 'value': '2'}
41 'group_name': 'OtherGroup'
47 self
.assertEqual(expected
, result
)
49 def test_FieldTrialToStructMain(self
):
51 '../../chrome/common/variations/fieldtrial_testing_config_schema.json')
52 test_ouput_filename
= 'test_ouput'
53 fieldtrial_to_struct
.main([
55 '--output=' + test_ouput_filename
,
57 'unittest_data/test_config.json'
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
)
67 cc_filename
= test_ouput_filename
+ '.cc'
68 with
open(cc_filename
, 'r') as cc
:
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
)
75 if __name__
== '__main__':