def do_test(self, policy_data, writer):
    '''Executes a test case.

    Creates and invokes an instance of PolicyTemplateGenerator with
    the given arguments.

    Notice: Plain comments are used in test methods instead of docstrings,
    so that method names do not get overridden by the docstrings in the
    test output.

    Args:
      policy_data: The list of policies and groups as it would be
        loaded from policy_templates.json.
      writer: A writer used for this test. It is usually derived from
        mock_writer.MockWriter.
    '''
    writer.tester = self
    config = {
      'app_name': '_app_name',
      'frame_name': '_frame_name',
      'os_name': '_os_name',
    }
    if not 'messages' in policy_data:
      policy_data['messages'] = {}
    if not 'placeholders' in policy_data:
      policy_data['placeholders'] = []
    if not 'policy_definitions' in policy_data:
      policy_data['policy_definitions'] = []
    policy_generator = policy_template_generator.PolicyTemplateGenerator(
        config,
        policy_data)
    res = policy_generator.GetTemplateText(writer)
    writer.Test()
    return res
def _TemplateFormatter(writer_module_name, root, lang, output_dir):
    '''Creates a template file corresponding to an <output> node of the grit
  tree.

  More precisely, processes the whole grit tree for a given <output> node whose
  type is one of adm, plist, plist_strings, admx, adml, doc, json, reg.
  The result of processing is a policy template file with the given type and
  language of the <output> node. This function does the interfacing with
  grit, but the actual template-generating work is done in
  policy_template_generator.PolicyTemplateGenerator.

  Args:
    writer_name: A string identifying the TemplateWriter subclass used
      for generating the output.
    root: the <grit> root node of the grit tree.
    lang: the language of outputted text, e.g.: 'en'
    output_dir: The output directory, currently unused here.

  Yields the text of the template file.
  '''
    __import__(writer_module_name)
    writer_module = sys.modules[writer_module_name]
    config = writer_configuration.GetConfigurationForBuild(root.defines)
    policy_data = _ParseGritNodes(root, lang)
    policy_generator = \
        policy_template_generator.PolicyTemplateGenerator(config, policy_data)
    writer = writer_module.GetWriter(config)
    yield policy_generator.GetTemplateText(writer)
Пример #3
0
    def _GetOutput(self):
        '''Generates a template file using the instance variables initialized
    in Format() using the writer specified in __init__().

    Returns:
      The text of the policy template based on the parameters passed
      to __init__() and Format().
    '''
        policy_generator = policy_template_generator.PolicyTemplateGenerator(
            self._config, self._policy_data)
        writer = self._writer_module.GetWriter(self._config)
        str = policy_generator.GetTemplateText(writer)
        return str
Пример #4
0
    def do_test(self, messages, policy_definitions, writer):
        '''Executes a test case.

    Creates and invokes an instance of PolicyTemplateGenerator with
    the given arguments.

    Notice: Plain comments are used in test methods instead of docstrings,
    so that method names do not get overridden by the docstrings in the
    test output.

    Args:
      messages: The dictionary of localized messages.
      policy_definitions: The list of policies and groups as it would be
        loaded from policy_templates.json.
      writer: A writer used for this test. It is usually derived from
        mock_writer.MockWriter.
    '''
        writer.tester = self
        policy_generator = policy_template_generator.PolicyTemplateGenerator(
            messages, policy_definitions)
        res = policy_generator.GetTemplateText(writer)
        writer.Test()
        return res
Пример #5
0
 def testSorting(self):
     # Tests that policies are sorted correctly.
     policy_defs = [{
         'name': 'zp',
         'type': 'string',
         'caption': 'a1',
         'supported_on': []
     }, {
         'type':
         'group',
         'caption':
         'z_group1_caption',
         'name':
         'group1',
         'policies': [{
             'name': 'z0',
             'type': 'string',
             'supported_on': []
         }, {
             'name': 'a0',
             'type': 'string',
             'supported_on': []
         }]
     }, {
         'type':
         'group',
         'caption':
         'b_group2_caption',
         'name':
         'group2',
         'policies': [{
             'name': 'q',
             'type': 'string',
             'supported_on': []
         }],
     }, {
         'name': 'ap',
         'type': 'string',
         'caption': 'a2',
         'supported_on': []
     }]
     sorted_policy_defs = [
         {
             'type': 'group',
             'caption': 'b_group2_caption',
             'name': 'group2',
             'policies': [{
                 'name': 'q',
                 'type': 'string',
                 'supported_on': []
             }],
         },
         {
             'type':
             'group',
             'caption':
             'z_group1_caption',
             'name':
             'group1',
             'policies': [{
                 'name': 'z0',
                 'type': 'string',
                 'supported_on': []
             }, {
                 'name': 'a0',
                 'type': 'string',
                 'supported_on': []
             }]
         },
         {
             'name': 'ap',
             'type': 'string',
             'caption': 'a2',
             'supported_on': []
         },
         {
             'name': 'zp',
             'type': 'string',
             'caption': 'a1',
             'supported_on': []
         },
     ]
     ptg = policy_template_generator.PolicyTemplateGenerator([], [])
     ptg._SortPolicies(policy_defs)
     self.assertEquals(policy_defs, sorted_policy_defs)