예제 #1
0
def test_import_and_get():
    """Test the behavior of the import and get utility function.

    """
    assert (import_and_get('ecpy.utils.declarator', 'Declarator', {}, '') is
            Declarator)

    tb = {}
    import_and_get('___ecpy', 'r', tb, 'test')
    assert 'ImportError' in tb['test']

    import_and_get('ecpy.testing.broken_enaml', 'r', tb, 'test')
    assert 'NameError' in tb['test']

    import_and_get('ecpy.utils.declarator', '___D', tb, 'test')
    assert 'AttributeError' in tb['test']
예제 #2
0
def test_import_and_get():
    """Test the behavior of the import and get utility function.

    """
    assert (import_and_get('ecpy.utils.declarator', 'Declarator', {}, '') is
            Declarator)

    tb = {}
    import_and_get('___ecpy', 'r', tb, 'test')
    assert 'ImportError' in tb['test']

    import_and_get('ecpy.testing.broken_enaml', 'r', tb, 'test')
    assert 'AttributeError' in tb['test'] or 'NameError' in tb['test']

    import_and_get('ecpy.utils.declarator', '___D', tb, 'test')
    assert 'AttributeError' in tb['test']
예제 #3
0
def test_import_and_get():
    """Test the behavior of the import and get utility function.

    """
    assert (import_and_get('ecpy.utils.declarator', 'Declarator', {}, '') is
            Declarator)

    tb = {}
    import_and_get('___ecpy', 'r', tb, 'test')
    if sys.version_info < (3, 6):
        assert 'ImportError' in tb['test']
    else:
        assert 'ModuleNotFoundError' in tb['test']

    import_and_get('ecpy.testing.broken_enaml', 'r', tb, 'test')
    assert 'AttributeError' in tb['test'] or 'NameError' in tb['test']

    import_and_get('ecpy.utils.declarator', '___D', tb, 'test')
    assert 'AttributeError' in tb['test']
예제 #4
0
    def register(self, collector, traceback):
        """Collect sequence and view and add infos to the DeclaratorCollector
        contributions member.

        The group declared by a parent if any is taken into account. All
        Interface children are also registered.

        """
        # Build the sequence id by assembling the package name and the class
        # name.
        sequence_id = self.id

        # If the sequence only specifies a name update the matching infos.
        if ":" not in self.sequence:
            if self.sequence not in collector.contributions:
                collector._delayed.append(self)
                return

            infos = collector.contributions[sequence_id]
            infos.metadata.update(self.metadata)
            self.is_registered = True
            return

        # Determine the path of sequence and view
        path = self.get_path()
        try:
            s_path, sequence = (path + "." + self.sequence if path else self.sequence).split(":")
            v_path, view = (path + "." + self.view if path else self.view).split(":")
        except ValueError:
            msg = "Incorrect %s (%s), path must be of the form a.b.c:Class"
            err_id = s_path.split(".", 1)[0] + "." + sequence
            msg = msg % ("view", self.view)

            traceback[err_id] = msg
            return

        # Check that the sequence does not already exist.
        if sequence_id in collector.contributions or sequence_id in traceback:
            i = 1
            while True:
                err_id = "%s_duplicate%d" % (sequence_id, i)
                if err_id not in traceback:
                    break

            msg = "Duplicate definition of {}, found in {}"
            traceback[err_id] = msg.format(sequence, s_path)
            return

        infos = SequenceInfos(metadata=self.metadata)

        # Get the sequence class.
        s_cls = import_and_get(s_path, sequence, traceback, sequence_id)
        if s_cls is None:
            return

        try:
            infos.cls = s_cls
        except TypeError:
            msg = "{} should be a subclass of AbstractSequence. \n{}"
            traceback[sequence_id] = msg.format(s_cls, format_exc())
            return

        # Get the sequence view.
        s_view = import_and_get(v_path, view, traceback, sequence_id)
        if s_view is None:
            return

        try:
            infos.view = s_view
        except TypeError:
            msg = "{} should be a subclass of AbstractSequenceView,.\n{}"
            traceback[sequence_id] = msg.format(s_view, format_exc())
            return

        # Add group and add to collector
        infos.metadata["group"] = self.get_group()
        collector.contributions[sequence_id] = infos

        self.is_registered = True
