示例#1
0
    def testExpandWithAdditionalContext(self):
        y_val = "bar"
        extra = dict(y=y_val)
        d = dict(t="${y}")
        expanded = json_expander.ExpandJsonTemplate(d)
        self.assertNotEquals(y_val, expanded["t"])

        expanded = json_expander.ExpandJsonTemplate(d, extra)
        self.assertEquals(y_val, expanded["t"])
示例#2
0
  def LoadJsonFile(self, path, expand=False):
    """Loads a file but ignores the broken ones.

    Fails a test assertion if the file is not loadable.

    Args:
      path: (str) path to file.
      expand: (bool, default False) whether to expand as a Json template.
    Returns:
      (dict) or None if the file is in a white list of known broken files.
    """
    json_file = open(path)
    content = json_file.read()
    self.assertLess(1, len(content))
    json_file.close()
    try:
      json_data = json_with_comments.Loads(content)
    except ValueError as err:
      # Ignore the known broken files.
      if not path.endswith('testdata/broken.json'):
        self.fail('%s: %s' % (path, err))
      return None
    if expand:
      json_data = json_expander.ExpandJsonTemplate(json_data)
    return json_data
示例#3
0
  def GetFeatures(self, variation):
    """Returns the features dictionary for a specific variation.

    This is the basic dictionary informaion plus any specific overrides in
    the per-template-tree features.json file.

    Args:
      variation: (str) A target variation name.
    Returns:
      (Features) features dictionary
    """
    if not variation:
      return None
    template_dir = self.AbsoluteTemplateDir(variation)
    features = Features(template_dir, self.get(variation), variation)
    json_path = os.path.join(template_dir, 'features.json')

    try:
      features_json = files.GetFileContents(json_path)
    except files.FileDoesNotExist:
      # for backwards compatibility, we forgive this.
      # TODO(user): be stricter about this and
      # fix/remove any tests that fail as a result.
      return features

    features.update(json_expander.ExpandJsonTemplate(
        json_with_comments.Loads(features_json)))
    # If not specified, the releaseVersion matches the variation
    if not features.get('releaseVersion'):
      features['releaseVersion'] = variation
    return features
示例#4
0
 def testExpand(self):
     x_val = "foo"
     y_val = "bar"
     d = dict(x=x_val,
              y=y_val,
              t1="$x",
              t2="${y}",
              r={
                  "t": "$x$y",
                  "l": [3, "$x"]
              })
     expanded = json_expander.ExpandJsonTemplate(d)
     self.assertEquals(x_val, expanded["t1"])
     self.assertEquals(y_val, expanded["t2"])
     self.assertEquals(x_val + y_val, expanded["r"]["t"])
     self.assertEquals(x_val, expanded["r"]["l"][1])
示例#5
0
 def testExpandNoSelf(self):
     d = dict(x="aha", t1="$x")
     extra = dict(x="no-no")
     expanded = json_expander.ExpandJsonTemplate(d, extra, use_self=False)
     self.assertEquals("no-no", expanded["t1"])