当前位置: 首页>>代码示例>>Python>>正文


Python absltest.main方法代码示例

本文整理汇总了Python中absl.testing.absltest.main方法的典型用法代码示例。如果您正苦于以下问题:Python absltest.main方法的具体用法?Python absltest.main怎么用?Python absltest.main使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在absl.testing.absltest的用法示例。


在下文中一共展示了absltest.main方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_helpfull_message

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def test_helpfull_message(self):
    flags.DEFINE_string(
        'non_main_module_flag', 'default', 'help',
        module_name='other.module', flag_values=self._absl_flags)
    parser = argparse_flags.ArgumentParser(
        inherited_absl_flags=self._absl_flags)
    with self.assertRaises(SystemExit),\
        mock.patch.object(sys, 'stdout', new=six.StringIO()) as mock_stdout:
      parser.parse_args(['--helpfull'])
    stdout_message = mock_stdout.getvalue()
    logging.info('captured stdout message:\n%s', stdout_message)
    self.assertIn('--non_main_module_flag', stdout_message)
    self.assertIn('other.module', stdout_message)
    # Make sure the main module is not included.
    self.assertNotIn(sys.argv[0], stdout_message)
    # Special flags defined in absl.flags.
    self.assertIn('absl.flags:', stdout_message)
    self.assertIn('--flagfile', stdout_message)
    self.assertIn('--undefok', stdout_message) 
开发者ID:abseil,项目名称:abseil-py,代码行数:21,代码来源:argparse_flags_test.py

示例2: main

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def main(*args, **kwargs):
    """Pass args and kwargs through to absltest main."""
    return absltest.main(*args, **kwargs) 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:5,代码来源:test.py

示例3: testMainError

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def testMainError(self, ab):
    ab.return_value.RunBuild.side_effect = KeyboardInterrupt
    self.assertRaises(LogFatalError, autobuild.main, 'something') 
开发者ID:google,项目名称:glazier,代码行数:5,代码来源:autobuild_test.py

示例4: testMainException

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def testMainException(self, ab):
    ab.return_value.RunBuild.side_effect = Exception
    with self.assertRaises(LogFatalError):
      autobuild.main('something') 
开发者ID:google,项目名称:glazier,代码行数:6,代码来源:autobuild_test.py

示例5: testMainWebApp

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def testMainWebApp(self, mocked_appengine_server_config):
    deploy_impl.main(argv=['first-arg', 'web'])
    mocked_appengine_server_config.assert_called_once_with(
        app_servers=deploy_impl.FLAGS.app_servers,
        build_target=deploy_impl.FLAGS.build_target,
        deployment_type='local',
        loaner_path=deploy_impl.FLAGS.loaner_path,
        web_app_dir=deploy_impl.FLAGS.web_app_dir,
        yaml_files=deploy_impl.FLAGS.yaml_files,
        version=deploy_impl.FLAGS.version) 
开发者ID:google,项目名称:loaner,代码行数:12,代码来源:deploy_impl_test.py

示例6: testMainChromeApp

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def testMainChromeApp(self, mocked_chrome_app_config):
    deploy_impl.main(argv=['first-arg', 'chrome'])
    mocked_chrome_app_config.assert_called_once_with(
        chrome_app_dir=deploy_impl.FLAGS.chrome_app_dir,
        deployment_type='local',
        loaner_path=deploy_impl.FLAGS.loaner_path) 
开发者ID:google,项目名称:loaner,代码行数:8,代码来源:deploy_impl_test.py

示例7: testMainWithoutParam

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def testMainWithoutParam(self, mocked_app_usage):
    with self.assertRaises(IndexError):
      deploy_impl.main(argv=[])
    mocked_app_usage.assert_called_once_with(shorthelp=True, exitcode=1) 
开发者ID:google,项目名称:loaner,代码行数:6,代码来源:deploy_impl_test.py

示例8: testMainWithInvalidAppType

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def testMainWithInvalidAppType(self, mocked_app_usage):
    deploy_impl.main(argv=['first-arg', 'fake-app'])
    mocked_app_usage.assert_called_once_with(shorthelp=True, exitcode=1) 
开发者ID:google,项目名称:loaner,代码行数:5,代码来源:deploy_impl_test.py

示例9: test_main

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def test_main(self, mock_prompt_enum):
    with flagsaver.flagsaver(
        project=common.DEFAULT, config_file_path=self._valid_config_path,
        prefer_gcs=False, app_version='valid-version'):
      with self.assertRaises(SystemExit) as exit_err:
        gng_impl.main('unused')
        self.assertEqual(exit_err.exception.code, 0)
    self.assertEqual(mock_prompt_enum.call_count, 1) 
