def testCorrectFormatWithActiveColocations(self):
   t_obj_1 = traceable_stack.TraceableObject(
       None, filename="test_1.py", lineno=27)
   t_obj_2 = traceable_stack.TraceableObject(
       None, filename="test_2.py", lineno=38)
   colocation_dict = {
       "test_node_1": t_obj_1,
       "test_node_2": t_obj_2,
   }
   summary = error_interpolation._compute_colocation_summary_from_dict(
       "node_name", colocation_dict, prefix="  ")
   self.assertIn("node_name", summary)
   self.assertIn("colocate_with(test_node_1)", summary)
   self.assertIn("<test_1.py:27>", summary)
   self.assertIn("colocate_with(test_node_2)", summary)
   self.assertIn("<test_2.py:38>", summary)
  def testCorrectFormatWithActiveDeviceAssignments(self):
    assignments = []
    assignments.append(
        traceable_stack.TraceableObject(
            "/cpu:0", filename="hope.py", lineno=24))
    assignments.append(
        traceable_stack.TraceableObject(
            "/gpu:2", filename="please.py", lineno=42))

    summary = error_interpolation._compute_device_summary_from_list(
        "nodename", assignments, prefix="  ")

    self.assertIn("nodename", summary)
    self.assertIn("tf.device(/cpu:0)", summary)
    self.assertIn("<hope.py:24>", summary)
    self.assertIn("tf.device(/gpu:2)", summary)
    self.assertIn("<please.py:42>", summary)
    def testSetFilenameAndLineFromCallerHandlesRidiculousOffset(self):
        t_obj = traceable_stack.TraceableObject('The quick brown fox.')
        # This line shouldn't die.
        result = t_obj.set_filename_and_line_from_caller(offset=300)

        # We expect a heuristic to be used because we are not currently 300 frames
        # down on the stack.  The filename should be some wacky thing from the
        # outermost stack frame -- definitely not equal to this filename.
        self.assertEqual(t_obj.HEURISTIC_USED, result)
        self.assertNotEqual(_THIS_FILENAME, t_obj.filename)
Esempio n. 4
0
    def testSetFilenameAndLineFromCallerHandlesRidiculousOffset(self):
        t_obj = traceable_stack.TraceableObject('The quick brown fox.')
        # This line shouldn't die.
        result = t_obj.set_filename_and_line_from_caller(offset=300)

        # We expect a heuristic to be used because we are not currently 300 frames
        # down on the stack.  The filename and lineno of the outermost frame are not
        # predictable -- in some environments the filename is this test file, but in
        # other environments it is not (e.g. due to a test runner calling this
        # file).  Therefore we only test that the called function knows it applied a
        # heuristic for the ridiculous stack offset.
        self.assertEqual(t_obj.HEURISTIC_USED, result)
Esempio n. 5
0
    def testSetFilenameAndLineFromCallerUsesCallersStack(self):
        t_obj = traceable_stack.TraceableObject(17)

        # Do not separate placeholder from the set_filename_and_line_from_caller()
        # call one line below it as it is used to calculate the latter's line
        # number.
        placeholder = lambda x: x
        result = t_obj.set_filename_and_line_from_caller()

        expected_lineno = inspect.getsourcelines(placeholder)[1] + 1
        self.assertEqual(expected_lineno, t_obj.lineno)
        self.assertEqual(_THIS_FILENAME, t_obj.filename)
        self.assertEqual(t_obj.SUCCESS, result)
 def testCorrectFormatWithActiveColocations(self):
   t_obj_1 = traceable_stack.TraceableObject(None,
                                             filename="test_1.py",
                                             lineno=27)
   t_obj_2 = traceable_stack.TraceableObject(None,
                                             filename="test_2.py",
                                             lineno=38)
   colocation_dict = {
       "test_node_1": t_obj_1,
       "test_node_2": t_obj_2,
   }
   summary = error_interpolation._compute_colocation_summary_from_dict(
       colocation_dict, prefix="  ")
   assert_node_in_colocation_summary(self,
                                     summary,
                                     name="test_node_1",
                                     filename="test_1.py",
                                     lineno=27)
   assert_node_in_colocation_summary(self, summary,
                                     name="test_node_2",
                                     filename="test_2.py",
                                     lineno=38)
Esempio n. 7
0
    def testSetFilenameAndLineFromCallerRespectsOffset(self):
        def call_set_filename_and_line_from_caller(t_obj):
            # We expect to retrieve the line number from _our_ caller.
            return t_obj.set_filename_and_line_from_caller(offset=1)

        t_obj = traceable_stack.TraceableObject(None)
        # Do not separate placeholder from the
        # call_set_filename_and_line_from_caller() call one line below it as it is
        # used to calculate the latter's line number.
        placeholder = lambda x: x
        result = call_set_filename_and_line_from_caller(t_obj)

        expected_lineno = inspect.getsourcelines(placeholder)[1] + 1
        self.assertEqual(expected_lineno, t_obj.lineno)
        self.assertEqual(t_obj.SUCCESS, result)