Example #1
0
    def test_analysis_files(self):
        fw = self.fw

        # Upload to session
        poem = 'A gaze blank and pitiless as the sun,'
        fw.upload_file_to_session(self.session_id,
                                  flywheel.FileSpec('yeats.txt', poem))

        file_ref = flywheel.FileReference(id=self.session_id,
                                          type='session',
                                          name='yeats.txt')

        analysis = flywheel.AnalysisInput(label=self.rand_string(),
                                          description=self.rand_string(),
                                          inputs=[file_ref])

        # Add
        analysis_id = fw.add_session_analysis(self.session_id, analysis)

        # Download the input file and check content
        self.assertDownloadFileTextEquals(
            fw.download_input_from_analysis_as_data, analysis_id, 'yeats.txt',
            poem)
        self.assertDownloadFileTextEqualsWithTicket(
            fw.get_analysis_input_download_url, analysis_id, 'yeats.txt', poem)

        poem_out = 'Surely the Second Coming is at hand.'
        r_analysis = fw.get(analysis_id)
        r_analysis.upload_output(flywheel.FileSpec('yeats-out.txt', poem_out))

        r_analysis = r_analysis.reload()
        self.assertEqual(len(r_analysis.files), 1)
        self.assertEqual(r_analysis.files[0].name, 'yeats-out.txt')
        self.assertEqual(r_analysis.files[0].size, 36)
        self.assertEqual(r_analysis.files[0].mimetype, 'text/plain')

        # Download and check content
        self.assertDownloadFileTextEquals(
            fw.download_output_from_analysis_as_data, analysis_id,
            'yeats-out.txt', poem_out)
        self.assertDownloadFileTextEqualsWithTicket(
            fw.get_analysis_output_download_url, analysis_id, 'yeats-out.txt',
            poem_out)
Example #2
0
    def test_container_analysis(self):
        fw = self.fw

        acquisition = flywheel.Acquisition(session=self.session_id,
                                           label=self.rand_string())

        # Add
        acquisition_id = fw.add_acquisition(acquisition)
        self.assertNotEmpty(acquisition_id)

        poem = 'Troubles my sight: a waste of desert sand;'
        fw.upload_file_to_container(acquisition_id,
                                    flywheel.FileSpec('yeats.txt', poem))

        file_ref = flywheel.FileReference(id=acquisition_id,
                                          type='acquisition',
                                          name='yeats.txt')

        analysis = flywheel.AnalysisInput(label=self.rand_string(),
                                          description=self.rand_string(),
                                          inputs=[file_ref])

        # Add
        analysis_id = fw.add_container_analysis(acquisition_id, analysis)
        self.assertNotEmpty(analysis_id)

        # Get the list of analyses in the acquisition
        analyses = fw.get_container_analyses(acquisition_id)
        self.assertEqual(len(analyses), 1)

        r_analysis = analyses[0]

        self.assertEqual(r_analysis.id, analysis_id)
        self.assertEmpty(r_analysis.job)

        self.assertTimestampBeforeNow(r_analysis.created)
        self.assertGreaterEqual(r_analysis.modified, r_analysis.created)

        self.assertEqual(len(r_analysis.inputs), 1)
        self.assertEqual(r_analysis.inputs[0].name, 'yeats.txt')
Example #3
0
    def test_project_analysis(self):
        fw = self.fw

        project = flywheel.Project(group=self.group_id,
                                   label=self.rand_string())

        # Add
        self.project_id = project_id = fw.add_project(project)
        self.assertNotEmpty(project_id)

        poem = 'The Second Coming! Hardly are those words out'
        fw.upload_file_to_project(project_id,
                                  flywheel.FileSpec('yeats.txt', poem))

        file_ref = flywheel.FileReference(id=project_id,
                                          type='project',
                                          name='yeats.txt')

        analysis = flywheel.AnalysisInput(label=self.rand_string(),
                                          description=self.rand_string(),
                                          inputs=[file_ref])

        # Add
        analysis_id = fw.add_project_analysis(project_id, analysis)
        self.assertNotEmpty(analysis_id)

        # Get the list of analyses in the project
        analyses = fw.get_project_analyses(project_id)
        self.assertEqual(len(analyses), 1)

        r_analysis = analyses[0]

        self.assertEqual(r_analysis.id, analysis_id)
        self.assertEmpty(r_analysis.job)

        self.assertTimestampBeforeNow(r_analysis.created)
        self.assertGreaterEqual(r_analysis.modified, r_analysis.created)

        self.assertEqual(len(r_analysis.inputs), 1)
        self.assertEqual(r_analysis.inputs[0].name, 'yeats.txt')
Example #4
0
    def test_session_analysis(self):
        fw = self.fw

        session = flywheel.Session(project=self.project_id,
                                   label=self.rand_string())

        # Add
        session_id = fw.add_session(session)
        self.assertNotEmpty(session_id)

        poem = 'When a vast image out of Spiritus Mundi'
        fw.upload_file_to_session(session_id,
                                  flywheel.FileSpec('yeats.txt', poem))

        file_ref = flywheel.FileReference(id=session_id,
                                          type='session',
                                          name='yeats.txt')

        analysis = flywheel.AnalysisInput(label=self.rand_string(),
                                          description=self.rand_string(),
                                          inputs=[file_ref])

        # Add
        analysis_id = fw.add_session_analysis(session_id, analysis)
        self.assertNotEmpty(analysis_id)

        # Get the list of analyses in the session
        analyses = fw.get_session_analyses(session_id)
        self.assertEqual(len(analyses), 1)

        r_analysis = analyses[0]

        self.assertEqual(r_analysis.id, analysis_id)
        self.assertEmpty(r_analysis.job)

        self.assertTimestampBeforeNow(r_analysis.created)
        self.assertGreaterEqual(r_analysis.modified, r_analysis.created)

        self.assertEqual(len(r_analysis.inputs), 1)
        self.assertEqual(r_analysis.inputs[0].name, 'yeats.txt')
