def test_get_load_log_paths( patch_search_command, namespace_args, bayes_log_folder, fixture_cleanup_bayes_log_folder ): """Tests that log files are loaded from the Bayesian search log folder. Ensures: - Loaded log file paths are correct - Non-json files are not loaded from the log folder """ bayes_log_folder.mkdir() log_paths = [ bayes_log_folder / 'file1.json', bayes_log_folder / 'file2.json', bayes_log_folder / 'file3.json', bayes_log_folder / 'file4', ] for filename in log_paths: log_file = bayes_log_folder / filename with log_file.open('w') as f: f.write('Test log file') search = PerformBayesianSearch(namespace_args) search.trainer_config_path = Path(__file__) retrieved_log_paths = search.get_load_log_paths() assert len(retrieved_log_paths) == 3 for path in retrieved_log_paths: assert path.suffix == '.json' assert path in log_paths
def test_get_save_log_path(monkeypatch, patch_search_command, namespace_args, bayes_log_folder): """Tests for the correct Bayesian search log file path creation.""" def mock_get_timestamp(): return '2019-09-13_03-41-44' def mock_get_log_folder_path(self): return bayes_log_folder monkeypatch.setattr(grimagents.common, 'get_timestamp', mock_get_timestamp) monkeypatch.setattr(PerformBayesianSearch, 'get_log_folder_path', mock_get_log_folder_path) log_path = Path(__file__).parent / '3DBall_bayes/3DBall_2019-09-13_03-41-44.json' search = PerformBayesianSearch(namespace_args) search.trainer_config_path = Path(__file__) assert search.get_save_log_path() == log_path
def test_get_log_folder_path( monkeypatch, patch_search_command, namespace_args, bayes_log_folder, fixture_cleanup_bayes_log_folder, ): """Test for the correct generation of a Bayesian search log folder path and ensure the folder is created if it doesn't exist. Ensures: - The correct log folder path is returned - The log folder is created if it did not previously exist """ search = PerformBayesianSearch(namespace_args) search.trainer_config_path = Path(__file__) assert search.get_log_folder_path() == bayes_log_folder assert bayes_log_folder.exists()