ionelmc/python-aspectlib

View on GitHub
src/aspectlib/test.py

Summary

Maintainability
F
3 days
Test Coverage

File test.py has 626 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
from collections import defaultdict
from collections import namedtuple
from difflib import unified_diff
from functools import partial
Severity: Major
Found in src/aspectlib/test.py - About 1 day to fix

    Function _handle has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        def _handle(self, binding, name, args, kwargs, wrapped, bind=None):
            pk = self._make_key(binding, name, args, kwargs)
            if pk in self._expected:
                result = self._actual[pk] = self._expected[pk]
                if isinstance(result, _Binds):
    Severity: Minor
    Found in src/aspectlib/test.py - About 4 hrs 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 __call__ has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def __call__(self, *args, **kwargs):
            record = not self.__recurse_lock or self.__recurse_lock.acquire(False)
            try:
                if self.__results:
                    try:
    Severity: Minor
    Found in src/aspectlib/test.py - About 2 hrs 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 _format_calls has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def _format_calls(calls):
        for (binding, name, args, kwargs), result in calls.items():
            sig = '%s(%s%s%s)' % (name, args, ', ' if kwargs and args else '', kwargs)
    
            if isinstance(result, _Binds):
    Severity: Minor
    Found in src/aspectlib/test.py - About 1 hr 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 has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def has(self, message, *args, **kwargs):
            level = kwargs.pop('level', None)
            assert not kwargs, "Unexpected arguments: %s" % kwargs
            for call_final_message, call_message, call_args, call_level in self._calls:
                if level is None or level == call_level:
    Severity: Minor
    Found in src/aspectlib/test.py - About 1 hr 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 __record has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def __record(self, args, kwargs, *response):
            if self.__callback is not None:
                self.__callback(self.__binding, qualname(self), args, kwargs, *response)
            if self.calls is not None:
                if self.__extended:
    Severity: Minor
    Found in src/aspectlib/test.py - About 1 hr 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 __exit__ has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def __exit__(self, *exception):
            super(Replay, self).__exit__()
            if self._strict or self._dump:
                diff = self.diff
                if diff:
    Severity: Minor
    Found in src/aspectlib/test.py - About 1 hr 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 __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, wrapped, iscalled=True, calls=None, callback=None, extended=False, results=False, recurse_lock=None, binding=None):
    Severity: Major
    Found in src/aspectlib/test.py - About 1 hr to fix

      Function __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, play, proxy=True, strict=True, dump=True, recurse_lock=False, **options):
      Severity: Minor
      Found in src/aspectlib/test.py - About 45 mins to fix

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

            def _callback(self, _binding, qualname, args, _kwargs):
                _, name = qualname.rsplit('.', 1)
        
                if name == 'log':
                    level, args = _checkLevel(args[0]), args[1:]
        Severity: Minor
        Found in src/aspectlib/test.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 _handle has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def _handle(self, binding, name, args, kwargs, wrapped, bind=None):
        Severity: Minor
        Found in src/aspectlib/test.py - About 45 mins to fix

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

              def _handle(self, binding, name, args, kwargs, result):
          Severity: Minor
          Found in src/aspectlib/test.py - About 35 mins to fix

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

                    elif isinstance(result, _Raises):
                        if binding is None:
                            yield '%s ** %s  # raises\n' % (sig, result.value)
                        else:
                            yield '%s.%s ** %s  # raises\n' % (binding, sig, result.value)
            Severity: Major
            Found in src/aspectlib/test.py and 1 other location - About 1 hr to fix
            src/aspectlib/test.py on lines 740..744

            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 44.

            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

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

                    elif isinstance(result, _Returns):
                        if binding is None:
                            yield '%s == %s  # returns\n' % (sig, result.value)
                        else:
                            yield '%s.%s == %s  # returns\n' % (binding, sig, result.value)
            Severity: Major
            Found in src/aspectlib/test.py and 1 other location - About 1 hr to fix
            src/aspectlib/test.py on lines 745..749

            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 44.

            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

            There are no issues that match your filters.

            Category
            Status