def testDependencyViewFromValue_Error(self):
    def Getter():
      raise deps.AttributeNotFoundError('not found')
    dependency_view = dependency_managers.DependencyViewFromValue(Getter)

    with self.assertRaisesRegex(deps.AttributeNotFoundError, 'not found'):
      dependency_view.value  # pylint:disable=pointless-statement
예제 #2
0
 def Parse(self, dependencies):
     """Parses the dict from dependencies and returns it."""
     dict_value = {}
     try:
         value = dependencies.value
     except deps_lib.AttributeNotFoundError as e:
         if not self.required:
             return None
         raise exceptions.MissingRequiredArgumentError(
             self.GetPresentationName(), e)
     items, self._delim = self._Split(value)
     for item in items:
         key, val = item.split('=', 1)
         entry = self._entries.get(key)
         if not entry:
             if not self._additional:
                 raise exceptions.ParseError(
                     self.GetPresentationName(),
                     'Unknown dictionary key [{}].'.format(key))
             entry = self._additional(key)
         item_dependencies = copy.copy(
             dependencies.marshalled_dependencies.get(key))
         try:
             item_dependencies.value = val
         except AttributeError:
             item_dependencies = dependency_managers.DependencyViewFromValue(
                 val)
         dict_value[key] = entry.Parse(item_dependencies)
     dict_value = self.Convert(dict_value)
     self.Validate(dict_value)
     return self.Normalize(dict_value)
예제 #3
0
 def Parse(self, dependencies):
   """Parses the list from dependencies and returns it."""
   list_value = []
   try:
     value = dependencies.value
   except deps_lib.AttributeNotFoundError as e:
     if not self.required:
       return None
     raise exceptions.MissingRequiredArgumentException(
         self.GetPresentationName(), e)
   items, self._delim = self._Split(value)
   for item in items:
     # TODO(b/117144623): eventually use dependencies.marshalled_dependencies.
     item_dependencies = dependency_managers.DependencyViewFromValue(item)
     list_value.append(self._element.Parse(item_dependencies))
   list_value = self.Convert(list_value)
   self.Validate(list_value)
   return self.Normalize(list_value)
  def testDependencyViewFromValue(self):
    def Getter():
      return 'x'
    dependency_view = dependency_managers.DependencyViewFromValue(Getter)

    self.assertEqual('x', dependency_view.value)