proxygen
gtest_filter_unittest Namespace Reference

Classes

class  GTestFilterUnitTest
 

Functions

def SetEnvVar (env_var, value)
 
def RunAndReturnOutput (args=None)
 
def RunAndExtractTestList (args=None)
 
def InvokeWithModifiedEnv (extra_env, function, args, kwargs)
 
def RunWithSharding (total_shards, shard_index, command)
 

Variables

string __author__ = 'wan@google.com (Zhanyong Wan)'
 
 child
 
 CAN_PASS_EMPTY_ENV = eval(child.output)
 
 CAN_UNSET_ENV = eval(child.output)
 
tuple CAN_TEST_EMPTY_FILTER = (CAN_PASS_EMPTY_ENV and CAN_UNSET_ENV)
 
string FILTER_ENV_VAR = 'GTEST_FILTER'
 
string TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS'
 
string SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX'
 
string SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'
 
string FILTER_FLAG = 'gtest_filter'
 
string ALSO_RUN_DISABED_TESTS_FLAG = 'gtest_also_run_disabled_tests'
 
 COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_filter_unittest_')
 
 PARAM_TEST_REGEX = re.compile(r'/ParamTest')
 
 TEST_CASE_REGEX = re.compile(r'^\[\-+\] \d+ tests? from (\w+(/\w+)?)')
 
 TEST_REGEX = re.compile(r'^\[\s*RUN\s*\].*\.(\w+(/\w+)?)')
 
string LIST_TESTS_FLAG = '--gtest_list_tests'
 
string SUPPORTS_DEATH_TESTS = 'HasDeathTest'
 
list PARAM_TESTS
 
list DISABLED_TESTS
 
list DEATH_TESTS
 
list ACTIVE_TESTS
 
 param_tests_present = None
 
 environ = os.environ.copy()
 

Function Documentation

def gtest_filter_unittest.InvokeWithModifiedEnv (   extra_env,
  function,
  args,
  kwargs 
)
Runs the given function and arguments in a modified environment.

Definition at line 207 of file gtest_filter_unittest.py.

Referenced by RunWithSharding(), gtest_filter_unittest.GTestFilterUnitTest.testShardStatusFileIsCreated(), and gtest_filter_unittest.GTestFilterUnitTest.testShardStatusFileIsCreatedWithListTests().

207 def InvokeWithModifiedEnv(extra_env, function, *args, **kwargs):
208  """Runs the given function and arguments in a modified environment."""
209  try:
210  original_env = environ.copy()
211  environ.update(extra_env)
212  return function(*args, **kwargs)
213  finally:
214  environ.clear()
215  environ.update(original_env)
216 
217 
def InvokeWithModifiedEnv(extra_env, function, args, kwargs)
def gtest_filter_unittest.RunAndExtractTestList (   args = None)
Runs the test program and returns its exit code and a list of tests run.

Definition at line 188 of file gtest_filter_unittest.py.

Referenced by gtest_filter_unittest.GTestFilterUnitTest.RunAndVerify(), gtest_filter_unittest.GTestFilterUnitTest.RunAndVerifyAllowingDisabled(), and gtest_filter_unittest.GTestFilterUnitTest.testFlagOverridesEnvVar().

188 def RunAndExtractTestList(args = None):
189  """Runs the test program and returns its exit code and a list of tests run."""
190 
191  p = gtest_test_utils.Subprocess([COMMAND] + (args or []), env=environ)
192  tests_run = []
193  test_case = ''
194  test = ''
195  for line in p.output.split('\n'):
196  match = TEST_CASE_REGEX.match(line)
197  if match is not None:
198  test_case = match.group(1)
199  else:
200  match = TEST_REGEX.match(line)
201  if match is not None:
202  test = match.group(1)
203  tests_run.append(test_case + '.' + test)
204  return (tests_run, p.exit_code)
205 
206 
def RunAndExtractTestList(args=None)
def gtest_filter_unittest.RunAndReturnOutput (   args = None)
Runs the test program and returns its output.

Definition at line 181 of file gtest_filter_unittest.py.

Referenced by gtest_filter_unittest.GTestFilterUnitTest.setUp().

181 def RunAndReturnOutput(args = None):
182  """Runs the test program and returns its output."""
183 
184  return gtest_test_utils.Subprocess([COMMAND] + (args or []),
185  env=environ).output
186 
187 
def gtest_filter_unittest.RunWithSharding (   total_shards,
  shard_index,
  command 
)
Runs a test program shard and returns exit code and a list of tests run.

Definition at line 218 of file gtest_filter_unittest.py.

References InvokeWithModifiedEnv().

Referenced by gtest_filter_unittest.GTestFilterUnitTest.RunAndVerifyWithSharding().

218 def RunWithSharding(total_shards, shard_index, command):
219  """Runs a test program shard and returns exit code and a list of tests run."""
220 
221  extra_env = {SHARD_INDEX_ENV_VAR: str(shard_index),
222  TOTAL_SHARDS_ENV_VAR: str(total_shards)}
223  return InvokeWithModifiedEnv(extra_env, RunAndExtractTestList, command)
224 
225 # The unit test.
226 
227 
def RunWithSharding(total_shards, shard_index, command)
def InvokeWithModifiedEnv(extra_env, function, args, kwargs)
def gtest_filter_unittest.SetEnvVar (   env_var,
  value 
)
Sets the env variable to 'value'; unsets it when 'value' is None.

