Python absl.testing.absltest.get_default_test_tmpdir() Examples
The following are 14
code examples of absl.testing.absltest.get_default_test_tmpdir().
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
.
Example #1
Source File: continuous_collect_eval_test.py From tensor2robot with Apache License 2.0 | 6 votes |
def test_run_pose_env_collect(self, demo_policy_cls): urdf_root = pose_env.get_pybullet_urdf_root() config_dir = 'research/pose_env/configs' gin_config = os.path.join( FLAGS.test_srcdir, config_dir, 'run_random_collect.gin') gin.parse_config_file(gin_config) tmp_dir = absltest.get_default_test_tmpdir() root_dir = os.path.join(tmp_dir, str(demo_policy_cls)) gin.bind_parameter('PoseToyEnv.urdf_root', urdf_root) gin.bind_parameter( 'collect_eval_loop.root_dir', root_dir) gin.bind_parameter('run_meta_env.num_tasks', 2) gin.bind_parameter('run_meta_env.num_episodes_per_adaptation', 1) gin.bind_parameter( 'collect_eval_loop.policy_class', demo_policy_cls) continuous_collect_eval.collect_eval_loop() output_files = tf.io.gfile.glob(os.path.join( root_dir, 'policy_collect', '*.tfrecord')) self.assertLen(output_files, 2)
Example #2
Source File: make_train_test_split_test.py From deep-molecular-massspec with Apache License 2.0 | 6 votes |
def setUp(self): super(MakeTrainTestSplitTest, self).setUp() test_data_directory = test_utils.test_dir('testdata/') self.temp_dir = tempfile.mkdtemp(dir=absltest.get_default_test_tmpdir()) test_sdf_file_large = os.path.join(test_data_directory, 'test_14_mend.sdf') test_sdf_file_small = os.path.join(test_data_directory, 'test_2_mend.sdf') max_atoms = ms_constants.MAX_ATOMS self.mol_list_large = parse_sdf_utils.get_sdf_to_mol( test_sdf_file_large, max_atoms=max_atoms) self.mol_list_small = parse_sdf_utils.get_sdf_to_mol( test_sdf_file_small, max_atoms=max_atoms) self.inchikey_dict_large = train_test_split_utils.make_inchikey_dict( self.mol_list_large) self.inchikey_dict_small = train_test_split_utils.make_inchikey_dict( self.mol_list_small) self.inchikey_list_large = list(self.inchikey_dict_large.keys()) self.inchikey_list_small = list(self.inchikey_dict_small.keys())
Example #3
Source File: utils_impl_test.py From federated with Apache License 2.0 | 5 votes |
def test_atomic_write(self): for name in ['foo.csv', 'baz.csv.bz2']: dataframe = pd.DataFrame(dict(a=[1, 2], b=[4.0, 5.0])) output_file = os.path.join(absltest.get_default_test_tmpdir(), name) utils_impl.atomic_write_to_csv(dataframe, output_file) dataframe2 = pd.read_csv(output_file, index_col=0) pd.testing.assert_frame_equal(dataframe, dataframe2) # Overwriting dataframe3 = pd.DataFrame(dict(a=[1, 2, 3], b=[4.0, 5.0, 6.0])) utils_impl.atomic_write_to_csv(dataframe3, output_file) dataframe4 = pd.read_csv(output_file, index_col=0) pd.testing.assert_frame_equal(dataframe3, dataframe4)
Example #4
Source File: utils_impl_test.py From federated with Apache License 2.0 | 5 votes |
def test_atomic_read(self): for name in ['foo.csv', 'baz.csv.bz2']: dataframe = pd.DataFrame(dict(a=[1, 2], b=[4.0, 5.0])) csv_file = os.path.join(absltest.get_default_test_tmpdir(), name) utils_impl.atomic_write_to_csv(dataframe, csv_file) dataframe2 = utils_impl.atomic_read_from_csv(csv_file) pd.testing.assert_frame_equal(dataframe, dataframe2)
Example #5
Source File: spectra_predictor_test.py From deep-molecular-massspec with Apache License 2.0 | 5 votes |
def setUp(self): super(SpectraPredictorTest, self).setUp() self.np_fingerprint_input = np.ones((2, 4096)) self.np_mol_weight_input = np.reshape(np.array([18., 16.]), (2, 1)) self.test_data_directory = test_utils.test_dir("testdata/") self.temp_dir = tempfile.mkdtemp(dir=absltest.get_default_test_tmpdir()) self.test_file_short = os.path.join(self.test_data_directory, "test_2_mend.sdf")
Example #6
Source File: util_test.py From deep-molecular-massspec with Apache License 2.0 | 5 votes |
def setUp(self): self.temp_dir = tempfile.mkdtemp(dir=absltest.get_default_test_tmpdir())
Example #7
Source File: model_eval_lib_test.py From model-analysis with Apache License 2.0 | 5 votes |
def testLoadValidationResult(self): result = validation_result_pb2.ValidationResult(validation_ok=True) path = os.path.join(absltest.get_default_test_tmpdir(), 'results.tfrecord') with tf.io.TFRecordWriter(path) as writer: writer.write(result.SerializeToString()) loaded_result = model_eval_lib.load_validation_result(path) self.assertTrue(loaded_result.validation_ok)
Example #8
Source File: model_eval_lib_test.py From model-analysis with Apache License 2.0 | 5 votes |
def testLoadValidationResultDir(self): result = validation_result_pb2.ValidationResult(validation_ok=True) path = os.path.join(absltest.get_default_test_tmpdir(), constants.VALIDATIONS_KEY) with tf.io.TFRecordWriter(path) as writer: writer.write(result.SerializeToString()) loaded_result = model_eval_lib.load_validation_result(os.path.dirname(path)) self.assertTrue(loaded_result.validation_ok)
Example #9
Source File: model_eval_lib_test.py From model-analysis with Apache License 2.0 | 5 votes |
def testLoadValidationResultEmptyFile(self): path = os.path.join(absltest.get_default_test_tmpdir(), constants.VALIDATIONS_KEY) with tf.io.TFRecordWriter(path): pass with self.assertRaises(AssertionError): model_eval_lib.load_validation_result(path)
Example #10
Source File: export_with_assets_as_zip_test.py From dm_control with Apache License 2.0 | 5 votes |
def setUpModule(): # Flags are not parsed when this test is invoked by `nosetests`, so we fall # back on using the default value for `--test_tmpdir`. if not FLAGS.is_parsed(): FLAGS.test_tmpdir = absltest.get_default_test_tmpdir() FLAGS.mark_as_parsed()
Example #11
Source File: export_with_assets_test.py From dm_control with Apache License 2.0 | 5 votes |
def setUpModule(): # Flags are not parsed when this test is invoked by `nosetests`, so we fall # back on using the default value for ``--test_tmpdir`. if not FLAGS.is_parsed(): FLAGS.test_tmpdir = absltest.get_default_test_tmpdir() FLAGS.mark_as_parsed()
Example #12
Source File: debugging_test.py From dm_control with Apache License 2.0 | 5 votes |
def setup_debug_mode(self, debug_mode_enabled, full_dump_enabled=False): if debug_mode_enabled: debugging.enable_debug_mode() else: debugging.disable_debug_mode() if full_dump_enabled: base_dir = absltest.get_default_test_tmpdir() self.dump_dir = os.path.join(base_dir, 'mjcf_debugging_test') shutil.rmtree(self.dump_dir, ignore_errors=True) os.mkdir(self.dump_dir) else: self.dump_dir = '' debugging.set_full_dump_dir(self.dump_dir)
Example #13
Source File: image_utils_test.py From dm_control with Apache License 2.0 | 5 votes |
def test_save_images_on_failure(self): random_state = np.random.RandomState(SEED) image1 = random_state.randint(0, 255, size=(64, 64, 3), dtype=np.uint8) image2 = random_state.randint(0, 255, size=(64, 64, 3), dtype=np.uint8) diff = (0.5 * (image2.astype(np.int16) - image1 + 255)).astype(np.uint8) message = 'exception message' output_dir = absltest.get_default_test_tmpdir() @image_utils.save_images_on_failure(output_dir=output_dir) def func(): raise image_utils.ImagesNotCloseError(message, image1, image2) with six.assertRaisesRegex(self, image_utils.ImagesNotCloseError, '{}.*'.format(message)): func() def validate_saved_file(name, expected_contents): path = os.path.join(output_dir, '{}-{}.png'.format('func', name)) self.assertTrue(os.path.isfile(path)) image = Image.open(path) actual_contents = np.array(image) np.testing.assert_array_equal(expected_contents, actual_contents) validate_saved_file('expected', image1) validate_saved_file('actual', image2) validate_saved_file('difference', diff)
Example #14
Source File: molecule_estimator_test.py From deep-molecular-massspec with Apache License 2.0 | 4 votes |
def setUp(self): """Sets up a dataset json for regular, baseline, and all_predicted cases.""" super(MoleculeEstimatorTest, self).setUp() self.test_data_directory = test_utils.test_dir('testdata/') record_file = os.path.join(self.test_data_directory, 'test_14_record.gz') self.num_eval_examples = parse_sdf_utils.parse_info_file(record_file)[ 'num_examples'] self.temp_dir = tempfile.mkdtemp(dir=absltest.get_default_test_tmpdir()) self.default_dataset_config_file = os.path.join(self.temp_dir, 'dataset_config.json') self.baseline_dataset_config_file = os.path.join( self.temp_dir, 'baseline_dataset_config.json') self.all_predicted_dataset_config_file = os.path.join( self.temp_dir, 'all_predicted_dataset_config.json') dataset_names = [ ds_constants.SPECTRUM_PREDICTION_TRAIN_KEY, ds_constants.SPECTRUM_PREDICTION_TEST_KEY, ds_constants.LIBRARY_MATCHING_OBSERVED_KEY, ds_constants.LIBRARY_MATCHING_PREDICTED_KEY, ds_constants.LIBRARY_MATCHING_QUERY_KEY ] default_dataset_config = {key: [record_file] for key in dataset_names} default_dataset_config[ ds_constants.TRAINING_SPECTRA_ARRAY_KEY] = os.path.join( self.test_data_directory, 'test_14.spectra_library.npy') with tf.gfile.Open(self.default_dataset_config_file, 'w') as f: json.dump(default_dataset_config, f) # Test estimator behavior when predicted set is empty baseline_dataset_config = dict( [(key, [record_file]) if key != ds_constants.LIBRARY_MATCHING_PREDICTED_KEY else (key, []) for key in dataset_names]) baseline_dataset_config[ ds_constants.TRAINING_SPECTRA_ARRAY_KEY] = os.path.join( self.test_data_directory, 'test_14.spectra_library.npy') with tf.gfile.Open(self.baseline_dataset_config_file, 'w') as f: json.dump(baseline_dataset_config, f) # Test estimator behavior when observed set is empty all_predicted_dataset_config = dict( [(key, [record_file]) if key != ds_constants.LIBRARY_MATCHING_OBSERVED_KEY else (key, []) for key in dataset_names]) all_predicted_dataset_config[ ds_constants.TRAINING_SPECTRA_ARRAY_KEY] = os.path.join( self.test_data_directory, 'test_14.spectra_library.npy') with tf.gfile.Open(self.all_predicted_dataset_config_file, 'w') as f: json.dump(all_predicted_dataset_config, f)