Python absl.testing.absltest.main() Examples
The following are 30
code examples of absl.testing.absltest.main().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
absl.testing.absltest
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: argparse_flags_test.py From abseil-py with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: run_training_test.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def test_run_training(self, targets): """Tests whether the training loop can be run successfully. Generates test input files and runs the main driving code. Args: targets: the targets to train on. """ # Create test input and metadata files. num_examples, read_len = 20, 5 train_file = test_utils.create_tmp_train_file(num_examples, read_len) metadata_path = test_utils.create_tmp_metadata(num_examples, read_len) # Check that the training loop runs as expected. logdir = os.path.join(FLAGS.test_tmpdir, 'train:{}'.format(len(targets))) with flagsaver.flagsaver( train_files=train_file, metadata_path=metadata_path, targets=targets, logdir=logdir, hparams='train_steps=10,min_read_length=5', batch_size=10): run_training.main(FLAGS) # Check training loop ran by confirming existence of a checkpoint file. self.assertIsNotNone(tf.train.latest_checkpoint(FLAGS.logdir)) # Check training loop ran by confiming existence of a measures file. self.assertTrue( os.path.exists(os.path.join(FLAGS.logdir, 'measures.pbtxt')))
Example #3
Source File: argparse_flags_test.py From abseil-py with Apache License 2.0 | 5 votes |
def test_help_non_main_module_flags(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) help_message = parser.format_help() # Non main module key flags are not printed in the help message. self.assertNotIn('non_main_module_flag', help_message)
Example #4
Source File: sim_scene_test.py From robel with Apache License 2.0 | 5 votes |
def test_accessors(self, robot: SimScene): self.assertTrue(robot.model.body_name2id('main') >= 0) self.assertTrue(robot.model.geom_name2id('base') >= 0) self.assertTrue(robot.model.site_name2id('end') >= 0) self.assertTrue(robot.model.joint_name2id('j1') >= 0) self.assertIsNotNone(robot.data.body_xpos[0]) self.assertIsNotNone(robot.data.body_xquat[0])
Example #5
Source File: resources_test.py From robel with Apache License 2.0 | 5 votes |
def test_add_mujoco(self): """Tests adding a MuJoCo file.""" resources = DummyResources({ 'a/b/main.xml': '<mujoco><include file="../child1.xml"/></mujoco>', 'a/child1.xml': """ <mujoco> <compiler meshdir="c"/> <asset> <mesh name="a1" file="hello.stl"/> <mesh name="a2" file="world.stl"/> </asset> </mujoco> """, 'a/c/hello.stl': 'Hello!', 'a/c/world.stl': 'World!', }) bundle = AssetBundle( dest_path='test', dry_run=True, resource_fn=resources.get_resource) transformed_path = bundle.add_mujoco('a/b/main.xml') self.assertEqual(transformed_path, 'test/a/b/main.xml') self.assertDictEqual( bundle.copied_paths, { 'a/b/main.xml': 'test/a/b/main.xml', 'a/child1.xml': 'test/a/child1.xml', 'a/c/hello.stl': 'test/a/c/hello.stl', 'a/c/world.stl': 'test/a/c/world.stl', })
Example #6
Source File: basetest.py From upvote with Apache License 2.0 | 5 votes |
def main(): """Simple wrapper to call absltest.main().""" return absltest.main()
Example #7
Source File: element_test.py From dm_control with Apache License 2.0 | 5 votes |
def testAttributes(self): mujoco = element.RootElement(model='test') mujoco.default.dclass = 'main' self._test_attributes(mujoco, recursive=True)
Example #8
Source File: element_test.py From dm_control with Apache License 2.0 | 5 votes |
def testGetAssetsFromDict(self): with open(_MODEL_WITH_INVALID_FILENAMES, 'rb') as f: xml_string = f.read() with open(_TEXTURE_PATH, 'rb') as f: texture_contents = f.read() with open(_MESH_PATH, 'rb') as f: mesh_contents = f.read() with open(_INCLUDED_WITH_INVALID_FILENAMES, 'rb') as f: included_xml_contents = f.read() assets = { 'invalid_texture_name.png': texture_contents, 'invalid_mesh_name.stl': mesh_contents, 'invalid_included_name.xml': included_xml_contents, } # The paths specified in the main and included XML files are deliberately # invalid, so the parser should fail unless the pre-loaded assets are passed # in as a dict. with self.assertRaises(IOError): parser.from_xml_string(xml_string=xml_string) mujoco = parser.from_xml_string(xml_string=xml_string, assets=assets) expected_assets = {} for path, contents in six.iteritems(assets): _, filename = os.path.split(path) prefix, extension = os.path.splitext(filename) if extension != '.xml': vfs_filename = ''.join( [prefix, '-', hashlib.sha1(contents).hexdigest(), extension]) expected_assets[vfs_filename] = contents self.assertDictEqual(expected_assets, mujoco.get_assets())
Example #9
Source File: attribute_test.py From dm_control with Apache License 2.0 | 5 votes |
def testDefaults(self): mujoco = self._mujoco # Unnamed global defaults class should become a properly named and scoped # class with a trailing slash self.assertIsNone(mujoco.default.dclass) self.assertCorrectXMLStringForDefaultsClass(mujoco.default, 'class', '') # An element without an explicit dclass should be assigned to the properly # scoped global defaults class entity = mujoco.worldentity.add('entity') subentity = entity.add('subentity') self.assertIsNone(subentity.dclass) self.assertCorrectXMLStringForDefaultsClass(subentity, 'class', '') # Named global defaults class should gain scoping prefix mujoco.default.dclass = 'main' self.assertEqual(mujoco.default.dclass, 'main') self.assertCorrectXMLStringForDefaultsClass(mujoco.default, 'class', 'main') self.assertCorrectXMLStringForDefaultsClass(subentity, 'class', 'main') # Named subordinate defaults class should gain scoping prefix sub_default = mujoco.default.add('default', dclass='sub') self.assertEqual(sub_default.dclass, 'sub') self.assertCorrectXMLStringForDefaultsClass(sub_default, 'class', 'sub') # An element without an explicit dclass but belongs to a childclassed # parent should be left alone entity.childclass = 'sub' self.assertEqual(entity.childclass, 'sub') self.assertCorrectXMLStringForDefaultsClass(entity, 'childclass', 'sub') self.assertXMLStringIsNone(subentity, 'class') # An element WITH an explicit dclass should be left alone have it properly # scoped regardless of whether it belongs to a childclassed parent or not. subentity.dclass = 'main' self.assertCorrectXMLStringForDefaultsClass(subentity, 'class', 'main')
Example #10
Source File: autobuild_test.py From glazier with Apache License 2.0 | 5 votes |
def testMainException(self, ab): ab.return_value.RunBuild.side_effect = Exception with self.assertRaises(LogFatalError): autobuild.main('something')
Example #11
Source File: infogan_eval_test.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def test_build_graph(self): infogan_eval.main(None, run_eval_loop=False)
Example #12
Source File: eval_test.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def test_build_graph(self, eval_real_images): flags.FLAGS.eval_real_images = eval_real_images eval.main(None, run_eval_loop=False)
Example #13
Source File: conditional_eval_test.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def test_build_graph(self): conditional_eval.main(None, run_eval_loop=False)
Example #14
Source File: run_training_test.py From models with Apache License 2.0 | 5 votes |
def test_run_training(self, targets): """Tests whether the training loop can be run successfully. Generates test input files and runs the main driving code. Args: targets: the targets to train on. """ # Create test input and metadata files. num_examples, read_len = 20, 5 train_file = test_utils.create_tmp_train_file(num_examples, read_len) metadata_path = test_utils.create_tmp_metadata(num_examples, read_len) # Check that the training loop runs as expected. logdir = os.path.join(FLAGS.test_tmpdir, 'train:{}'.format(len(targets))) with flagsaver.flagsaver( train_files=train_file, metadata_path=metadata_path, targets=targets, logdir=logdir, hparams='train_steps=10,min_read_length=5', batch_size=10): run_training.main(FLAGS) # Check training loop ran by confirming existence of a checkpoint file. self.assertIsNotNone(tf.train.latest_checkpoint(FLAGS.logdir)) # Check training loop ran by confiming existence of a measures file. self.assertTrue( os.path.exists(os.path.join(FLAGS.logdir, 'measures.pbtxt')))
Example #15
Source File: run_training_test.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def test_run_training(self, targets): """Tests whether the training loop can be run successfully. Generates test input files and runs the main driving code. Args: targets: the targets to train on. """ # Create test input and metadata files. num_examples, read_len = 20, 5 train_file = test_utils.create_tmp_train_file(num_examples, read_len) metadata_path = test_utils.create_tmp_metadata(num_examples, read_len) # Check that the training loop runs as expected. logdir = os.path.join(FLAGS.test_tmpdir, 'train:{}'.format(len(targets))) with flagsaver.flagsaver( train_files=train_file, metadata_path=metadata_path, targets=targets, logdir=logdir, hparams='train_steps=10,min_read_length=5', batch_size=10): run_training.main(FLAGS) # Check training loop ran by confirming existence of a checkpoint file. self.assertIsNotNone(tf.train.latest_checkpoint(FLAGS.logdir)) # Check training loop ran by confiming existence of a measures file. self.assertTrue( os.path.exists(os.path.join(FLAGS.logdir, 'measures.pbtxt')))
Example #16
Source File: infogan_eval_test.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def test_build_graph(self): infogan_eval.main(None, run_eval_loop=False)
Example #17
Source File: eval_test.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def test_build_graph(self, eval_real_images): flags.FLAGS.eval_real_images = eval_real_images eval.main(None, run_eval_loop=False)
Example #18
Source File: conditional_eval_test.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def test_build_graph(self): conditional_eval.main(None, run_eval_loop=False)
Example #19
Source File: _utils.py From tmppy with Apache License 2.0 | 5 votes |
def main(): absltest.main(*sys.argv)
Example #20
Source File: autobuild_test.py From glazier with Apache License 2.0 | 5 votes |
def testMainError(self, ab): ab.return_value.RunBuild.side_effect = KeyboardInterrupt self.assertRaises(LogFatalError, autobuild.main, 'something')
Example #21
Source File: deploy_impl_test.py From loaner with Apache License 2.0 | 5 votes |
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)
Example #22
Source File: deploy_impl_test.py From loaner with Apache License 2.0 | 5 votes |
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)
Example #23
Source File: deploy_impl_test.py From loaner with Apache License 2.0 | 5 votes |
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)
Example #24
Source File: deploy_impl_test.py From loaner with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: gng_impl_test.py From loaner with Apache License 2.0 | 5 votes |
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)
Example #26
Source File: loanertest.py From loaner with Apache License 2.0 | 5 votes |
def main(): absltest.main()
Example #27
Source File: _utils.py From tmppy with Apache License 2.0 | 5 votes |
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.
Example #28
Source File: initializers_test.py From trax with Apache License 2.0 | 5 votes |
def rng(): # Can't be a constant, because JAX has to init itself in main first. return fastmath.random.get_prng(0)
Example #29
Source File: initializers_test.py From trax with Apache License 2.0 | 5 votes |
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)
Example #30
Source File: test.py From tensorboard with Apache License 2.0 | 5 votes |
def main(*args, **kwargs): """Pass args and kwargs through to absltest main.""" return absltest.main(*args, **kwargs)