Exemplo n.º 1
0
    def testListCLI(self):
        """
        Test that we can list clis, get help for each, and get the xml spec for
        each.
        """
        from girder.plugins.slicer_cli_web import rest_slicer_cli
        from girder.api.rest import Resource

        restResource = Resource()
        cli_args = ('--list_cli', )
        cli_list = self._runTest(cli_args, contains=['"NucleiDetection"'])
        cli_list = json.loads(cli_list)
        self.assertIn('NucleiDetection', cli_list)
        for cli in cli_list:
            cli_args = (cli, '--help')
            # Each cli's help must mention usage, its own name, and that you
            # can output xml
            self._runTest(cli_args, contains=['usage:', cli, '--xml'])
            cli_args = (cli, '--xml')
            # The xml output needs to have a tile and an executable tag
            xml = self._runTest(cli_args,
                                contains=[
                                    '<executable>', '<title>', '</executable>',
                                    '</title>'
                                ])
            if '<' in xml:
                xml = xml[xml.index('<'):]
            try:
                rest_slicer_cli.genHandlerToRunDockerCLI(
                    'dockerimage', os.environ.get('CLI_CWD'), xml,
                    restResource)
            except Exception:
                sys.stderr.write('Failed in generating endpoints for %s' % cli)
                raise
Exemplo n.º 2
0
    def test_genHandlerToRunDockerCLI(self):
        from girder.plugins.slicer_cli_web import docker_resource
        from girder.plugins.slicer_cli_web import rest_slicer_cli

        xmlpath = os.path.join(os.path.dirname(__file__), 'data', 'ExampleSpec.xml')
        cliXML = open(xmlpath, 'rb').read()
        resource = docker_resource.DockerResource('test')
        handlerFunc = rest_slicer_cli.genHandlerToRunDockerCLI(
            'dockerImage', 'data', cliXML, resource)
        self.assertIsNotNone(handlerFunc)

        job = handlerFunc(params={
            'inputImageFile_girderFileId': str(self.file['_id']),
            'secondImageFile_girderFileId': str(self.file['_id']),
            'outputStainImageFile_1_girderFolderId': str(self.folder['_id']),
            'outputStainImageFile_1_name': 'sample1.png',
            'outputStainImageFile_2_girderFolderId': str(self.folder['_id']),
            'outputStainImageFile_2_name': 'sample2.png',
            'stainColor_1': '[0.5, 0.5, 0.5]',
            'stainColor_2': '[0.2, 0.3, 0.4]',
            'returnparameterfile_girderFolderId': str(self.folder['_id']),
            'returnparameterfile_name': 'output.data',
        })
        self.assertHasKeys(
            job['kwargs']['inputs'],
            ['inputImageFile', 'stainColor_1', 'stainColor_2'])
        self.assertEqual(job['kwargs']['inputs']['inputImageFile']['id'], str(self.file['_id']))
        self.assertEqual(job['kwargs']['inputs']['stainColor_1']['data'], '[0.5, 0.5, 0.5]')
        self.assertEqual(job['kwargs']['inputs']['stainColor_1']['type'], 'number_list')
        self.assertHasKeys(
            job['kwargs']['outputs'],
            ['outputStainImageFile_1', 'outputStainImageFile_2', 'returnparameterfile'])
        self.assertEqual(len(job['kwargs']['task']['inputs']), 5)
        self.assertEqual(len(job['kwargs']['task']['outputs']), 3)