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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/variations/fieldtrial_to_struct_unittest.py
diff --git a/tools/variations/fieldtrial_to_struct_unittest.py b/tools/variations/fieldtrial_to_struct_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..f1980ac55466d5aca1e768ced5722c6fee4d5de6
--- /dev/null
+++ b/tools/variations/fieldtrial_to_struct_unittest.py
@@ -0,0 +1,76 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+
+import fieldtrial_to_struct
+import os
+
+
+class FieldTrialToStruct(unittest.TestCase):
+
+ def test_FieldTrialToDescription(self):
+ config = {
+ 'Study1': [
+ {
+ 'group_name': 'Group1',
+ 'params': {
+ 'x': '1',
+ 'y': '2'
+ }
+ }
+ ],
+ 'Study2': [{'group_name': 'OtherGroup'}]
+ }
+ result = fieldtrial_to_struct._FieldTrialConfigToDescription(config)
+ expected = {
+ 'elements': {
+ 'kFieldTrialConfig': {
+ 'groups': [
+ {
+ 'study': 'Study1',
+ 'group_name': 'Group1',
+ 'params': [
+ {'key': 'x', 'value': '1'},
+ {'key': 'y', 'value': '2'}
+ ]
+ },
+ {
+ 'study': 'Study2',
+ 'group_name': 'OtherGroup'
+ }
+ ]
+ }
+ }
+ }
+ self.assertEqual(expected, result)
+
+ def test_FieldTrialToStructMain(self):
+ schema = (
+ '../../chrome/common/variations/fieldtrial_testing_config_schema.json')
+ test_ouput_filename = 'test_ouput'
+ fieldtrial_to_struct.main([
+ '--schema=' + schema,
+ '--output=' + test_ouput_filename,
+ '--year=2015',
+ 'unittest_data/test_config.json'
+ ])
+ header_filename = test_ouput_filename + '.h'
+ with open(header_filename, 'r') as header:
+ test_header = header.read()
+ with open('unittest_data/expected_output.h', 'r') as expected:
+ expected_header = expected.read()
+ self.assertEqual(expected_header, test_header)
+ os.unlink(header_filename)
+
+ cc_filename = test_ouput_filename + '.cc'
+ with open(cc_filename, 'r') as cc:
+ test_cc = cc.read()
+ with open('unittest_data/expected_output.cc', 'r') as expected:
+ expected_cc = expected.read()
+ self.assertEqual(expected_cc, test_cc)
+ os.unlink(cc_filename)
+
+if __name__ == '__main__':
+ unittest.main()
« 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