tesseract v5.3.3.20231005
gtest_test_utils Namespace Reference

Classes

class  Subprocess
 

Functions

def SetEnvVar (env_var, value)
 
def GetFlag (flag)
 
def GetSourceDir ()
 
def GetBuildDir ()
 
def GetTempDir ()
 
def GetTestExecutablePath (executable_name, build_dir=None)
 
def GetExitStatus (exit_code)
 
def Main ()
 

Variables

string IS_WINDOWS = 'nt'
 
string IS_CYGWIN = 'posix' and 'CYGWIN' in os.uname()[0]
 
string IS_OS2 = 'os2'
 
string GTEST_OUTPUT_VAR_NAME = 'GTEST_OUTPUT'
 
string PREMATURE_EXIT_FILE_ENV_VAR = 'TEST_PREMATURE_EXIT_FILE'
 
 environ = os.environ.copy()
 
 TestCase = _test_module.TestCase
 

Function Documentation

◆ GetBuildDir()

def gtest_test_utils.GetBuildDir ( )
Returns the absolute path of the directory where the test binaries are.

Definition at line 129 of file gtest_test_utils.py.

129def GetBuildDir():
130 """Returns the absolute path of the directory where the test binaries are."""
131
132 return os.path.abspath(GetFlag('build_dir'))
133
134

◆ GetExitStatus()

def gtest_test_utils.GetExitStatus (   exit_code)
Returns the argument to exit(), or -1 if exit() wasn't called.

Args:
  exit_code: the result value of os.system(command).

Definition at line 182 of file gtest_test_utils.py.

182def GetExitStatus(exit_code):
183 """Returns the argument to exit(), or -1 if exit() wasn't called.
184
185 Args:
186 exit_code: the result value of os.system(command).
187 """
188
189 if os.name == 'nt':
190 # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns
191 # the argument to exit() directly.
192 return exit_code
193 else:
194 # On Unix, os.WEXITSTATUS() must be used to extract the exit status
195 # from the result of os.system().
196 if os.WIFEXITED(exit_code):
197 return os.WEXITSTATUS(exit_code)
198 else:
199 return -1
200
201
def GetExitStatus(exit_code)

◆ GetFlag()

def gtest_test_utils.GetFlag (   flag)
Returns the value of the given flag.

Definition at line 112 of file gtest_test_utils.py.

112def GetFlag(flag):
113 """Returns the value of the given flag."""
114
115 # In case GetFlag() is called before Main(), we always call
116 # _ParseAndStripGTestFlags() here to make sure the --gtest_* flags
117 # are parsed.
118 _ParseAndStripGTestFlags(sys.argv)
119
120 return _flag_map[flag]
121
122

◆ GetSourceDir()

def gtest_test_utils.GetSourceDir ( )
Returns the absolute path of the directory where the .py files are.

Definition at line 123 of file gtest_test_utils.py.

123def GetSourceDir():
124 """Returns the absolute path of the directory where the .py files are."""
125
126 return os.path.abspath(GetFlag('source_dir'))
127
128

◆ GetTempDir()

def gtest_test_utils.GetTempDir ( )

Definition at line 144 of file gtest_test_utils.py.

144def GetTempDir():
145 global _temp_dir
146 if not _temp_dir:
147 _temp_dir = tempfile.mkdtemp()
148 return _temp_dir
149
150

◆ GetTestExecutablePath()

def gtest_test_utils.GetTestExecutablePath (   executable_name,
  build_dir = None 
)
Returns the absolute path of the test binary given its name.

The function will print a message and abort the program if the resulting file
doesn't exist.

Args:
  executable_name: name of the test binary that the test script runs.
  build_dir:       directory where to look for executables, by default
                   the result of GetBuildDir().

Returns:
  The absolute path of the test binary.

Definition at line 151 of file gtest_test_utils.py.

151def GetTestExecutablePath(executable_name, build_dir=None):
152 """Returns the absolute path of the test binary given its name.
153
154 The function will print a message and abort the program if the resulting file
155 doesn't exist.
156
157 Args:
158 executable_name: name of the test binary that the test script runs.
159 build_dir: directory where to look for executables, by default
160 the result of GetBuildDir().
161
162 Returns:
163 The absolute path of the test binary.
164 """
165
166 path = os.path.abspath(os.path.join(build_dir or GetBuildDir(),
167 executable_name))
168 if (IS_WINDOWS or IS_CYGWIN or IS_OS2) and not path.endswith('.exe'):
169 path += '.exe'
170
171 if not os.path.exists(path):
172 message = (
173 'Unable to find the test binary "%s". Please make sure to provide\n'
174 'a path to the binary via the --build_dir flag or the BUILD_DIR\n'
175 'environment variable.' % path)
176 print >> sys.stderr, message
177 sys.exit(1)
178
179 return path
180
181
def GetTestExecutablePath(executable_name, build_dir=None)

◆ Main()

def gtest_test_utils.Main ( )
Runs the unit test.

Definition at line 300 of file gtest_test_utils.py.

300def Main():
301 """Runs the unit test."""
302
303 # We must call _ParseAndStripGTestFlags() before calling
304 # unittest.main(). Otherwise the latter will be confused by the
305 # --gtest_* flags.
306 _ParseAndStripGTestFlags(sys.argv)
307 # The tested binaries should not be writing XML output files unless the
308 # script explicitly instructs them to.
309 if GTEST_OUTPUT_VAR_NAME in os.environ:
310 del os.environ[GTEST_OUTPUT_VAR_NAME]
311
312 _test_module.main()

◆ SetEnvVar()

def gtest_test_utils.SetEnvVar (   env_var,
  value 
)
Sets/unsets an environment variable to a given value.

Definition at line 62 of file gtest_test_utils.py.

62def SetEnvVar(env_var, value):
63 """Sets/unsets an environment variable to a given value."""
64
65 if value is not None:
66 environ[env_var] = value
67 elif env_var in environ:
68 del environ[env_var]
69
70
71# Here we expose a class from a particular module, depending on the
72# environment. The comment suppresses the 'Invalid variable name' lint
73# complaint.
def SetEnvVar(env_var, value)

Variable Documentation

◆ environ

gtest_test_utils.environ = os.environ.copy()

Definition at line 59 of file gtest_test_utils.py.

◆ GTEST_OUTPUT_VAR_NAME

string gtest_test_utils.GTEST_OUTPUT_VAR_NAME = 'GTEST_OUTPUT'

Definition at line 54 of file gtest_test_utils.py.

◆ IS_CYGWIN

string gtest_test_utils.IS_CYGWIN = 'posix' and 'CYGWIN' in os.uname()[0]

Definition at line 38 of file gtest_test_utils.py.

◆ IS_OS2

string gtest_test_utils.IS_OS2 = 'os2'

Definition at line 39 of file gtest_test_utils.py.

◆ IS_WINDOWS

string gtest_test_utils.IS_WINDOWS = 'nt'

Definition at line 37 of file gtest_test_utils.py.

◆ PREMATURE_EXIT_FILE_ENV_VAR

string gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR = 'TEST_PREMATURE_EXIT_FILE'

Definition at line 57 of file gtest_test_utils.py.

◆ TestCase

gtest_test_utils.TestCase = _test_module.TestCase

Definition at line 74 of file gtest_test_utils.py.