Пример #1
0
def test_find_class_with_full_namespace_where_namespace_is_not_last():
    module_name, cls = find_class(
        'SharedLoggingObject',
        namespaces=['daisychain.log', 'daisychain.steps'])
    assert module_name == 'daisychain.log'
    assert cls is SharedLoggingObject
    module_cache.clear()
Пример #2
0
    def __init__(self, step_config, creator, **fields):
        super(InstantiationStep, self).__init__(name=step_config['name'], **fields)
        self.step_config = step_config
        if CLASS_KEY not in step_config:
            raise KeyError("Step {0!r} does not specify a class".format(step_config))

        step_class_name = step_config.pop(CLASS_KEY)
        _, step_class = find_class(step_class_name)
        if step_class is None:
            raise KeyError("Could not find the class {!r}".format(step_class_name))

        self.step_class = step_class
        self.creator = creator
        self.result_instance = None
 def compile(self, config):
     for namespace_section in self.find_subsections_specifying_key(self.NAMESPACES_KEY, config):
         namespaces = namespace_section.pop(self.NAMESPACES_KEY)
         for class_section in self.find_subsections_specifying_key(CLASS_KEY, namespace_section, self.NAMESPACES_KEY):
             if self.NAMESPACES_KEY in class_section:
                 class_namespaces = class_section.pop(self.NAMESPACES_KEY)
             else:
                 class_namespaces = namespaces
             self.log('compiler').debug('Attempting to find a class for {!r} based on namespaces:{!r}'.format(class_section, class_namespaces))
             module_name, cls = find_class(class_section[CLASS_KEY], class_namespaces)
             if module_name is None:
                 self.log('compiler').error('Could not find a class for {!r} based on the namespaces:{!r}'.format(class_section, class_namespaces))
             else:
                 class_section[CLASS_KEY] = cls.__module__ + '.' + cls.__name__
     return config
Пример #4
0
    def __init__(self, step_config, creator, **fields):
        super(InstantiationStep, self).__init__(name=step_config['name'],
                                                **fields)
        self.step_config = step_config
        if CLASS_KEY not in step_config:
            raise KeyError(
                "Step {0!r} does not specify a class".format(step_config))

        step_class_name = step_config.pop(CLASS_KEY)
        _, step_class = find_class(step_class_name)
        if step_class is None:
            raise KeyError(
                "Could not find the class {!r}".format(step_class_name))

        self.step_class = step_class
        self.creator = creator
        self.result_instance = None
Пример #5
0
 def compile(self, config):
     for namespace_section in self.find_subsections_specifying_key(
             self.NAMESPACES_KEY, config):
         namespaces = namespace_section.pop(self.NAMESPACES_KEY)
         for class_section in self.find_subsections_specifying_key(
                 CLASS_KEY, namespace_section, self.NAMESPACES_KEY):
             if self.NAMESPACES_KEY in class_section:
                 class_namespaces = class_section.pop(self.NAMESPACES_KEY)
             else:
                 class_namespaces = namespaces
             self.log('compiler').debug(
                 'Attempting to find a class for {!r} based on namespaces:{!r}'
                 .format(class_section, class_namespaces))
             module_name, cls = find_class(class_section[CLASS_KEY],
                                           class_namespaces)
             if module_name is None:
                 self.log('compiler').error(
                     'Could not find a class for {!r} based on the namespaces:{!r}'
                     .format(class_section, class_namespaces))
             else:
                 class_section[
                     CLASS_KEY] = cls.__module__ + '.' + cls.__name__
     return config
Пример #6
0
def test_find_class_cannot_find_class():
    module_name, cls = find_class('SharedLoggingObject', namespaces=['daisychain.steps'])
    assert module_name is None
    assert cls is None
    module_cache.clear()
Пример #7
0
def test_find_class_no_namespaces():
    module_name, cls = find_class('daisychain.log.SharedLoggingObject')
    assert module_name == 'daisychain.log'
    assert cls is SharedLoggingObject
    module_cache.clear()
Пример #8
0
def test_find_class_with_full_namespace_where_namespace_is_not_last():
    module_name, cls = find_class('SharedLoggingObject', namespaces=['daisychain.log', 'daisychain.steps'])
    assert module_name == 'daisychain.log'
    assert cls is SharedLoggingObject
    module_cache.clear()
Пример #9
0
def test_find_class_with_partial_namespace():
    module_name, cls = find_class('log.SharedLoggingObject', namespaces=['daisychain'])
    assert module_name == 'daisychain.log'
    assert cls is SharedLoggingObject
    module_cache.clear()
Пример #10
0
def test_find_class_with_full_path_when_namespaces_specified():
    module_name, cls = find_class('daisychain.log.SharedLoggingObject', namespaces=['daisychain'])
    assert module_name == 'daisychain.log'
    assert cls is SharedLoggingObject
    module_cache.clear()
Пример #11
0
def test_find_class_cannot_find_class():
    module_name, cls = find_class('SharedLoggingObject',
                                  namespaces=['daisychain.steps'])
    assert module_name is None
    assert cls is None
    module_cache.clear()
Пример #12
0
def test_find_class_no_namespaces():
    module_name, cls = find_class('daisychain.log.SharedLoggingObject')
    assert module_name == 'daisychain.log'
    assert cls is SharedLoggingObject
    module_cache.clear()
Пример #13
0
def test_find_class_with_partial_namespace():
    module_name, cls = find_class('log.SharedLoggingObject',
                                  namespaces=['daisychain'])
    assert module_name == 'daisychain.log'
    assert cls is SharedLoggingObject
    module_cache.clear()
Пример #14
0
def test_find_class_with_full_path_when_namespaces_specified():
    module_name, cls = find_class('daisychain.log.SharedLoggingObject',
                                  namespaces=['daisychain'])
    assert module_name == 'daisychain.log'
    assert cls is SharedLoggingObject
    module_cache.clear()