Definition at line 172 of file gtest_filter_unittest.py.

Referenced by gtest_filter_unittest.GTestFilterUnitTest.RunAndVerify(), gtest_filter_unittest.GTestFilterUnitTest.RunAndVerifyWithSharding(), and gtest_filter_unittest.GTestFilterUnitTest.testFlagOverridesEnvVar().

172 def SetEnvVar(env_var, value):
173  """Sets the env variable to 'value'; unsets it when 'value' is None."""
174 
175  if value is not None:
176  environ[env_var] = value
177  elif env_var in environ:
178  del environ[env_var]
179 
180 
def SetEnvVar(env_var, value)

Variable Documentation

string gtest_filter_unittest.__author__ = 'wan@google.com (Zhanyong Wan)'
private

Definition at line 43 of file gtest_filter_unittest.py.

list gtest_filter_unittest.ACTIVE_TESTS
Initial value:
1 = [
2  'FooTest.Abc',
3  'FooTest.Xyz',
4 
5  'BarTest.TestOne',
6  'BarTest.TestTwo',
7  'BarTest.TestThree',
8 
9  'BazTest.TestOne',
10  'BazTest.TestA',
11  'BazTest.TestB',
12  ]+DEATH_TESTS+PARAM_TESTS

Definition at line 152 of file gtest_filter_unittest.py.

string gtest_filter_unittest.ALSO_RUN_DISABED_TESTS_FLAG = 'gtest_also_run_disabled_tests'

Definition at line 100 of file gtest_filter_unittest.py.

gtest_filter_unittest.CAN_PASS_EMPTY_ENV = eval(child.output)

Definition at line 65 of file gtest_filter_unittest.py.

tuple gtest_filter_unittest.CAN_TEST_EMPTY_FILTER = (CAN_PASS_EMPTY_ENV and CAN_UNSET_ENV)

Definition at line 85 of file gtest_filter_unittest.py.

gtest_filter_unittest.CAN_UNSET_ENV = eval(child.output)

Definition at line 78 of file gtest_filter_unittest.py.

gtest_filter_unittest.child
Initial value:
2  [sys.executable, '-c', 'import os; print(\'EMPTY_VAR\' in os.environ)'])

Definition at line 63 of file gtest_filter_unittest.py.

gtest_filter_unittest.COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_filter_unittest_')

Definition at line 103 of file gtest_filter_unittest.py.

list gtest_filter_unittest.DEATH_TESTS
Initial value:
1 = [
2  'HasDeathTest.Test1',
3  'HasDeathTest.Test2',
4  ]

Definition at line 144 of file gtest_filter_unittest.py.

list gtest_filter_unittest.DISABLED_TESTS
Initial value:
1 = [
2  'BarTest.DISABLED_TestFour',
3  'BarTest.DISABLED_TestFive',
4  'BazTest.DISABLED_TestC',
5  'DISABLED_FoobarTest.Test1',
6  'DISABLED_FoobarTest.DISABLED_Test2',
7  'DISABLED_FoobarbazTest.TestA',
8  ]

Definition at line 134 of file gtest_filter_unittest.py.

gtest_filter_unittest.environ = os.environ.copy()

Definition at line 169 of file gtest_filter_unittest.py.

string gtest_filter_unittest.FILTER_ENV_VAR = 'GTEST_FILTER'

Definition at line 89 of file gtest_filter_unittest.py.

string gtest_filter_unittest.FILTER_FLAG = 'gtest_filter'

Definition at line 97 of file gtest_filter_unittest.py.

string gtest_filter_unittest.LIST_TESTS_FLAG = '--gtest_list_tests'

Definition at line 116 of file gtest_filter_unittest.py.

gtest_filter_unittest.PARAM_TEST_REGEX = re.compile(r'/ParamTest')

Definition at line 106 of file gtest_filter_unittest.py.

list gtest_filter_unittest.PARAM_TESTS
Initial value:
1 = [
2  'SeqP/ParamTest.TestX/0',
3  'SeqP/ParamTest.TestX/1',
4  'SeqP/ParamTest.TestY/0',
5  'SeqP/ParamTest.TestY/1',
6  'SeqQ/ParamTest.TestX/0',
7  'SeqQ/ParamTest.TestX/1',
8  'SeqQ/ParamTest.TestY/0',
9  'SeqQ/ParamTest.TestY/1',
10  ]

Definition at line 123 of file gtest_filter_unittest.py.

gtest_filter_unittest.param_tests_present = None

Definition at line 165 of file gtest_filter_unittest.py.

string gtest_filter_unittest.SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX'

Definition at line 93 of file gtest_filter_unittest.py.

string gtest_filter_unittest.SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'

Definition at line 94 of file gtest_filter_unittest.py.

string gtest_filter_unittest.SUPPORTS_DEATH_TESTS = 'HasDeathTest'

Definition at line 119 of file gtest_filter_unittest.py.

gtest_filter_unittest.TEST_CASE_REGEX = re.compile(r'^\[\-+\] \d+ tests? from (\w+(/\w+)?)')

Definition at line 109 of file gtest_filter_unittest.py.

gtest_filter_unittest.TEST_REGEX = re.compile(r'^\[\s*RUN\s*\].*\.(\w+(/\w+)?)')

Definition at line 112 of file gtest_filter_unittest.py.

string gtest_filter_unittest.TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS'

Definition at line 92 of file gtest_filter_unittest.py.