Ejemplo n.º 1
0
def test_uncached_step_function_25():
    
    def my_step(state):
        raise NotImplementedError()
    
    assert not hasattr(my_step, '_BaseStepType__step_type')
    
    assert BaseStep.__instancecheck__(my_step)
    
    
    assert hasattr(my_step, '_BaseStepType__step_type')
    
    assert step_types_module.SimpleStep.__instancecheck__(my_step)
Ejemplo n.º 2
0
def test_uncached_step_function_25():
    
    def my_step(state):
        raise NotImplementedError()
    
    assert not hasattr(my_step, '_BaseStepType__step_type')
    
    assert BaseStep.__instancecheck__(my_step)
    
    
    assert hasattr(my_step, '_BaseStepType__step_type')
    
    assert step_types_module.SimpleStep.__instancecheck__(my_step)
     def parse_arguments_to_step_profile(*args, **kwargs):
         '''
         Build a step profile smartly.
     
         The canonical way to build a step profile is to provide it with a
         step function, `*args` and `**kwargs`. But in this function we're
         being a little smarter so the user will have less work.
         
         You do not need to enter a step function; we will use the default
         one, unless you specify a different one as `step_function`.
         
         You may also pass in a step profile as `step_profile`, and it will
         be noticed and used.
         '''
     
         # We have two candidates to check now: `args[0]` and
         # `kwargs['step_function']`. We'll check the latter first, because
         # that's more explicit and there's less chance we'll be catching
         # some other object by mistake.
         #
         # So we start with `kwargs`:
         
         if 'step_function' in kwargs:
             kwargs_copy = kwargs.copy()
             step_function = kwargs_copy.pop('step_function')
             
             
             assert BaseStep.__instancecheck__(step_function)
             # If the user specified 'step_function', he's not going to get
             # away with it not being an actual step function.
 
             return StepProfile(step_function, *args, **kwargs_copy)
         
         
         if 'step_profile' in kwargs:
             kwargs_copy = kwargs.copy()
             step_profile = kwargs_copy.pop('step_profile')
             
             if step_profile is None:
                 # We let the user specify `step_profile=None` if he wants
                 # to get the default step profile.
                 return StepProfile(default_step_function)
                 
             else: # step_profile is not None
                 if not isinstance(step_profile, StepProfile):
                     raise GarlicSimException(
                         "You passed in `%s` as a keyword argument with a "
                         "keyword of `step_profile`, but it's not a step "
                         "profile." % step_profile
                     )
                 return step_profile
 
         
         # No step function in `kwargs`. We'll try `args`:
         
         elif args:
             
             candidate = args[0]
             
             if isinstance(candidate, StepProfile):
                 return candidate
             
             elif BaseStep.__instancecheck__(candidate):
                 args_copy = args[1:]
                 return StepProfile(
                     candidate,
                     *args_copy,
                     **kwargs
                 )
               
         
         
         return StepProfile(default_step_function, *args, **kwargs)
Ejemplo n.º 4
0
        def parse_arguments_to_step_profile(*args, **kwargs):
            '''
            Build a step profile smartly.
        
            The canonical way to build a step profile is to provide it with a
            step function, `*args` and `**kwargs`. But in this function we're
            being a little smarter so the user will have less work.
            
            You do not need to enter a step function; we will use the default
            one, unless you specify a different one as `step_function`.
            
            You may also pass in a step profile as `step_profile`, and it will
            be noticed and used.
            '''

            # We have two candidates to check now: `args[0]` and
            # `kwargs['step_function']`. We'll check the latter first, because
            # that's more explicit and there's less chance we'll be catching
            # some other object by mistake.
            #
            # So we start with `kwargs`:

            if 'step_function' in kwargs:
                kwargs_copy = kwargs.copy()
                step_function = kwargs_copy.pop('step_function')

                assert BaseStep.__instancecheck__(step_function)
                # If the user specified 'step_function', he's not going to get
                # away with it not being an actual step function.

                return StepProfile(step_function, *args, **kwargs_copy)

            if 'step_profile' in kwargs:
                kwargs_copy = kwargs.copy()
                step_profile = kwargs_copy.pop('step_profile')

                if step_profile is None:
                    # We let the user specify `step_profile=None` if he wants
                    # to get the default step profile.
                    return StepProfile(default_step_function)

                else:  # step_profile is not None
                    if not isinstance(step_profile, StepProfile):
                        raise GarlicSimException(
                            "You passed in `%s` as a keyword argument with a "
                            "keyword of `step_profile`, but it's not a step "
                            "profile." % step_profile)
                    return step_profile

            # No step function in `kwargs`. We'll try `args`:

            elif args:

                candidate = args[0]

                if isinstance(candidate, StepProfile):
                    return candidate

                elif BaseStep.__instancecheck__(candidate):
                    args_copy = args[1:]
                    return StepProfile(candidate, *args_copy, **kwargs)

            return StepProfile(default_step_function, *args, **kwargs)