OLD | NEW |
(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() |
OLD | NEW |