예제 #1
0
파일: SubTest.py 프로젝트: zuphilip/coala
 def test__ne__(self, RootAspect, SubAspect, SubAspect_taste_values):
     assert not SubAspect('py') != SubAspect('py')
     assert not SubAspect('py', **SubAspect_taste_values) \
         != SubAspect('py', **SubAspect_taste_values)
     assert SubAspect('py') != RootAspect('py')
     assert SubAspect('py') != Root('py')
     assert SubAspect('py') != SubAspect('py', **SubAspect_taste_values)
     assert SubAspect('py', **SubAspect_taste_values) != SubAspect('py')
예제 #2
0
 def test__eq__(self, RootAspect, SubAspect, SubAspect_taste_values):
     assert SubAspect() == SubAspect()
     assert SubAspect(**SubAspect_taste_values) \
         == SubAspect(**SubAspect_taste_values)
     assert not SubAspect() == RootAspect()
     assert not SubAspect() == Root()
     assert not SubAspect() == SubAspect(**SubAspect_taste_values)
     assert not SubAspect(**SubAspect_taste_values) == SubAspect()
예제 #3
0
 def test__eq__(self, RootAspect, SubAspect, SubAspect_taste_values):
     assert SubAspect('py') == SubAspect('py')
     assert (SubAspect('py', **SubAspect_taste_values) == SubAspect(
         'py', **SubAspect_taste_values))
     assert not SubAspect('py') == RootAspect('py')
     assert not SubAspect('py') == Root('py')
     assert not (SubAspect('py') == SubAspect('py', **
                                              SubAspect_taste_values))
     assert not (SubAspect('py', **SubAspect_taste_values)
                 == SubAspect('py'))
    def test_isaspect(self, RootAspect):
        @RootAspect.subaspect
        class SubAspect:
            """
            Description
            """

        assert isaspect(RootAspect)
        assert isaspect(SubAspect)
        assert isaspect(SubAspect('Python'))
        assert isaspect(Root('py'))
        assert not isaspect('String')
예제 #5
0
파일: SectionTest.py 프로젝트: mani87/coala
    def test_extract_aspects_from_section(self):
        section = Section('section')
        section.append(
            Setting('aspects', 'spelling, commitmessage, methodsmell'))
        # Custom taste for ColonExistence
        section.append(Setting('commitmessage.shortlog_colon', 'false'))
        section.append(Setting('language', 'py 3.4'))

        aspects = extract_aspects_from_section(section)
        spelling_instance = Root.Spelling('py 3.4')
        colon_existence_instance = (
            Root.Metadata.CommitMessage.Shortlog.ColonExistence(
                'py 3.4', shortlog_colon=False))
        method_smell_instance = Root.Smell.MethodSmell('py 3.4')
        trailing_period_instance = (
            Root.Metadata.CommitMessage.Shortlog.TrailingPeriod('py 3.4'))

        self.assertIsInstance(aspects, AspectList)
        self.assertEqual(aspects.get('spelling'), spelling_instance)
        self.assertEqual(aspects.get('colonexistence'),
                         colon_existence_instance)
        self.assertEqual(aspects.get('methodsmell'), method_smell_instance)
        self.assertEqual(aspects.get('TrailingPeriod'),
                         trailing_period_instance)
예제 #6
0
from coalib.bearlib.aspects import (
    Aspect, AspectDocumentation, AspectSetting, Root)


Root.new_subaspect(
    'Redundancy',
    AspectDocumentation(
        definition="""
        This aspect describes redundancy in your source code.
        """,
        importance_reason="""
        Redundant code makes your code harder to read and understand.
        """,
        fix_suggestions="""
        Redundant code can usually be removed without consequences.
        """
    )
)

