Beispiel #1
0
def validate_driver_arguments(Driver, arguments):
    """
    Validate that in all required arguments are existing.
    @param required_arguments:
    @param arguments:

    @raise: L{MissingHeaderError}
    """
    try:
        required_args = get_method_requirements(Driver.__init__)
        method_with_docstring = Driver.__init__
    except NotImplementedError:
        required_args = get_method_requirements(Driver.__new__)
        method_with_docstring = Driver.__init__
        #required args validate
    missing_args = []
    for arg_altertives in required_args:
        if not any([arg in arguments for arg in arg_altertives]):
            missing_args.append(arg_altertives)
    if missing_args:
        raise MissingArguments(missing_args)
        #optional args validate
    method_args_spec = inspect.getargspec(method_with_docstring)
    method_args = method_args_spec[0][1:]  # with removing 'self' or 'cls' arg
    if method_args_spec[2]:
        pass  # TODO: add docs parsing for keyword arguments
    unknown_arguments = []
    required_args_flat = list(chain(*required_args))
    for arg in arguments:
        if not (arg in method_args or arg in required_args_flat):
            unknown_arguments.append(arg)
    if unknown_arguments:
        raise UnknownArgument(arguments=unknown_arguments)
    return True
Beispiel #2
0
def validate_driver_arguments(Driver, arguments):
    """
    Validate that in all required arguments are existing.
    @param required_arguments:
    @param arguments:

    @raise: L{MissingHeaderError}
    """
    try:
        required_args = get_method_requirements(Driver.__init__)
        method_with_docstring = Driver.__init__
    except NotImplementedError:
        required_args = get_method_requirements(Driver.__new__)
        method_with_docstring = Driver.__init__
        #required args validate
    missing_args = []
    for arg_altertives in required_args:
        if not any([arg in arguments for arg in arg_altertives]):
            missing_args.append(arg_altertives)
    if missing_args:
        raise MissingArguments(missing_args)
        #optional args validate
    method_args_spec = inspect.getargspec(method_with_docstring)
    method_args = method_args_spec[0][1:]  # with removing 'self' or 'cls' arg
    if method_args_spec[2]:
        pass  # TODO: add docs parsing for keyword arguments
    unknown_arguments = []
    required_args_flat = list(chain(*required_args))
    for arg in arguments:
        if not (arg in method_args or arg in required_args_flat):
            unknown_arguments.append(arg)
    if unknown_arguments:
        raise UnknownArgument(arguments=unknown_arguments)
    return True
Beispiel #3
0
    def test_get_method_requirements(self):
        #valid input
        def t3():
            """
            @requires: x, y or z
            """

        reqs = parser.get_method_requirements(t3)
        self.assertItemsEqual(reqs, [['x'], ['y', 'z']])

        #invalid input
        def t1():
            pass

        self.assertRaises(NotImplementedError, parser.get_method_requirements,
                          t1)

        def t2():
            """
            @return:
            @rtype:
            """

        self.assertRaises(NotImplementedError, parser.get_method_requirements,
                          t2)
Beispiel #4
0
    def test_get_method_requirements(self):
        #valid input
        def t3():
            """
            @requires: x, y or z
            """

        reqs = parser.get_method_requirements(t3)
        self.assertItemsEqual(reqs, [['x'], ['y', 'z']])

        #invalid input
        def t1():
            pass

        self.assertRaises(NotImplementedError,
                          parser.get_method_requirements, t1)

        def t2():
            """
            @return:
            @rtype:
            """

        self.assertRaises(NotImplementedError,
                          parser.get_method_requirements, t2)
Beispiel #5
0
 def test_compute_requires(self):
     providers = compute_providers.Provider
     drivers = compute_providers.DRIVERS
     for provider_name in providers.__dict__.keys():
         if not provider_name.startswith('_'):
             provider_name = provider_name.upper()
             try:
                 Driver = get_driver_by_provider_name(
                     drivers, providers, provider_name)
                 try:
                     get_method_requirements(Driver.__init__)
                 except NotImplementedError:
                     try:
                         get_method_requirements(Driver.__new__)
                     except NotImplementedError:
                         raise NotImplementedError(
                             '%s provider has not @requires docstrign' %
                             provider_name)
             except ProviderNotSupportedError:
                 pass
 def test_compute_requires(self):
     providers = compute_providers.Provider
     drivers = compute_providers.DRIVERS
     for provider_name in providers.__dict__.keys():
         if not provider_name.startswith('_'):
             provider_name = provider_name.upper()
             try:
                 Driver = get_driver_by_provider_name(drivers,
                                                      providers,
                                                      provider_name)
                 try:
                     get_method_requirements(Driver.__init__)
                 except NotImplementedError:
                     try:
                         get_method_requirements(Driver.__new__)
                     except NotImplementedError:
                         raise NotImplementedError(
                             '%s provider has not @requires docstrign'
                             % provider_name)
             except ProviderNotSupportedError:
                 pass