Add ICU message format support
[chromium-blink-merge.git] / tools / variations / fieldtrial_to_struct_unittest.py
blobf1980ac55466d5aca1e768ced5722c6fee4d5de6
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.
5 import unittest
7 import fieldtrial_to_struct
8 import os
11 class FieldTrialToStruct(unittest.TestCase):
13 def test_FieldTrialToDescription(self):
14 config = {
15 'Study1': [
17 'group_name': 'Group1',
18 'params': {
19 'x': '1',
20 'y': '2'
24 'Study2': [{'group_name': 'OtherGroup'}]
26 result = fieldtrial_to_struct._FieldTrialConfigToDescription(config)
27 expected = {
28 'elements': {
29 'kFieldTrialConfig': {
30 'groups': [
32 'study': 'Study1',
33 'group_name': 'Group1',
34 'params': [
35 {'key': 'x', 'value': '1'},
36 {'key': 'y', 'value': '2'}
40 'study': 'Study2',
41 'group_name': 'OtherGroup'
47 self.assertEqual(expected, result)
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'
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:
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)
75 if __name__ == '__main__':
76 unittest.main()