Root.Redundancy.new_subaspect(
    'Clone',
    AspectDocumentation(
        definition="""
        Code clones are multiple pieces of source code in your
        codebase that are very similar.
        """,
        example="""
        extern int array_a[];
        extern int array_b[];

        int sum_a = 0;
예제 #7
0
from coalib.bearlib.aspects import (Aspect, AspectDocumentation, AspectSetting,
                                    Root)

Root.new_subaspect(
    'Redundancy',
    AspectDocumentation(definition="""
        This aspect describes redundancy in your source code.
        """,
                        importance_reason="""
        Redundant code makes your code harder to read and understand.
        """,
                        fix_suggestions="""
        Redundant code can usually be removed without consequences.
        """))

Root.Redundancy.new_subaspect(
    'Clone',
    AspectDocumentation(definition="""
        Code clones are multiple pieces of source code in your
        codebase that are very similar.
        """,
                        example="""
        extern int array_a[];
        extern int array_b[];

        int sum_a = 0;

        for (int i = 0; i < 4; i++)
            sum_a += array_a[i];

        int average_a = sum_a / 4;
예제 #8
0
 def test__ne__(self, RootAspect):
     assert not Root() != Root()
     assert Root() != RootAspect()
예제 #9
0
 def test__eq__(self, RootAspect):
     assert Root() == Root()
     assert not Root() == RootAspect()
예제 #10
0
from coalib.bearlib.aspects import Root, AspectDocumentation, AspectSetting


Root.new_subaspect(
    "Metadata",
    AspectDocumentation(
        definition="""
        This describes any aspect that is related to metadata that is not
        inside your source code.
        """
    )
)

Root.Metadata.new_subaspect(
    "CommitMessage",
    AspectDocumentation(
        definition="""
        Your commit message is important documentation associated with your
        source code. It can help you to identify bugs (e.g. through
        `git bisect`) or find missing information about unknown source code
        (through `git blame`).

        Commit messages are also sometimes used to generate - or write
        manually - release notes.
        """
    )
)

Root.Metadata.CommitMessage.new_subaspect(
    "Emptiness",
    AspectDocumentation(
예제 #11
0
    def from_values(cls,
                    origin,
                    message: str,
                    file: str,
                    line: (int, None) = None,
                    column: (int, None) = None,
                    end_line: (int, None) = None,
                    end_column: (int, None) = None,
                    severity: int = RESULT_SEVERITY.NORMAL,
                    additional_info: str = '',
                    debug_msg='',
                    diffs: (dict, None) = None,
                    confidence: int = 100,
                    aspect: aspectbase = Root()):
        """
        Creates a result with only one SourceRange with the given start and end
        locations.

        origin:
            Class name or creator object of this object.
        :param message:
            Message to show with this result.
        :param file:
            The related file.
        :param line:
            The first related line in the file. (First line is 1)
        :param column:
            The column indicating the first character. (First character is 1)
        :param end_line:
            The last related line in the file.
        :param end_column:
            The column indicating the last character.
        :param severity:
            Severity of this result.
        :param additional_info:
            A long description holding additional information about the issue
            and/or how to fix it. You can use this like a manual entry for a
            category of issues.
        :param debug_msg:
            A message which may help the user find out why this result was
            yielded.
        :param diffs:
            A dictionary with filenames as key and a sequence of ``Diff``
            objects associated with them as values.
        :param confidence:
            A number between 0 and 100 describing the likelihood of this result
            being a real issue.
        :param aspect:
            An Aspect object which this result is associated to. Note that this
            should be a leaf of the aspect tree! (If you have a node, spend
            some time figuring out which of the leafs exactly your result
            belongs to.)
        """
        range = SourceRange.from_values(file, line, column, end_line,
                                        end_column)

        return cls(origin=origin,
                   message=message,
                   affected_code=(range, ),
                   severity=severity,
                   additional_info=additional_info,
                   debug_msg=debug_msg,
                   diffs=diffs,
                   confidence=confidence,
                   aspect=aspect)
예제 #12
0
    def __init__(self,
                 origin,
                 message: str,
                 affected_code: (tuple, list) = (),
                 severity: int = RESULT_SEVERITY.NORMAL,
                 additional_info: str = '',
                 debug_msg='',
                 diffs: (dict, None) = None,
                 confidence: int = 100,
                 aspect: aspectbase = Root()):
        """
        :param origin:
            Class name or creator object of this object.
        :param message:
            Message to show with this result.
        :param affected_code:
            A tuple of SourceRange objects pointing to related positions in the
            source code.
        :param severity:
            Severity of this result.
        :param additional_info:
            A long description holding additional information about the issue
            and/or how to fix it. You can use this like a manual entry for a
            category of issues.
        :param debug_msg:
            A message which may help the user find out why this result was
            yielded.
        :param diffs:
            A dictionary with filenames as key and a sequence of ``Diff``
            objects associated with them as values.
        :param confidence:
            A number between 0 and 100 describing the likelihood of this result
            being a real issue.
        :param aspect:
            An aspectclass instance which this result is associated to.
            Note that this should be a leaf of the aspect tree!
            (If you have a node, spend some time figuring out which of
            the leafs exactly your result belongs to.)
        :raises ValueError:
            Raised when confidence is not between 0 and 100.
        """
        origin = origin or ''
        if not isinstance(origin, str):
            origin = origin.__class__.__name__
        if severity not in RESULT_SEVERITY.reverse:
            raise ValueError('severity is not a valid RESULT_SEVERITY')

        self.origin = origin
        self.message = message
        self.debug_msg = debug_msg
        self.additional_info = additional_info
        # Sorting is important for tuple comparison
        self.affected_code = tuple(sorted(affected_code))
        self.severity = severity
        if confidence < 0 or confidence > 100:
            raise ValueError(
                'Value of confidence should be between 0 and 100.')
        self.confidence = confidence
        self.diffs = diffs
        self.id = uuid.uuid4().int
        self.aspect = aspect