def test_can_download_from_one_job_and_upload_same_data_to_another(self): import os import json self.run_job() with open( 'acceptance/fixtures/syncable_directory_job_again/foundations_job_parameters.json', 'w') as params_file: json.dump({'source_job_id': self.job_id_1}, params_file) self.run_job_2() syncable_directory_data = foundations.create_syncable_directory( 'some data', self.first_directory_path, source_job_id=self.job_id_2) syncable_directory_data.download() self.assertEqual(['some_data.txt'], os.listdir(self.first_directory_path)) syncable_directory_meta = foundations.create_syncable_directory( 'some metadata', self.second_directory_path, source_job_id=self.job_id_2) syncable_directory_meta.download() self.assertEqual(['some_metadata.txt'], os.listdir(self.second_directory_path))
def test_syncable_directory_does_a_download_upon_instantiation(self): from foundations import create_syncable_directory mock_download = self.patch( 'foundations.artifacts.syncable_directory.SyncableDirectory.download' ) syncable_directory = create_syncable_directory(self.key, None, self.remote_job_id) mock_download.assert_called_once()
def test_foundations_create_syncable_directory_defaults_to_current_job_for_remote_and_local( self): from foundations import create_syncable_directory self.patch( 'foundations_internal.pipeline_context.PipelineContext.file_name', self.local_job_id) instance = self._mock_syncable_directory(self.local_job_id) self.assertEqual( instance, create_syncable_directory(self.key, self.directory_path))
def test_downloads_upon_instantiation(self): import os self._deploy_job_file('acceptance/fixtures/syncable_directory_job', job_id=self.job_id_1, entrypoint='main.py') syncable_directory = foundations.create_syncable_directory( 'some data', None, self.job_id_1) self.assertEqual(['some_data.txt'], os.listdir(str(syncable_directory)))
def test_foundations_create_syncable_directory_without_any_job_ids(self): from foundations import create_syncable_directory klass_mock = self.patch( 'foundations.artifacts.syncable_directory.SyncableDirectory', ConditionalReturn()) instance = Mock() klass_mock.return_when(instance, self.key, self.directory_path, None, None) self.assertEqual( instance, create_syncable_directory(self.key, self.directory_path))
def test_foundations_create_syncable_directory_uses_source_job_for_remote( self): from foundations import create_syncable_directory self.patch( 'foundations_internal.pipeline_context.PipelineContext.file_name', self.local_job_id) instance = self._mock_syncable_directory(self.remote_job_id) self.assertEqual( instance, create_syncable_directory(self.key, self.directory_path, self.remote_job_id))
def test_foundations_create_syncable_directory_with_no_directory_creates_temp_directory( self): from foundations import create_syncable_directory create_syncable_directory(self.key, None, self.remote_job_id) self.mock_mkdtemp.assert_called_once()
def second_directory(self, job_id): return foundations.create_syncable_directory( 'some metadata', self.second_directory_path, job_id)
def first_directory(self, job_id): return foundations.create_syncable_directory('some data', self.first_directory_path, job_id)
def temporary_syncable_directory(self, job_id): return foundations.create_syncable_directory('some data', None, job_id)
def _create_tensorboard_logdir(path): from foundations import create_syncable_directory tensorboard_logdir = create_syncable_directory('__tensorboard__', path) return lambda: tensorboard_logdir.upload()
import foundations first_directory = foundations.create_syncable_directory('some data', 'results') first_directory.upload() second_directory = foundations.create_syncable_directory( 'some metadata', 'metadata') second_directory.upload()
import foundations parameters = foundations.load_parameters(log_parameters=False) job_id = parameters['source_job_id'] first_directory = foundations.create_syncable_directory('some data', 'results', source_job_id=job_id) first_directory.upload() second_directory = foundations.create_syncable_directory('some metadata', 'metadata', source_job_id=job_id) second_directory.upload()
import foundations first_directory = foundations.create_syncable_directory('some data', 'results') first_directory.upload()