class ComponentTester: def __init__(self, taskName='test_task'): self.taskDirectory = 'data/test_tasks/' self.taskName = taskName + '.xml' taskPath = self.taskDirectory + self.taskName self.taskBuilder = TaskBuilder(taskPath) self.taskBuilder.createTemplate() self.taskBuilder.addDefaultExecutor() self.taskBuilder.save() self.componentSinkName = 'Component.in_data' self.generatorOutput = 'out_data' self.componentName = 'Component' self.componentOutput = 'out_data' self.runner = DisCODeRunner() def setComponent(self, componentName, componentType): self.taskBuilder.addComponent(componentName, componentType) self.taskBuilder.save() def addGenerator(self, generatorType, generatorName = 'Generator'): self.taskBuilder.addComponent(generatorName, generatorType) self.taskBuilder.save() def addSink(self, sinkType, sinkInput = 'in_data'): self.taskBuilder.addComponent('Sink', sinkType) self.taskBuilder.save() def addDataStream(self, sourceName, sourcePort, sinkName, sinkPort): self.taskBuilder.addDataStream(sourceName + '.' + sourcePort, sinkName + '.' + sinkPort) self.taskBuilder.save() def start(self, taskName=''): if taskName is '': self.runner.taskName = self.taskDirectory + self.taskName else: self.runner.taskName = taskName self.runner.start() def getOutput(self): return self.runner.readOutput() def stop(self): self.runner.kill() def addTerminationStatement(self, terminationStatement): self.runner.terminationStatements.append(terminationStatement) def resetTerminationStatements(self): self.runner.terminationStatements = [] def setDebugMode(self, debugMode): self.runner.debugMode = debugMode
def __init__(self, taskName='test_task'): self.taskDirectory = 'data/test_tasks/' self.taskName = taskName + '.xml' taskPath = self.taskDirectory + self.taskName self.taskBuilder = TaskBuilder(taskPath) self.taskBuilder.createTemplate() self.taskBuilder.addDefaultExecutor() self.taskBuilder.save() self.componentSinkName = 'Component.in_data' self.generatorOutput = 'out_data' self.componentName = 'Component' self.componentOutput = 'out_data' self.runner = DisCODeRunner()
def setUp(self): self.runner = DisCODeRunner()
class TestDisCODeRunner(unittest.TestCase): def setUp(self): self.runner = DisCODeRunner() def test_discode_exists_on_path(self): import os discodeExecutable = 'discode' def isExe(filepath): return os.path.isfile(filepath) and os.access(filepath, os.X_OK) discodeExists = False for path in os.environ['PATH'].split(os.pathsep): path = path.strip('"') discodePath = os.path.join(path, discodeExecutable) if isExe(discodePath): discodeExists = True assert_that(discodeExists, equal_to(True)) def test_if_dcl_dir_exists(self): import os discode_dcl_dir = os.environ['DISCODE_DCL_DIR'] assert_that(discode_dcl_dir, is_not(empty)) def test_if_discode_runs(self): self.runner.start() output = self.runner.readOutput() assert_that(output, contains_string('\x1b[33mWARNING: \x1b[00mConfiguration file config.xml not found.\n')) def test_displays_error_when_no_task_specified(self): self.runner.terminationStatements = [] self.runner.start() output = self.runner.readOutput() assert_that(output, contains_string('ERROR')) assert_that(output, contains_string('No task specified!')) # @unittest.skip('integration test skipped!') def test_if_discode_runs_with_task(self): self.runner.taskName = 'CvBasic:SequenceViewer' self.runner.terminationStatements = [] self.runner.start() time.sleep(.500) self.runner.process.kill() output = self.runner.readOutput() assert_that(output, contains_string('Kopiowanie TASKA!')) # @unittest.skip('integration test skipped!') def test_if_discode_is_killed_manually(self): self.runner.taskName = 'data/SequenceViewer.xml' self.runner.logLevel = '0' self.runner.start() time.sleep(5) self.runner.kill() output = self.runner.readOutput() assert_that(output, contains_string('Finishing DisCODe.')) assert_that(output, contains_string('Server stoped.')) # @unittest.skip('integration test skipped!') def test_if_discode_is_killed_on_termination_statement(self): self.runner.taskName = 'data/SequenceViewer.xml' self.runner.terminationStatements = [] self.runner.terminationStatements.append('ERROR') self.runner.start() output = self.runner.readOutput() assert_that(output, contains_string('Finishing DisCODe.')) assert_that(output, contains_string('Server stoped.')) # @unittest.skip('integration test skipped!') def test_if_discode_is_killed_on_error_with_different_termination_statement_set(self): self.runner.taskName = 'data/SequenceViewer.xml' self.runner.terminationStatements.append('SOME TERMINATION STATEMENT') self.runner.start() output = self.runner.readOutput() assert_that(output, contains_string('ERROR')) assert_that(output, contains_string('Finishing DisCODe.')) assert_that(output, contains_string('Server stoped.')) # @unittest.skip('integration test skipped!') def test_if_prints_output_when_debug_flag_is_set(self): from io import StringIO out = StringIO() self.runner.taskName = 'data/SequenceViewer.xml' self.runner.debugMode = True self.runner.start(out) output = out.getvalue().strip() assert_that(output, contains_string('\x1b[33mWARNING: \x1b[00mConfiguration file config.xml not found.\n'))