예제 #5
0
    def register(self, collector, traceback):
        """Collect config and view and add infos to the DeclaratorCollector
        contributions member under the supported task name.

        """
        # Determine the path to the config and view.
        path = self.get_path()
        try:
            c_path, config = (path + "." + self.config if path else self.config).split(":")
            v_path, view = (path + "." + self.view if path else self.view).split(":")
        except ValueError:
            msg = "Incorrect %s (%s), path must be of the form a.b.c:Class"
            if ":" in self.config:
                msg = msg % ("view", self.view)
            else:
                msg = msg % ("config", self.config)

            traceback[self.id] = msg
            return

        try:
            s_cls = self.get_sequence_class()
        except Exception:
            msg = "Failed to get supported sequence : %s"
            traceback[self.id] = msg % format_exc()
            return

        # Check that the configurer does not already exist.
        if self.id in traceback:
            i = 1
            while True:
                err_id = "%s_duplicate%d" % (self.id, i)
                if err_id not in traceback:
                    break

            msg = "Duplicate definition of {}, found in {}"
            traceback[err_id] = msg.format(s_cls, c_path)
            return

        if s_cls in collector.contributions:
            msg = "Duplicate definition for {}, found in {}"
            traceback[self.id] = msg.format(s_cls, c_path)
            return

        infos = ConfigInfos()

        # Get the config class.
        c_cls = import_and_get(c_path, config, traceback, self.id)
        if c_cls is None:
            return

        try:
            infos.cls = c_cls
        except TypeError:
            msg = "{} should a subclass of AbstractConfig.\n{}"
            traceback[self.id] = msg.format(c_cls, format_exc())
            return

        # Get the config view.
        view = import_and_get(v_path, view, traceback, self.id)
        if view is None:
            return

        try:
            infos.view = view
        except TypeError:
            msg = "{} should a subclass of AbstractConfigView.\n{}"
            traceback[self.id] = msg.format(c_cls, format_exc())
            return

        collector.contributions[s_cls] = infos

        self.is_registered = True
예제 #6
0
    def register(self, collector, traceback):
        """Collect shape and view and add infos to the DeclaratorCollector
        contributions member.

        The group declared by a parent if any is taken into account. All
        Interface children are also registered.

        """
        # Build the shape id by assembling the package name and the class
        # name.
        shape_id = self.id

        # If the shape only specifies a name update the matching infos.
        if ':' not in self.shape:
            if self.shape not in collector.contributions:
                collector._delayed.append(self)
                return

            infos = collector.contributions[shape_id]
            # TODO Check or Update something?

        # Determine the path of shape and view
        path = self.get_path()
        try:
            s_path, shape = (path + '.' + self.shape
                             if path else self.shape).split(':')
            v_path, view = (path + '.' + self.view
                            if path else self.view).split(':')
        except ValueError:
            msg = 'Incorrect %s (%s), path must be of the form a.b.c:Class'
            err_id = s_path.split('.', 1)[0] + '.' + shape
            msg = msg % ('view', self.view)

            traceback[err_id] = msg
            return

        # Check that the shape does not already exist.
        if shape_id in collector.contributions or shape_id in traceback:
            i = 1
            while True:
                err_id = '%s_duplicate%d' % (shape_id, i)
                if err_id not in traceback:
                    break

            msg = 'Duplicate definition of {}, found in {}'
            traceback[err_id] = msg.format(shape, s_path)
            return

        infos = ShapeInfos(metadata=self.metadata)

        # Get the sequence class.
        s_cls = import_and_get(s_path, shape, traceback, shape_id)
        if s_cls is None:
            return

        try:
            infos.cls = s_cls
        except TypeError:
            msg = '{} should be a subclass of AbstractShape. \n{}'
            traceback[shape_id] = msg.format(s_cls, format_exc())
            return

        # Get the shape view.
        s_view = import_and_get(v_path, view, traceback, shape_id)
        if s_view is None:
            return

        try:
            infos.view = s_view
        except TypeError:
            msg = '{} should be a subclass of AbstractShapeView,.\n{}'
            traceback[shape_id] = msg.format(s_view, format_exc())
            return

        # Add group and add to collector
        infos.metadata['group'] = self.get_group()
        collector.contributions[shape_id] = infos

        # Register children.
        for i in self.children:
            i.register(collector, traceback)

        self.is_registered = True