开发者ID:google,项目名称:loaner,代码行数:10,代码来源:gng_impl_test.py

示例10: main

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def main():
  absltest.main() 
开发者ID:google,项目名称:loaner,代码行数:4,代码来源:loanertest.py

示例11: assert_conversion_fails

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def assert_conversion_fails(f):
    @wraps(f)
    def wrapper(tmppy: TmppyFixture = TmppyFixture(ObjectFileContent({}))):
        def run_test(allow_toplevel_static_asserts_after_optimization: bool):
            tmppy_source = _get_function_body(f)
            e = None
            object_file_content = None
            try:
                object_file_content = compile(tmppy_source, tmppy.tmppyc_files)
            except CompilationError as e1:
                e = e1

            if not e:
                main_module = object_file_content.modules_by_name[TEST_MODULE_NAME]
                raise TestFailedException(textwrap.dedent('''\
                        Expected an exception, but the _py2tmp conversion completed successfully.
                        TMPPy source:
                        {tmppy_source}
    
                        TMPPy IR1:
                        {tmppy_ir1}
                        ''').format(tmppy_source=add_line_numbers(tmppy_source),
                                    tmppy_ir1=str(main_module.ir1_module)))

            check_compilation_error(e, tmppy_source)

            return '(no C++ source)'

        run_test_with_optional_optimization(run_test)

    return wrapper


# Note: this is not the main function of this file, it's meant to be used as main function from test_*.py files. 
开发者ID:google,项目名称:tmppy,代码行数:36,代码来源:_utils.py

示例12: main

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def main():
    absltest.main(*sys.argv) 
开发者ID:google,项目名称:tmppy,代码行数:4,代码来源:_utils.py

示例13: rng

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def rng():  # Can't be a constant, because JAX has to init itself in main first.
  return fastmath.random.get_prng(0) 
开发者ID:google,项目名称:trax,代码行数:4,代码来源:initializers_test.py

示例14: test_from_file

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def test_from_file(self):
    params = np.array([[0.0, 0.1], [0.2, 0.3], [0.4, 0.5]])
    # `create_tempfile` needs access to --test_tmpdir, however in the OSS world
    # pytest doesn't run `absltest.main`, so we need to manually parse the flags
    test_utils.ensure_flag('test_tmpdir')
    filename = self.create_tempfile('params.npy').full_path
    with open(filename, 'wb') as f:
      np.save(f, params)
    f = tl.InitializerFromFile(filename)
    init_value = f(params.shape, rng())
    self.assertEqual(tl.to_list(init_value), tl.to_list(params))
    # self.assertEqual('%s' % init_value, '%s' % params) 
开发者ID:google,项目名称:trax,代码行数:14,代码来源:initializers_test.py

示例15: _Test

# 需要导入模块: from absl.testing import absltest [as 别名]
# 或者: from absl.testing.absltest import main [as 别名]
def _Test(self, name, expected_return_code=0):
    """Verifies that the input file is converted as expected."""

    # Copy the contents of the input file to a temporary file.
    with open(os.path.join(self.TESTDATA, '{0}-input.py'.format(name))) as f:
      input_contents = f.read()

    self.temp_file.write(input_contents)
    self.temp_file.close()

    # Convert the temporary file in-place.
    return_code = convert.main(['convert', self.temp_file.name])

    # Check the return code.
    AssertThat(return_code).IsEqualTo(expected_return_code)

    # Check the contents line by line.
    # This is not strictly necessary given the SHA-512 verification, but it
    # makes debugging test failures easier.
    expected_path = os.path.join(self.TESTDATA, '{0}-expected.py'.format(name))
    line = 0
    with open(self.temp_file.name) as converted_file:
      with open(expected_path) as expected_file:
        for converted_line in converted_file:
          line += 1
          name = 'at line {0}'.format(line)
          expected_line = expected_file.readline()
          AssertThat(converted_line).Named(name).IsEqualTo(expected_line)

    # Verify the contents are exactly identical.
    actual_hash = self._Checksum(self.temp_file.name)
    expected_hash = self._Checksum(expected_path)
    AssertThat(actual_hash).IsEqualTo(expected_hash) 
开发者ID:google,项目名称:pytruth,代码行数:35,代码来源:convert_test.py


注:本文中的absl.testing.absltest.main方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。