當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。