OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''Common tools for unit-testing writers.''' | 6 '''Common tools for unit-testing writers.''' |
7 | 7 |
8 | 8 |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 <grit base_dir="." latest_public_release="0" current_release="1" source_lang
_id="en"> | 54 <grit base_dir="." latest_public_release="0" current_release="1" source_lang
_id="en"> |
55 <release seq="1"> | 55 <release seq="1"> |
56 <structures> | 56 <structures> |
57 <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_templa
te_metafile" /> | 57 <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_templa
te_metafile" /> |
58 </structures> | 58 </structures> |
59 </release> | 59 </release> |
60 </grit>''' % json_file_path | 60 </grit>''' % json_file_path |
61 grd_string_io = StringIO.StringIO(grd_text) | 61 grd_string_io = StringIO.StringIO(grd_text) |
62 # Parse the grit tree and load the policies' JSON with a gatherer. | 62 # Parse the grit tree and load the policies' JSON with a gatherer. |
63 grd = grd_reader.Parse(grd_string_io, dir=tmp_dir_name) | 63 grd = grd_reader.Parse(grd_string_io, dir=tmp_dir_name) |
| 64 grd.SetOutputContext('en', {}) |
64 grd.RunGatherers(recursive=True) | 65 grd.RunGatherers(recursive=True) |
65 # Remove the policies' JSON. | 66 # Remove the policies' JSON. |
66 os.unlink(json_file_path) | 67 os.unlink(json_file_path) |
67 return grd | 68 return grd |
68 | 69 |
69 def GetOutput(self, grd, env_lang, env_defs, out_type, out_lang): | 70 def GetOutput(self, grd, env_lang, env_defs, out_type, out_lang): |
70 '''Generates an output of a writer. | 71 '''Generates an output of a writer. |
71 | 72 |
72 Args: | 73 Args: |
73 grd: The root of the grit tree. | 74 grd: The root of the grit tree. |
74 env_lang: The environment language. | 75 env_lang: The environment language. |
75 env_defs: Environment definitions. | 76 env_defs: Environment definitions. |
76 out_type: Type of the output node for which output will be generated. | 77 out_type: Type of the output node for which output will be generated. |
77 This selects the writer. | 78 This selects the writer. |
78 out_lang: Language of the output node for which output will be generated. | 79 out_lang: Language of the output node for which output will be generated. |
79 | 80 |
80 Returns: | 81 Returns: |
81 The string of the tamplete created by the writer. | 82 The string of the tamplete created by the writer. |
82 ''' | 83 ''' |
83 grd.SetOutputContext(env_lang, env_defs) | 84 grd.SetOutputContext(env_lang, env_defs) |
84 buf = StringIO.StringIO() | 85 buf = StringIO.StringIO() |
85 build.RcBuilder.ProcessNode(grd, DummyOutput(out_type, out_lang), buf) | 86 build.RcBuilder.ProcessNode(grd, DummyOutput(out_type, out_lang), buf) |
86 return buf.getvalue() | 87 return buf.getvalue() |
OLD | NEW |