avocado-framework/avocado

View on GitHub
avocado/core/loader.py

Summary

Maintainability
F
5 days
Test Coverage
C
78%

File loader.py has 755 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
Severity: Major
Found in avocado/core/loader.py - About 1 day to fix

    Function discover has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

        def discover(self, references, which_tests=DiscoverMode.DEFAULT, force=None):
            """
            Discover (possible) tests from test references.
    
            :param references: a list of tests references; if [] use plugin defaults
    Severity: Minor
    Found in avocado/core/loader.py - About 5 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 _make_python_file_tests has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def _make_python_file_tests(self, test_path, make_broken,
                                    subtests_filter, test_name=None):
            if test_name is None:
                test_name = test_path
            try:
    Severity: Minor
    Found in avocado/core/loader.py - About 3 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 load_plugins has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def load_plugins(self, config):
            if self._initialized_plugins:
                return
    
            def _good_test_types(plugin):
    Severity: Minor
    Found in avocado/core/loader.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 load_test has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def load_test(test_factory):
            """
            Load test from the test factory.
    
            :param test_factory: a pair of test class and parameters.
    Severity: Minor
    Found in avocado/core/loader.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 _discover has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def _discover(self, reference, which_tests=DiscoverMode.DEFAULT):
            """
            Recursively walk in a directory and find tests params.
            The tests are returned in alphabetic order.
    
    
    Severity: Minor
    Found in avocado/core/loader.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 _make_tests has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def _make_tests(self, test_path, list_non_tests, subtests_filter=None):
            """
            Create test templates from given path
            :param test_path: File system path
            :param list_non_tests: include bad tests (NotATest, BrokenSymlink,...)
    Severity: Minor
    Found in avocado/core/loader.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 _process_external_runner has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def _process_external_runner(config, runner):
            """ Enables the external_runner when asked for """
            subcommand = config.get('subcommand')
            chdir = config.get("{}.external_runner_chdir".format(subcommand))
            test_dir = config.get("{}.external_runner_testdir".format(subcommand))
    Severity: Minor
    Found in avocado/core/loader.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 _find_python_unittests has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _find_python_unittests(test_path, disabled, subtests_filter):
            result = []
            class_methods = safeloader.find_python_unittests(test_path)
            for klass, methods in class_methods.items():
                if klass in disabled:
    Severity: Minor
    Found in avocado/core/loader.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

    Avoid deeply nested control flow statements.
    Open

                                if which_tests != DiscoverMode.ALL:
                                    break  # Don't process other plugins
                        except Exception as details:  # pylint: disable=W0703
    Severity: Major
    Found in avocado/core/loader.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                                  if (subtests_filter and
                                          not subtests_filter.search(name)):
                                      continue
                                  tst = (test_class, {'name': name,
      Severity: Major
      Found in avocado/core/loader.py - About 45 mins to fix

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

            def _make_nonexisting_file_tests(self, test_path, make_broken,
                                             subtests_filter, test_name):
                # Try to resolve test ID (keep compatibility)
                test_path = os.path.join(data_dir.get_test_dir(), test_name)
                if os.path.exists(test_path):
        Severity: Minor
        Found in avocado/core/loader.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

        Avoid too many return statements within this function.
        Open

                    return self._make_nonexisting_file_tests(test_path, make_broken,
        Severity: Major
        Found in avocado/core/loader.py - About 30 mins to fix

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

              def __init__(self, config, extra_params):  # pylint: disable=W0613
                  if "allowed_test_types" in extra_params:
                      mapping = self.get_type_label_mapping()
                      types = extra_params.pop("allowed_test_types")
                      if len(mapping) != 1:
          Severity: Minor
          Found in avocado/core/loader.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

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

              def discover(self, reference, which_tests=DiscoverMode.DEFAULT):
                  """
                  Discover (possible) tests from a directory.
          
                  Recursively walk in a directory and find tests params.
          Severity: Minor
          Found in avocado/core/loader.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

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

              def _make_simple_or_broken_test(self, test_path, subtests_filter, make_broken):
                  if os.access(test_path, os.X_OK):
                      return self._make_simple_test(test_path, subtests_filter)
                  else:
                      return make_broken(NotATest, test_path,
          Severity: Major
          Found in avocado/core/loader.py and 1 other location - About 1 hr to fix
          avocado/core/loader.py on lines 721..730

          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

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

              def _make_simple_or_broken_test(self, test_path, subtests_filter, make_broken):
                  if os.access(test_path, os.X_OK):
                      # Module does not have an avocado test class inside but
                      # it's executable, let's execute it.
                      return self._make_simple_test(test_path, subtests_filter)
          Severity: Major
          Found in avocado/core/loader.py and 1 other location - About 1 hr to fix
          avocado/core/loader.py on lines 588..593

          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