edgewall/trac

View on GitHub
trac/test.py

Summary

Maintainability
D
3 days
Test Coverage

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

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2003-2023 Edgewall Software
# Copyright (C) 2003-2005 Jonas Borgström <jonas@edgewall.com>
Severity: Minor
Found in trac/test.py - About 7 hrs to fix

    Function test_suite has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def test_suite():
        import trac.tests
        import trac.admin.tests
        import trac.db.tests
        import trac.mimeview.tests
    Severity: Minor
    Found in trac/test.py - About 1 hr to fix

      Function get_dburi has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_dburi():
          dburi = os.environ.get('TRAC_TEST_DB_URI')
          if dburi:
              scheme, db_prop = parse_connection_uri(dburi)
              # Assume the schema 'tractest' for PostgreSQL
      Severity: Minor
      Found in trac/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 rmtree has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      def rmtree(path):
          def onexc(function, path, e):
              # `os.unlink` and `os.remove` fail for a readonly file on Windows.
              # Then, it attempts to be writable and remove.
              if function not in (os.unlink, os.remove):
      Severity: Minor
      Found in trac/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 MockRequest has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def MockRequest(env, **kwargs):
          """Request object for testing. Keyword arguments populate an
          `environ` dictionary and the callbacks.
      
          If `authname` is specified in a keyword arguments a `PermissionCache`
      Severity: Minor
      Found in trac/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 Mock has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def Mock(bases=(), *initargs, **kw):
          """
          Simple factory for dummy classes that can be used as replacement for the
          real implementation in tests.
      
      
      Severity: Minor
      Found in trac/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 a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(self, default_data=False, enable=None, disable=None,
                       path=None, destroying=False, config=None):
              """Construct a new Environment stub object.
      
              :param default_data: If True, populate the database with some
      Severity: Minor
      Found in trac/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 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, default_data=False, enable=None, disable=None,
      Severity: Minor
      Found in trac/test.py - About 45 mins to fix

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

            def reset_db(self, default_data=None):
                """Remove all data from Trac tables, keeping the tables themselves.
        
                :param default_data: after clean-up, initialize with default data
                :return: True upon success
        Severity: Minor
        Found in trac/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 require has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def require(self, action, realm_or_resource=None, id=False, version=False,
        Severity: Minor
        Found in trac/test.py - About 35 mins to fix

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

              def _wrapped_run(self, *args, **kwargs):
                  """Python 2.7 / unittest2 compatibility - there must be a better
                  way..."""
                  self.setUp()
                  if hasattr(self, 'fixture'):
          Severity: Minor
          Found in trac/test.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 run has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def run(self, result):
                  """Setup the fixture (self.setUp), call .setFixture on all the tests,
                  and tear down the fixture (self.tearDown)."""
                  self.setUp()
                  if hasattr(self, 'fixture'):
          Severity: Minor
          Found in trac/test.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

                  if hasattr(self, 'fixture'):
                      for test in self._tests:
                          if hasattr(test, 'setFixture'):
                              test.setFixture(self.fixture)
          Severity: Minor
          Found in trac/test.py and 1 other location - About 55 mins to fix
          trac/test.py on lines 266..269

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

          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

                  if hasattr(self, 'fixture'):
                      for test in self._tests:
                          if hasattr(test, 'setFixture'):
                              test.setFixture(self.fixture)
          Severity: Minor
          Found in trac/test.py and 1 other location - About 55 mins to fix
          trac/test.py on lines 278..281

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

          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

                  for name_or_class in enable or ():
                      config_key = self._component_name(name_or_class)
                      self.config.set('components', config_key, 'enabled')
          Severity: Minor
          Found in trac/test.py and 1 other location - About 45 mins to fix
          trac/test.py on lines 375..377

          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

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

                  for name_or_class in disable or ():
                      config_key = self._component_name(name_or_class)
                      self.config.set('components', config_key, 'disabled')
          Severity: Minor
          Found in trac/test.py and 1 other location - About 45 mins to fix
          trac/test.py on lines 372..374

          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

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

                  if enable is not None and not isinstance(enable, (list, tuple)):
                      raise TypeError('Keyword argument "enable" must be a list')
          Severity: Minor
          Found in trac/test.py and 1 other location - About 40 mins to fix
          trac/test.py on lines 345..346

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

          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 disable is not None and not isinstance(disable, (list, tuple)):
                      raise TypeError('Keyword argument "disable" must be a list')
          Severity: Minor
          Found in trac/test.py and 1 other location - About 40 mins to fix
          trac/test.py on lines 343..344

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

          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