Example #5
0
    def test_collection_analysis(self):
        fw = self.fw

        collection = flywheel.Collection(label=self.rand_string())

        # Add
        self.collection_id = collection_id = fw.add_collection(collection)
        self.assertNotEmpty(collection_id)

        poem = 'A shape with lion body and the head of a man,'
        fw.upload_file_to_collection(collection_id,
                                     flywheel.FileSpec('yeats.txt', poem))

        file_ref = flywheel.FileReference(id=collection_id,
                                          type='collection',
                                          name='yeats.txt')

        analysis = flywheel.AnalysisInput(label=self.rand_string(),
                                          description=self.rand_string(),
                                          inputs=[file_ref])

        # Add
        analysis_id = fw.add_collection_analysis(collection_id, analysis)
        self.assertNotEmpty(analysis_id)

        # Get the list of analyses in the collection
        r_collection = fw.get_collection(collection_id)
        self.assertEqual(len(r_collection.analyses), 1)

        r_analysis = r_collection.analyses[0]

        self.assertEqual(r_analysis.id, analysis_id)
        self.assertEmpty(r_analysis.job)

        self.assertTimestampBeforeNow(r_analysis.created)
        self.assertGreaterEqual(r_analysis.modified, r_analysis.created)

        self.assertEqual(len(r_analysis.inputs), 1)
        self.assertEqual(r_analysis.inputs[0].name, 'yeats.txt')
Example #6
0
    def test_ad_hoc_analysis(self):
        fw = self.fw

        # Upload to session
        poem = 'A gaze blank and pitiless as the sun,'
        fw.upload_file_to_session(self.session_id,
                                  flywheel.FileSpec('yeats.txt', poem))

        file_ref = flywheel.FileReference(id=self.session_id,
                                          type='session',
                                          name='yeats.txt')

        analysis = flywheel.AnalysisInput(label=self.rand_string(),
                                          description=self.rand_string(),
                                          inputs=[file_ref])

        # Add
        analysis_id = fw.add_session_analysis(self.session_id, analysis)
        self.assertNotEmpty(analysis_id)

        session = fw.get_session(self.session_id)
        self.assertEqual(len(session.analyses), 1)

        r_analysis = session.analyses[0]
        self.assertEqual(r_analysis.id, analysis_id)
        self.assertIsNone(r_analysis.job)
        self.assertTimestampBeforeNow(r_analysis.created)
        self.assertGreaterEqual(r_analysis.modified, r_analysis.created)
        self.assertEqual(len(r_analysis.inputs), 1)
        self.assertEqual(r_analysis.inputs[0].name, 'yeats.txt')

        # Access analysis directly
        r_analysis2 = fw.get_analysis(analysis_id)
        self.assertEqual(r_analysis, r_analysis2)

        # Generic Get is equivalent
        self.assertEqual(fw.get(analysis_id).to_dict(), r_analysis2.to_dict())

        # Analysis Notes
        text = self.rand_string()
        fw.add_session_analysis_note(self.session_id, analysis_id, text)

        # Check
        session = fw.get_session(self.session_id)
        self.assertEqual(len(session.analyses), 1)

        r_analysis = session.analyses[0]
        self.assertEqual(len(r_analysis.notes), 1)
        self.assertNotEmpty(r_analysis.notes[0].user)
        self.assertEqual(r_analysis.notes[0].text, text)
        self.assertTimestampBeforeNow(r_analysis.notes[0].created)
        self.assertTimestampBeforeNow(r_analysis.notes[0].modified)
        self.assertTimestampAfter(r_analysis.notes[0].modified,
                                  r_analysis.created)
        self.assertGreaterEqual(r_analysis.notes[0].modified,
                                r_analysis.notes[0].created)

        self.assertEqual(r_analysis.parent.id, session.id)

        # Access multiple analyses
        analysis2 = session.add_analysis(label=analysis.label,
                                         description=analysis.description,
                                         inputs=analysis.inputs)
        self.assertIsNotNone(analysis2)
        analysis_id2 = analysis2.id

        # Try getting analysis incorrectly
        self.assertRaises(flywheel.ApiException, fw.get_analyses, 'session',
                          self.session_id, 'projects')

        # Get all Session level analyses in group
        analyses = fw.get_analyses('groups', self.group_id, 'sessions')
        self.assertEqual(len(analyses), 2)

        self.assertEqual(
            1, len(list(filter(lambda x: x.id == r_analysis.id, analyses))))
        self.assertEqual(
            1, len(list(filter(lambda x: x.id == analysis_id2, analyses))))

        # Get project level analyses in group (will be zero)
        analyses = fw.get_analyses('groups', self.group_id, 'projects')
        self.assertEmpty(analyses)

        # Info, tags
        tag = 'example-tag'
        fw.add_analysis_tag(analysis_id, tag)

        # Replace info
        fw.replace_analysis_info(analysis_id, {'foo': 3, 'bar': 'qaz'})

        # Set info
        fw.set_analysis_info(analysis_id, {'foo': 42, 'hello': 'world'})

        # Check
        r_analysis = fw.get_analysis(analysis_id)
        self.assertEqual(r_analysis.tags, [tag])
        self.assertEqual(r_analysis.info, {
            'foo': 42,
            'bar': 'qaz',
            'hello': 'world'
        })

        # Delete info fields
        fw.delete_analysis_info_fields(analysis_id, ['foo', 'bar'])
        r_analysis = fw.get_analysis(analysis_id)
        self.assertEqual(r_analysis.info, {'hello': 'world'})