Пример #1
0
    def test_CLIStatusEventTestCancel(self):
        self.delayDisplay('Testing status events when cancelling the execution of a CLI')

        tempFile = qt.QTemporaryFile("CLIEventTest-outputFile-XXXXXX")
        self.assertTrue(tempFile.open())

        logic = CLIEventTestLogic()
        parameters = {}
        parameters["InputValue1"] = 1
        parameters["InputValue2"] = 2
        parameters["OperationType"] = 'Addition'
        parameters["OutputFile"] = tempFile.fileName()

        cliModule = slicer.modules.cli4test
        cli = slicer.cli.createNode(cliModule)
        self.assertEqual(cli.GetStatus(), cli.Idle)

        logic.runCLI(cliModule, cli, parameters, False)
        cli.Cancel()

        while not logic.ExecutionFinished:
            self.delayDisplay('Waiting for module to complete...')

        expectedEvents = [
            cli.Scheduled,
            cli.Cancelling,
            cli.Cancelled,
        ]

        # Ignore cli.Running event (it may or may not be fired)
        if cli.Running in logic.StatusEvents:
            logic.StatusEvents.remove(cli.Running)

        self.assertEqual(logic.StatusEvents, expectedEvents)
        self.delayDisplay('Testing cancelled execution Passed')
Пример #2
0
    def _testCLIStatusEventOnErrorTest(self, wait_for_completion):
        self.delayDisplay('Testing status events for a bad execution of a CLI')

        tempFile = qt.QTemporaryFile("CLIEventTest-outputFile-XXXXXX")
        self.assertTrue(tempFile.open())

        logic = CLIEventTestLogic()
        parameters = {}
        parameters["InputValue1"] = 1
        parameters["InputValue2"] = 2
        parameters["OperationType"] = 'Fail'
        parameters["OutputFile"] = tempFile.fileName()

        cliModule = slicer.modules.cli4test
        cli = slicer.cli.createNode(cliModule)
        self.assertEqual(cli.GetStatus(), cli.Idle)

        logic.runCLI(cliModule, cli, parameters, wait_for_completion)

        while not logic.ExecutionFinished:
            self.delayDisplay('Waiting for module to complete...')

        cli = slicer.vtkMRMLCommandLineModuleNode()
        expectedEvents = []
        if not wait_for_completion:
            expectedEvents.append(cli.Scheduled)
        expectedEvents.append(cli.CompletedWithErrors)

        # Ignore cli.Running event (it may or may not be fired)
        if cli.Running in logic.StatusEvents:
            logic.StatusEvents.remove(cli.Running)

        self.assertEqual(logic.StatusEvents, expectedEvents)
        self.delayDisplay('Testing bad execution Passed')
Пример #3
0
 def test_downloadFromSource_downloadMRMLFile(self):
   logic = SampleDataLogic()
   tempFile = qt.QTemporaryFile(slicer.app.temporaryPath + "/SampleDataTest-loadSceneFile-XXXXXX.mrml");
   tempFile.open()
   tempFile.write(textwrap.dedent("""
     <?xml version="1.0" encoding="ISO-8859-1"?>
     <MRML  version="Slicer4.4.0" userTags="">
     </MRML>
     """).strip())
   tempFile.close()
   sceneMTime = slicer.mrmlScene.GetMTime()
   filePaths = logic.downloadFromSource(SampleDataSource(
     uris='file://' + tempFile.fileName(), fileNames='scene.mrml'))
   self.assertEqual(len(filePaths), 1)
   self.assertTrue(os.path.exists(filePaths[0]))
   self.assertTrue(os.path.isfile(filePaths[0]))
   self.assertEqual(sceneMTime, slicer.mrmlScene.GetMTime())
   os.remove(tempFile.fileName())
Пример #4
0
    def test_TwoCLIsInParallelTest(self):
        self.delayDisplay('Running two CLIs in a row Test')

        tempFile = qt.QTemporaryFile("TwoCLIsInParallelTest-outputFile-XXXXXX")
        self.assertTrue(tempFile.open())

        logic = TwoCLIsInParallelTestLogic()
        logic.parameters = {}
        logic.parameters["InputValue1"] = 1
        logic.parameters["InputValue2"] = 2
        logic.parameters["OperationType"] = 'Addition'
        logic.parameters["OutputFile"] = tempFile.fileName()

        logic.runModule1()
        self.delayDisplay('... Waiting to start module 2 ...')
        logic.runModule2()
        self.assertTrue(logic.success)

        self.delayDisplay('Two CLIs in parallel test passed !')
Пример #5
0
    def test_TwoCLIsInARowTest(self):
        self.delayDisplay('Running two CLIs in a row Test')

        tempFile = qt.QTemporaryFile("TwoCLIsInARowTest-outputFile-XXXXXX")
        self.assertTrue(tempFile.open())

        logic = TwoCLIsInARowTestLogic()
        logic.parameters = {}
        logic.parameters["InputValue1"] = 1
        logic.parameters["InputValue2"] = 2
        logic.parameters["OperationType"] = 'Addition'
        logic.parameters["OutputFile"] = tempFile.fileName()

        logic.runTest()
        while not logic.success:
            self.delayDisplay('Waiting for module 2 to complete...')
        self.assertTrue(logic.success)

        self.delayDisplay('Two CLIs in a row test passed !')