tensorflow/tensorflow

View on GitHub
tensorflow/python/framework/test_util.py

Summary

Maintainability
F
2 wks
Test Coverage

File test_util.py has 3276 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Major
Found in tensorflow/python/framework/test_util.py - About 1 wk to fix

    Function _find_reference_cycle has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
    Open

    def _find_reference_cycle(objects: Sequence[Any], idx: int) -> bool:
    
      def get_ignore_reason(obj: Any, denylist: Collection[Any]) -> Optional[str]:
        """Tests whether an object should be omitted from the dependency graph."""
        if len(denylist) > 100:
    Severity: Minor
    Found in tensorflow/python/framework/test_util.py - About 1 day 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

    TensorFlowTestCase has 43 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class TensorFlowTestCase(googletest.TestCase):
      """Base class for tests that need to test TensorFlow."""
    
      def __init__(self, methodName="runTest"):  # pylint: disable=invalid-name
        super().__init__(methodName)
    Severity: Minor
    Found in tensorflow/python/framework/test_util.py - About 5 hrs to fix

      Function assert_no_garbage_created has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

      def assert_no_garbage_created(f: _F) -> _F:
        """Test method decorator to assert that no garbage has been created.
      
        Note that this decorator sets DEBUG_SAVEALL, which in some Python interpreters
        cannot be un-set (i.e. will disable garbage collection for any other unit
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 assertAllEqual has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

        def assertAllEqual(self, a, b, msg=None):
          """Asserts that two numpy arrays or Tensors have the same values.
      
          Args:
            a: the expected numpy ndarray or anything can be converted to one.
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 assert_no_new_pyobjects_executing_eagerly has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

      def assert_no_new_pyobjects_executing_eagerly(
          warmup_iters: int = 2,
      ) -> Callable[[Callable[..., Any]], Callable[..., None]]:
        """Decorator for asserting that no new Python objects persist after a test.
      
      
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 _assertAllCloseRecursive has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

        def _assertAllCloseRecursive(self,
                                     a,
                                     b,
                                     rtol=1e-6,
                                     atol=1e-6,
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 run_in_graph_and_eager_modes has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

      def run_in_graph_and_eager_modes(
          func: Optional[Callable[..., Any]] = None,
          config: Optional[config_pb2.ConfigProto] = None,
          use_gpu: bool = True,
          assert_no_eager_garbage: bool = False,
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 _run_vn_only has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      def _run_vn_only(func=None, v2=True, reason=None):
        """Execute the decorated test only if running in the specified mode.
      
        This function is intended to be applied to tests that exercise functionality
         that belongs to either only v2, or v1.
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 _eval_tensor has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def _eval_tensor(self, tensor):
          if tensor is None:
            return None
          elif callable(tensor):
            return self._eval_helper(tensor())
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 with_forward_compatibility_horizons has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

      def with_forward_compatibility_horizons(
          *horizons: Optional[tuple[int, int, int]]
      ) -> Callable[[Callable[..., Any]], Callable[..., None]]:
        """Executes the decorated test with the specified forward-compat horizons.
      
      
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 _strip_checkpoint_v2_randomized has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      def _strip_checkpoint_v2_randomized(graph_def: graph_pb2.GraphDef) -> None:
        for node in graph_def.node:
          delete_keys: list[str] = []
          for attr_key in node.attr:
            attr_tensor_value = cast(
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 deprecated_graph_mode_only has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      def deprecated_graph_mode_only(func: Union[_TC, _F]) -> Union[_TC, _F]:
        """Execute the decorated test in graph mode.
      
        This is a decorator intended to be applied to tests that are not compatible
        with eager mode. When this decorator is applied, the test body will be run in
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 run_in_v1_v2 has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      def run_in_v1_v2(
          device_to_use: Optional[str] = None,
          assert_no_eager_garbage: bool = False,
      ) -> Callable[[Callable[..., Any]], Callable[..., None]]:
        """Execute the decorated test in v1 and v2 modes.
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 assertRaisesWithPredicateMatch has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def assertRaisesWithPredicateMatch(self, exception_type,
                                           expected_err_re_or_predicate):
          """Returns a context manager to enclose code expected to raise an exception.
      
          If the exception is an OpError, the op stack is also included in the message
      Severity: Minor
      Found in tensorflow/python/framework/test_util.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 assertAllCloseAccordingToType has 12 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def assertAllCloseAccordingToType(self,
      Severity: Major
      Found in tensorflow/python/framework/test_util.py - About 1 hr to fix

        Function disable_tfrt has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def disable_tfrt(
            unused_description: str,  # pylint: disable=unused-argument
        ) -> Callable[[Union[_TC, _F]], Union[_TC, _F, None]]:
        
          def disable_tfrt_impl(cls_or_func: Union[_TC, _F]) -> Union[_TC, _F, None]:
        Severity: Minor
        Found in tensorflow/python/framework/test_util.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 _GetNdArray has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def _GetNdArray(self, a):
            # If a is tensor-like then convert it to ndarray
            if tensor_util.is_tf_type(a):
              if isinstance(a, ops._EagerTensorBase):
                a = a.numpy()
        Severity: Minor
        Found in tensorflow/python/framework/test_util.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 is_gpu_available has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        def is_gpu_available(
            cuda_only: bool = False,
            min_cuda_compute_capability: Optional[tuple[int, int]] = None,
        ) -> bool:
          """Returns whether TensorFlow can access a GPU.
        Severity: Minor
        Found in tensorflow/python/framework/test_util.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 py_func_if_in_function has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        def py_func_if_in_function(f: _F) -> _F:
        
          def decorated(*args, **kwds):
            if not ops.inside_function():
              return f(*args, **kwds)
        Severity: Minor
        Found in tensorflow/python/framework/test_util.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 assert_no_new_tensors has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        def assert_no_new_tensors(f: _F) -> _F:
          """Decorator for asserting that no new Tensors persist after a test.
        
          Mainly useful for checking that code using the Python C API has correctly
          manipulated reference counts.
        Severity: Minor
        Found in tensorflow/python/framework/test_util.py - About 55 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 _assertArrayLikeAllClose has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def _assertArrayLikeAllClose(self, a, b, rtol=1e-6, atol=1e-6, msg=None):
            (a, b) = self.evaluate_if_both_tensors(a, b)
            a = self._GetNdArray(a)
            b = self._GetNdArray(b)
            # When the array rank is small, print its contents. Numpy array printing is
        Severity: Minor
        Found in tensorflow/python/framework/test_util.py - About 55 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 _assertAllCloseRecursive has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def _assertAllCloseRecursive(self,
        Severity: Major
        Found in tensorflow/python/framework/test_util.py - About 50 mins to fix

          Function _assertListCloseRecursive has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def _assertListCloseRecursive(self, a, b, rtol, atol, msg, path="value"):
          Severity: Major
          Found in tensorflow/python/framework/test_util.py - About 50 mins to fix

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

              def _assertArrayLikeAllClose(self, a, b, rtol=1e-6, atol=1e-6, msg=None):
            Severity: Minor
            Found in tensorflow/python/framework/test_util.py - About 45 mins to fix

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

                def assertAllInRange(self,
              Severity: Minor
              Found in tensorflow/python/framework/test_util.py - About 45 mins to fix

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

                  def assertAllInRange(self,
                                       target,
                                       lower_bound,
                                       upper_bound,
                                       open_lower_bound=False,
                Severity: Minor
                Found in tensorflow/python/framework/test_util.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 disable_cudnn_autotune has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def disable_cudnn_autotune(func: _F) -> _F:
                  """Disable autotuning during the call to this function.
                
                  Some tests want to base assertions on a graph being isomorphic with a copy.
                  To ensure this, this decorator disables autotuning.
                Severity: Minor
                Found in tensorflow/python/framework/test_util.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 _strip_hash_table_shared_name has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def _strip_hash_table_shared_name(graph_def: graph_pb2.GraphDef) -> None:
                  for node in graph_def.node:
                    delete_keys: list[str] = []
                    if node.op == "HashTableV2" and "shared_name" in node.attr:
                      if re.match(compat.as_bytes(_TABLE_SHARED_NAME_PATTERN),
                Severity: Minor
                Found in tensorflow/python/framework/test_util.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 assertNotAllClose has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  def assertNotAllClose(self, a, b, rtol=1e-6, atol=1e-6, msg=None):
                Severity: Minor
                Found in tensorflow/python/framework/test_util.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              if isinstance(item, str):
                                out_list.append(item.encode("utf-8"))
                              else:
                                out_list.append(item)
                          a = np.array(a_list)
                  Severity: Major
                  Found in tensorflow/python/framework/test_util.py - About 45 mins to fix

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

                      def assertAllClose(self, a, b, rtol=1e-6, atol=1e-6, msg=None):
                    Severity: Minor
                    Found in tensorflow/python/framework/test_util.py - About 45 mins to fix

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

                        def _assertRaggedClose(self, a, b, rtol, atol, msg=None):
                      Severity: Minor
                      Found in tensorflow/python/framework/test_util.py - About 45 mins to fix

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

                          def assertArrayNear(self, farray1, farray2, err, msg=None):
                        Severity: Minor
                        Found in tensorflow/python/framework/test_util.py - About 35 mins to fix

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

                            def assertProtoEqualsVersion(
                          Severity: Minor
                          Found in tensorflow/python/framework/test_util.py - About 35 mins to fix

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

                              def _get_cached_session(
                            Severity: Minor
                            Found in tensorflow/python/framework/test_util.py - About 35 mins to fix

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

                                def _format_subscripts(self, subscripts, value, limit=10, indent=2):
                              Severity: Minor
                              Found in tensorflow/python/framework/test_util.py - About 35 mins to fix

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

                                  def assertNDArrayNear(self, ndarray1, ndarray2, err, msg=None):
                                Severity: Minor
                                Found in tensorflow/python/framework/test_util.py - About 35 mins to fix

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

                                  def create_local_cluster(
                                  Severity: Minor
                                  Found in tensorflow/python/framework/test_util.py - About 35 mins to fix

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

                                      def assertNear(self, f1, f2, err, msg=None):
                                    Severity: Minor
                                    Found in tensorflow/python/framework/test_util.py - About 35 mins to fix

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

                                      def skip_if(condition: Union[Callable[[], bool], bool]) -> Callable[[_F], _F]:
                                        """Skips the decorated function if condition is or evaluates to True.
                                      
                                        Args:
                                          condition: Either an expression that can be used in "if not condition"
                                      Severity: Minor
                                      Found in tensorflow/python/framework/test_util.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 assert_ops_in_graph has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                      def assert_ops_in_graph(
                                          expected_ops: dict[str, str], graph: ops.Graph
                                      ) -> dict[str, node_def_pb2.NodeDef]:
                                        """Assert all expected operations are found.
                                      
                                      
                                      Severity: Minor
                                      Found in tensorflow/python/framework/test_util.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 assert_meta_graph_protos_equal has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                      def assert_meta_graph_protos_equal(
                                          tester: "TensorFlowTestCase",
                                          a: meta_graph_pb2.MetaGraphDef,
                                          b: meta_graph_pb2.MetaGraphDef,
                                      ) -> None:
                                      Severity: Minor
                                      Found in tensorflow/python/framework/test_util.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 set_xla_env_flag has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                      def set_xla_env_flag(flag: str = "") -> Callable[[_F], _F]:
                                        """Decorator for setting XLA_FLAGS prior to running a test.
                                      
                                        This function returns a decorator intended to be applied to test methods in
                                        a `tf.test.TestCase` class. Doing so will allow users to set any xla flags
                                      Severity: Minor
                                      Found in tensorflow/python/framework/test_util.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 "tuple({}): {}".format(
                                      Severity: Major
                                      Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                return "dict({}): {} keys".format(id(obj), len(obj.keys()))
                                        Severity: Major
                                        Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                              return None
                                          Severity: Major
                                          Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                return _pywrap_util_port.IsSystemZAvailable()
                                            Severity: Major
                                            Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                      return "function({}) {}; globals ID: {}".format(
                                              Severity: Major
                                              Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                        return "{}, {}".format(type(obj), id(obj))
                                                Severity: Major
                                                Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                              return tensor.numpy()
                                                  Severity: Major
                                                  Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                            return "list({}): {}".format(
                                                    Severity: Major
                                                    Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                return indexed_slices.IndexedSlicesValue(
                                                      Severity: Major
                                                      Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                                    return nest.map_structure(lambda t: t.numpy(), tensor,
                                                        Severity: Major
                                                        Found in tensorflow/python/framework/test_util.py - About 30 mins to fix

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

                                                          def IsCPUTargetAvailable(target):
                                                            if target.startswith("arm"):
                                                              return _pywrap_util_port.IsAArch32Available()
                                                            elif target.startswith("aarch64"):
                                                              return _pywrap_util_port.IsAArch64Available()
                                                          Severity: Minor
                                                          Found in tensorflow/python/framework/test_util.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 test_session has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                            def test_session(
                                                                self,
                                                                graph: Optional[ops.Graph] = None,
                                                                config: Optional[config_pb2.ConfigProto] = None,
                                                                use_gpu: bool = True,
                                                          Severity: Minor
                                                          Found in tensorflow/python/framework/test_util.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_all_in_deprecated_graph_mode_only has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                          def run_all_in_deprecated_graph_mode_only(cls: _TC) -> _TC:
                                                            """Execute all tests in a class in graph mode."""
                                                            base_decorator = deprecated_graph_mode_only
                                                            for name in dir(cls):
                                                              if (not name.startswith(unittest.TestLoader.testMethodPrefix) or
                                                          Severity: Minor
                                                          Found in tensorflow/python/framework/test_util.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_class_in_v1_v2 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                          def run_class_in_v1_v2(cls: _TC) -> _TC:
                                                            """Execute all test methods in a given class in v1 and v2 modes."""
                                                            base_decorator = run_in_v1_v2
                                                            for name in dir(cls):
                                                              if (not name.startswith(unittest.TestLoader.testMethodPrefix) or
                                                          Severity: Minor
                                                          Found in tensorflow/python/framework/test_util.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 skip_if_error has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                          def skip_if_error(
                                                              test_obj: unittest.TestCase,
                                                              error_type: type[Exception],
                                                              messages: Union[str, list[str], None] = None
                                                          ) -> Iterator[None]:
                                                          Severity: Minor
                                                          Found in tensorflow/python/framework/test_util.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 for_all_test_methods has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                          def for_all_test_methods(
                                                              decorator: Callable[..., Any], *args, **kwargs,
                                                          ) -> Callable[[_TC], _TC]:
                                                            """Generate class-level decorator from given method-level decorator.
                                                          
                                                          
                                                          Severity: Minor
                                                          Found in tensorflow/python/framework/test_util.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_all_in_graph_and_eager_modes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                          def run_all_in_graph_and_eager_modes(cls: _TC) -> _TC:
                                                            """Execute all test methods in the given class with and without eager."""
                                                            base_decorator = run_in_graph_and_eager_modes
                                                            for name in dir(cls):
                                                              if (not name.startswith(unittest.TestLoader.testMethodPrefix) or
                                                          Severity: Minor
                                                          Found in tensorflow/python/framework/test_util.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 add_graph_building_optimization_tests has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                          def add_graph_building_optimization_tests(cls: _TC) -> _TC:
                                                            """Adds methods with graph_building_optimization enabled to the test suite.
                                                          
                                                            Example:
                                                          
                                                          
                                                          Severity: Minor
                                                          Found in tensorflow/python/framework/test_util.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

                                                          There are no issues that match your filters.

                                                          Category
                                                          Status