grappa-py/grappa

View on GitHub

Showing 45 of 45 total issues

Function match has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def match(self, subject, *keys):
        if not isinstance(subject, collections_abc.Mapping):
            return False, ['subject is not a dict type']

        reasons = []
Severity: Minor
Found in grappa/operators/keys.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function mock_implementation_validator has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def mock_implementation_validator(func):
    """
    Validate that a mock conform to the implementation required to run
    have_been and have_been_with operators.

Severity: Minor
Found in grappa/decorators.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function match has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def match(self, subject, *values):
        if isinstance(subject, self.NORMALIZE_TYPES):
            subject = list(subject)
        elif isinstance(subject, collections_abc.Mapping):
            subject = list(subject.values())
Severity: Minor
Found in grappa/operators/contain.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    information = (
        Operator.Dsl.Help(
            Operator.Dsl.Description(
                'An empty object can be "None", "0" or "len(x) == 0".',
                'Most objects in Python can be tested via "len(x)"',
Severity: Minor
Found in grappa/operators/empty.py and 1 other location - About 45 mins to fix
grappa/operators/implements.py on lines 72..80

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 35.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function delegator has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def delegator(assertion, subject, expected, *args, **kw):
Severity: Minor
Found in grappa/decorators.py - About 35 mins to fix

    Function operator has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def operator(name=None, operators=None, aliases=None, kind=None):
        """
        Registers a new operator function in the test engine.
    
        Arguments:
    Severity: Minor
    Found in grappa/decorators.py - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _matches_any has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def _matches_any(self, expected, subject):
            if len(subject) == 0:
                return False, 'empty item'
    
            if isinstance(subject, six.string_types):
    Severity: Minor
    Found in grappa/operators/contain.py - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _has_property has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def _has_property(self, subject, name, *args):
            if args:
                try:
                    value = getattr(subject, name)
                except AttributeError:
    Severity: Minor
    Found in grappa/operators/property.py - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            if not isinstance(subject, six.string_types):
                return False, ['subject must be a string, but got "{}"'.format(
                    type(subject))]
    Severity: Minor
    Found in grappa/operators/match.py and 1 other location - About 35 mins to fix
    grappa/operators/match.py on lines 66..69

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 33.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, context=None, operator_name=None, fn=None,
                     kind=None, aliases=None, operators=None, suboperators=None):
            if inspect.isfunction(fn):
                self.match = fn
            if kind:
    Severity: Minor
    Found in grappa/operator.py - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function run_assertions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def run_assertions(self, ctx):
            # Trigger assertion functions
            for assertion in self.engine.assertions:
                # Store current subject
                subject = ctx.subject
    Severity: Minor
    Found in grappa/runner.py - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function register_operators has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def register_operators(*operators):
        """
        Registers one or multiple operators in the test engine.
        """
        def validate(operator):
    Severity: Minor
    Found in grappa/engine.py - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            if not isinstance(expected, six.string_types):
                return False, [
                    'value to match must be a string, but got "{}"'.format(
                        type(expected))
    Severity: Minor
    Found in grappa/operators/match.py and 1 other location - About 35 mins to fix
    grappa/operators/match.py on lines 62..64

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 33.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Avoid too many return statements within this function.
    Open

                return self.linefy(self.cut(value, size=size))
    Severity: Major
    Found in grappa/reporters/base.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return True
      Severity: Major
      Found in grappa/operators/empty.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return False
        Severity: Major
        Found in grappa/operators/empty.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return True
          Severity: Major
          Found in grappa/operators/empty.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return False, 'item {0!r} not found'.format(expected)
            Severity: Major
            Found in grappa/operators/contain.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return True, 'property {0!r} found'.format(name)
              Severity: Major
              Found in grappa/operators/property.py - About 30 mins to fix

                Function resolve has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def resolve(self, name):
                        # Check if should stop the call chain
                        if self.ctx.stop_chain:
                            raise RuntimeError(
                                'grappa: test operator "{}" does not allow '
                Severity: Minor
                Found in grappa/resolver.py - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Severity
                Category
                Status
                Source
                Language