예제 #7
0
    def register(self, collector, traceback):
        """Collect sequence and view and add infos to the DeclaratorCollector
        contributions member.

        The group declared by a parent if any is taken into account. All
        Interface children are also registered.

        """
        # Build the sequence id by assembling the package name and the class
        # name.
        sequence_id = self.id

        # If the sequence only specifies a name update the matching infos.
        if ':' not in self.sequence:
            if self.sequence not in collector.contributions:
                collector._delayed.append(self)
                return

            infos = collector.contributions[sequence_id]
            infos.metadata.update(self.metadata)
            self.is_registered = True
            return

        # Determine the path of sequence and view
        path = self.get_path()
        try:
            s_path, sequence = (path + '.' + self.sequence
                                if path else self.sequence).split(':')
            v_path, view = (path + '.' + self.view
                            if path else self.view).split(':')
        except ValueError:
            msg = 'Incorrect %s (%s), path must be of the form a.b.c:Class'
            err_id = s_path.split('.', 1)[0] + '.' + sequence
            msg = msg % ('view', self.view)

            traceback[err_id] = msg
            return

        # Check that the sequence does not already exist.
        if sequence_id in collector.contributions or sequence_id in traceback:
            i = 1
            while True:
                err_id = '%s_duplicate%d' % (sequence_id, i)
                if err_id not in traceback:
                    break

            msg = 'Duplicate definition of {}, found in {}'
            traceback[err_id] = msg.format(sequence, s_path)
            return

        infos = SequenceInfos(metadata=self.metadata)

        # Get the sequence class.
        s_cls = import_and_get(s_path, sequence, traceback, sequence_id)
        if s_cls is None:
            return

        try:
            infos.cls = s_cls
        except TypeError:
            msg = '{} should be a subclass of AbstractSequence. \n{}'
            traceback[sequence_id] = msg.format(s_cls, format_exc())
            return

        # Get the sequence view.
        s_view = import_and_get(v_path, view, traceback, sequence_id)
        if s_view is None:
            return

        try:
            infos.view = s_view
        except TypeError:
            msg = '{} should be a subclass of AbstractSequenceView,.\n{}'
            traceback[sequence_id] = msg.format(s_view, format_exc())
            return

        # Add group and add to collector
        infos.metadata['group'] = self.get_group()
        collector.contributions[sequence_id] = infos

        self.is_registered = True
예제 #8
0
    def register(self, collector, traceback):
        """Collect config and view and add infos to the DeclaratorCollector
        contributions member under the supported task name.

        """
        # Determine the path to the config and view.
        path = self.get_path()
        try:
            c_path, config = (path + '.' + self.config
                              if path else self.config).split(':')
            v_path, view = (path + '.' + self.view
                            if path else self.view).split(':')
        except ValueError:
            msg = 'Incorrect %s (%s), path must be of the form a.b.c:Class'
            if ':' in self.config:
                msg = msg % ('view', self.view)
            else:
                msg = msg % ('config', self.config)

            traceback[self.id] = msg
            return

        try:
            s_cls = self.get_sequence_class()
        except Exception:
            msg = 'Failed to get supported sequence : %s'
            traceback[self.id] = msg % format_exc()
            return

        # Check that the configurer does not already exist.
        if self.id in traceback:
            i = 1
            while True:
                err_id = '%s_duplicate%d' % (self.id, i)
                if err_id not in traceback:
                    break

            msg = 'Duplicate definition of {}, found in {}'
            traceback[err_id] = msg.format(s_cls, c_path)
            return

        if s_cls in collector.contributions:
            msg = 'Duplicate definition for {}, found in {}'
            traceback[self.id] = msg.format(s_cls, c_path)
            return

        infos = ConfigInfos()

        # Get the config class.
        c_cls = import_and_get(c_path, config, traceback, self.id)
        if c_cls is None:
            return

        try:
            infos.cls = c_cls
        except TypeError:
            msg = '{} should a subclass of AbstractConfig.\n{}'
            traceback[self.id] = msg.format(c_cls, format_exc())
            return

        # Get the config view.
        view = import_and_get(v_path, view, traceback, self.id)
        if view is None:
            return

        try:
            infos.view = view
        except TypeError:
            msg = '{} should a subclass of AbstractConfigView.\n{}'
            traceback[self.id] = msg.format(c_cls, format_exc())
            return

        collector.contributions[s_cls] = infos

        self.is_registered = True