예제 #1
0
    def test_all_filters_out_non_hyperparameters_and_does_not_append_suffix_if_flag_false(
            self, mock_get_all_jobs_data):
        from test.datetime_faker import fake_current_datetime, restore_real_current_datetime

        fake_current_datetime(1005000000)

        self.mock_get_all_artifacts.return_when(LazyResult(lambda: []),
                                                job_id='my job x')

        mock_get_all_jobs_data.return_value = [
            {
                'project_name': 'random test project',
                'job_id': 'my job x',
                'user': '******',
                'job_parameters': {
                    'hello': 'world'
                },
                'output_metrics': [],
                'status': 'completed',
                'start_time': 123456789,
                'completed_time': 2222222222,
                'tags': {
                    'beep': 'boop'
                },
                'artifacts': []
            },
        ]

        expected_job_1 = Job(job_id='my job x',
                             project='random test project',
                             user='******',
                             output_metrics=[],
                             job_parameters=[{
                                 'name': 'hello',
                                 'value': 'world',
                                 'type': 'string'
                             }],
                             status='completed',
                             start_time='1973-11-29T21:33:09',
                             completed_time='2040-06-02T03:57:02',
                             duration='24291d6h23m53s',
                             tags={'beep': 'boop'},
                             artifacts=[])

        result = Job.all(project_name='random test project').evaluate()

        restore_real_current_datetime()

        expected_jobs = [expected_job_1]
        self.assertEqual(expected_jobs, result)
    def test_all_returns_multiple_jobs_with_artifacts(self, mock_get_all_jobs_data):
        from test.datetime_faker import fake_current_datetime, restore_real_current_datetime

        fake_current_datetime(1005000000)

        self.mock_get_all_artifacts.return_when(LazyResult(lambda: [
            JobArtifact(filename='output_x.png',uri='output_x.png', artifact_type='png')
        ]), job_id='my job x')

        self.mock_get_all_artifacts.return_when(LazyResult(lambda: [
            JobArtifact(filename='output_v007.wav', uri='output_v007.wav', artifact_type='wav'),
            JobArtifact(filename='output_v007.txt', uri='output_v007.txt', artifact_type='unknown'),
        ]), job_id='00000000-0000-0000-0000-000000000007')

        mock_get_all_jobs_data.return_value = [
            {
                'project_name': 'random test project',
                'job_id': 'my job x',
                'user': '******',
                'job_parameters': {},
                'output_metrics': [],
                'status': 'completed',
                'start_time':  123456789,
                'completed_time': 2222222222,
                'tags': {},
                'artifacts': [{'filename': 'output_x.png', 'uri': 'output_x.png', 'artifact_type': 'png'}]
            },
            {
                'project_name': 'random test project',
                'job_id': '00000000-0000-0000-0000-000000000007',
                'user': '******',
                'job_parameters': {},
                'output_metrics': [],
                'status': 'running',
                'start_time': 999999999,
                'completed_time': None,
                'tags': {
                    'asdf': 'this',
                    'cool': 'dude'
                },
                'artifacts': [
                    {'filename': 'output_v007.wav', 'uri': 'output_v007.wav', 'artifact_type': 'wav'},
                    {'filename': 'output_v007.txt', 'uri': 'output_v007.txt', 'artifact_type': 'unknown'},
                ]
            }
        ]

        expected_job_1 = Job(
            job_id='00000000-0000-0000-0000-000000000007',
            project='random test project',
            user='******',
            output_metrics=[],
            job_parameters=[],
            status='running',
            start_time='2001-09-09T01:46:39',
            completed_time=None,
            duration='58d1h53m21s',
            tags={
                'asdf': 'this',
                'cool': 'dude'
            },
            artifacts=[
                JobArtifact(filename='output_v007.wav', uri='output_v007.wav', artifact_type='wav'),
                JobArtifact(filename='output_v007.txt', uri='output_v007.txt', artifact_type='unknown')
            ]
        )

        expected_job_2 = Job(
            job_id='my job x',
            project='random test project',
            user='******',
            output_metrics=[],
            job_parameters=[],
            status='completed',
            start_time='1973-11-29T21:33:09',
            completed_time='2040-06-02T03:57:02',
            duration='24291d6h23m53s',
            tags={},
            artifacts=[JobArtifact(filename='output_x.png',uri='output_x.png', artifact_type='png')]
        )

        result = Job.all(project_name='random test project').evaluate()

        restore_real_current_datetime()

        expected_jobs = [expected_job_1, expected_job_2]
        self.assertEqual(expected_jobs, result)