tesseract v5.3.3.20231005
googletest-json-output-unittest.GTestJsonOutputUnitTest Class Reference
Inheritance diagram for googletest-json-output-unittest.GTestJsonOutputUnitTest:

Public Member Functions

def testNonEmptyJsonOutput (self)
 
def testNoTestJsonOutput (self)
 
def testTimestampValue (self)
 
def testDefaultOutputFile (self)
 
def testSuppressedJsonOutput (self)
 
def testFilteredTestJsonOutput (self)
 

Detailed Description

Unit test for Google Test's JSON output functionality.

Definition at line 676 of file googletest-json-output-unittest.py.

Member Function Documentation

◆ testDefaultOutputFile()

def googletest-json-output-unittest.GTestJsonOutputUnitTest.testDefaultOutputFile (   self)
Verifies the default output file name.

Confirms that Google Test produces an JSON output file with the expected
default name if no name is explicitly specified.

Definition at line 725 of file googletest-json-output-unittest.py.

725 def testDefaultOutputFile(self):
726 """Verifies the default output file name.
727
728 Confirms that Google Test produces an JSON output file with the expected
729 default name if no name is explicitly specified.
730 """
731 output_file = os.path.join(gtest_test_utils.GetTempDir(),
732 GTEST_DEFAULT_OUTPUT_FILE)
734 'gtest_no_test_unittest')
735 try:
736 os.remove(output_file)
737 except OSError:
738 e = sys.exc_info()[1]
739 if e.errno != errno.ENOENT:
740 raise
741
743 [gtest_prog_path, '%s=json' % GTEST_OUTPUT_FLAG],
744 working_dir=gtest_test_utils.GetTempDir())
745 self.assert_(p.exited)
746 self.assertEquals(0, p.exit_code)
747 self.assert_(os.path.isfile(output_file))
748
def GetTestExecutablePath(executable_name, build_dir=None)

◆ testFilteredTestJsonOutput()

def googletest-json-output-unittest.GTestJsonOutputUnitTest.testFilteredTestJsonOutput (   self)
Verifies JSON output when a filter is applied.

Runs a test program that executes only some tests and verifies that
non-selected tests do not show up in the JSON output.

Definition at line 779 of file googletest-json-output-unittest.py.

779 def testFilteredTestJsonOutput(self):
780 """Verifies JSON output when a filter is applied.
781
782 Runs a test program that executes only some tests and verifies that
783 non-selected tests do not show up in the JSON output.
784 """
785
786 self._TestJsonOutput(GTEST_PROGRAM_NAME, EXPECTED_FILTERED, 0,
787 extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG])
788

◆ testNonEmptyJsonOutput()

def googletest-json-output-unittest.GTestJsonOutputUnitTest.testNonEmptyJsonOutput (   self)
Verifies JSON output for a Google Test binary with non-empty output.

Runs a test program that generates a non-empty JSON output, and
tests that the JSON output is expected.

Definition at line 684 of file googletest-json-output-unittest.py.

684 def testNonEmptyJsonOutput(self):
685 """Verifies JSON output for a Google Test binary with non-empty output.
686
687 Runs a test program that generates a non-empty JSON output, and
688 tests that the JSON output is expected.
689 """
690 self._TestJsonOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY, 1)
691

◆ testNoTestJsonOutput()

def googletest-json-output-unittest.GTestJsonOutputUnitTest.testNoTestJsonOutput (   self)
Verifies JSON output for a Google Test binary without actual tests.

Runs a test program that generates an JSON output for a binary with no
tests, and tests that the JSON output is expected.

Definition at line 692 of file googletest-json-output-unittest.py.

692 def testNoTestJsonOutput(self):
693 """Verifies JSON output for a Google Test binary without actual tests.
694
695 Runs a test program that generates an JSON output for a binary with no
696 tests, and tests that the JSON output is expected.
697 """
698
699 self._TestJsonOutput('gtest_no_test_unittest', EXPECTED_NO_TEST, 0)
700

◆ testSuppressedJsonOutput()

def googletest-json-output-unittest.GTestJsonOutputUnitTest.testSuppressedJsonOutput (   self)
Verifies that no JSON output is generated.

Tests that no JSON file is generated if the default JSON listener is
shut down before RUN_ALL_TESTS is invoked.

Definition at line 749 of file googletest-json-output-unittest.py.

749 def testSuppressedJsonOutput(self):
750 """Verifies that no JSON output is generated.
751
752 Tests that no JSON file is generated if the default JSON listener is
753 shut down before RUN_ALL_TESTS is invoked.
754 """
755
756 json_path = os.path.join(gtest_test_utils.GetTempDir(),
757 GTEST_PROGRAM_NAME + 'out.json')
758 if os.path.isfile(json_path):
759 os.remove(json_path)
760
761 command = [GTEST_PROGRAM_PATH,
762 '%s=json:%s' % (GTEST_OUTPUT_FLAG, json_path),
763 '--shut_down_xml']
764 p = gtest_test_utils.Subprocess(command)
765 if p.terminated_by_signal:
766 # p.signal is available only if p.terminated_by_signal is True.
767 self.assertFalse(
768 p.terminated_by_signal,
769 '%s was killed by signal %d' % (GTEST_PROGRAM_NAME, p.signal))
770 else:
771 self.assert_(p.exited)
772 self.assertEquals(1, p.exit_code,
773 "'%s' exited with code %s, which doesn't match "
774 'the expected exit code %s.'
775 % (command, p.exit_code, 1))
776
777 self.assert_(not os.path.isfile(json_path))
778

◆ testTimestampValue()

def googletest-json-output-unittest.GTestJsonOutputUnitTest.testTimestampValue (   self)
Checks whether the timestamp attribute in the JSON output is valid.

Runs a test program that generates an empty JSON output, and checks if
the timestamp attribute in the testsuites tag is valid.

Definition at line 701 of file googletest-json-output-unittest.py.

701 def testTimestampValue(self):
702 """Checks whether the timestamp attribute in the JSON output is valid.
703
704 Runs a test program that generates an empty JSON output, and checks if
705 the timestamp attribute in the testsuites tag is valid.
706 """
707 actual = self._GetJsonOutput('gtest_no_test_unittest', [], 0)
708 date_time_str = actual['timestamp']
709 # datetime.strptime() is only available in Python 2.5+ so we have to
710 # parse the expected datetime manually.
711 match = re.match(r'(\d+)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)', date_time_str)
712 self.assertTrue(
713 re.match,
714 'JSON datettime string %s has incorrect format' % date_time_str)
715 date_time_from_json = datetime.datetime(
716 year=int(match.group(1)), month=int(match.group(2)),
717 day=int(match.group(3)), hour=int(match.group(4)),
718 minute=int(match.group(5)), second=int(match.group(6)))
719
720 time_delta = abs(datetime.datetime.now() - date_time_from_json)
721 # timestamp value should be near the current local time
722 self.assertTrue(time_delta < datetime.timedelta(seconds=600),
723 'time_delta is %s' % time_delta)
724

The documentation for this class was generated from the following file: