ArturSpirin/test_junkie

View on GitHub
test_junkie/reporter/analyzer.py

Summary

Maintainability
A
3 hrs
Test Coverage

Avoid deeply nested control flow statements.
Open

                        if Analyzer.is_similar(traceback, key):
                            self.__analysis["traceback_insights"][key]["similar"].append(test_id)
            elif traceback and index == 0:
Severity: Major
Found in test_junkie/reporter/analyzer.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            if len(data["data"]["similar"]) > 0:
                                tb = Reporter.escape(data["traceback"], quote=True)
    
                                analysis.append(
                                    "{similar_count} test failures due to a similar "
    Severity: Major
    Found in test_junkie/reporter/analyzer.py - About 45 mins to fix

      Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed.
      Open

          def analyze(self, test_id, tracebacks, performance):
      Severity: Critical
      Found in test_junkie/reporter/analyzer.py by sonar-python

      Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

      See

      Refactor this function to reduce its Cognitive Complexity from 38 to the 15 allowed.
      Open

          def analysis(self):
      Severity: Critical
      Found in test_junkie/reporter/analyzer.py by sonar-python

      Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

      See

      Either merge this branch with the identical one on line "86" or change one of the implementations.
      Open

                              ones_to_report_on.update({test_id: {"data": category, "traceback": traceback}})

      Having two branches in the same if structure with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.

      Noncompliant Code Example

      if 0 <= a < 10:
          do_the_thing()
      elif 10 <= a < 20:
          do_the_other_thing()
      elif 20 <= a < 50:
          do_the_thing()  # Noncompliant; duplicates first condition
      else:
          do_the_rest()
      
      b = 4 if a > 12 else 4
      

      Compliant Solution

      if (0 <= a < 10) or (20 <= a < 50):
          do_the_thing()
      elif 10 <= a < 20:
          do_the_other_thing()
      else:
          do_the_rest()
      
      b = 4
      

      or

      if 0 <= a < 10:
          do_the_thing()
      elif 10 <= a < 20:
          do_the_other_thing()
      elif 20 <= a < 50:
          do_the_third_thing()
      else:
          do_the_rest()
      
      b = 8 if a > 12 else 4
      

      Merge this if statement with the enclosing one.
      Open

                              if Analyzer.is_similar(traceback, key):

      Merging collapsible if statements increases the code's readability.

      Noncompliant Code Example

      if condition1:
          if condition2:
              # ...
      

      Compliant Solution

      if condition1 and condition2:
          # ...
      

      Remove this commented out code.
      Open

                          # tb = traceback.replace("\n", "<br>").replace("    ", "&emsp;")

      Programmers should not comment out code as it bloats programs and reduces readability.

      Unused code should be deleted and can be retrieved from source control history if required.

      See

      • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
      • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
      • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
      • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

      Merge this if statement with the enclosing one.
      Open

                  if not self.__analysis["stable"]:

      Merging collapsible if statements increases the code's readability.

      Noncompliant Code Example

      if condition1:
          if condition2:
              # ...
      

      Compliant Solution

      if condition1 and condition2:
          # ...
      

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

                  if mem >= value:
                      self.__analysis["resources"]["mem"][level].append(mem)
      Severity: Major
      Found in test_junkie/reporter/analyzer.py and 1 other location - About 1 hr to fix
      test_junkie/reporter/analyzer.py on lines 21..22

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

      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

                  if cpu >= value:
                      self.__analysis["resources"]["cpu"][level].append(cpu)
      Severity: Major
      Found in test_junkie/reporter/analyzer.py and 1 other location - About 1 hr to fix
      test_junkie/reporter/analyzer.py on lines 23..24

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

      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