コード例 #1
0
    def result(
            func: 'phase_descriptor.PhaseT'
    ) -> 'phase_descriptor.PhaseDescriptor':
        """Wrap the given function and return the wrapper.

    Args:
      func: The function to wrap.

    Returns:
      A PhaseDescriptor that, when called will invoke the wrapped function,
        passing plugs as keyword args.

    Raises:
      DuplicatePlugError:  If a plug name is declared twice for the
          same function.
    """
        phase = phase_descriptor.PhaseDescriptor.wrap_or_copy(func)
        duplicates = (frozenset(p.name
                                for p in phase.plugs) & frozenset(plugs_map))
        if duplicates:
            raise DuplicatePlugError(
                'Plugs %s required multiple times on phase %s' %
                (duplicates, func))

        phase.plugs.extend([
            base_plugs.PhasePlug(name, a_plug, update_kwargs=update_kwargs)
            for name, a_plug in six.iteritems(plugs_map)
        ])
        return phase
コード例 #2
0
 def test_with_plugs_custom_placeholder_is_base_plug(self):
     phase = custom_placeholder_phase.with_plugs(
         custom=PlugVersionOfNonPlug)
     self.assertIs(phase.func, custom_placeholder_phase.func)
     self.assertEqual(
         [base_plugs.PhasePlug('custom', PlugVersionOfNonPlug)],
         phase.plugs)