def test_basic(self):
     with open('TestFiles/MakedirsBlock_test/test_basic/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         block = generateSerialBlock(data)
         self.assertTrue(isinstance(block.steps[0], MakedirsBlock))
         self.assertEqual(block.steps[0].dir,
                          'Output/MkdirBlock_test/TestDir1')
Exemple #2
0
 def run(self, workingDir, variables = {}, printer = Printer()):
     curDir = os.getcwd()
     printer.print("["+"RUN".ljust(10) + "] ---", self.testSuite.name + ("/" if self.testSuite.name != "" else "") + self.testCase.name)
     try:
         startTime = time.time()
         processStartTime = time.process_time()
         data = processScriptData(self.testCase.file, saveUpgradedScript = self.upgradeScriptFile, printer = printer)
         block = generateSerialBlock(data)
         if block == None: return
         res = block.run(workingDir = str(PurePath(self.testCase.file).parent), printer = printer)
         if (not res):
             self.testCase.add_failure_info(printer.errorOutput or "failed")
     except Exception as e:
         self.testCase.add_error_info(str(e))
         printer.print(str(e))
     finally:
         self.testCase.elapsed_sec = time.time() - startTime
         testResStr = "PASSED"
         if self.testCase.is_error(): 
             testResStr = "ERROR"
         elif self.testCase.is_failure(): 
             testResStr = "FAILED"
         printStr = "["+testResStr.rjust(10) + "] --- " + self.testSuite.name + ("/" if self.testSuite.name != "" else "") + self.testCase.name
         if (printer.isVerbose()): 
             printStr += " --- process time: "+  '%.2f' % (time.process_time() - processStartTime) + " execution time: "+  '%.2f' % (time.time() - startTime)
         printer.print(printStr)
     return testResStr == "PASSED"
 def test_invalid_commad(self):
     with open(
             'TestFiles/GeneratorRunBlock_test/test_invalid_commad/script.yaml'
     ) as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         with self.assertRaisesRegex(GeneratorException,
                                     "'run' block not recognized") as e:
             block = generateSerialBlock(data)
 def test_basic(self):
     with open('TestFiles/GeneratorDiffBlock_test/test_basic/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         block = generateSerialBlock(data)
         self.assertTrue(isinstance(block.steps[0], DiffBlock))
         self.assertEqual(block.steps[0].binarycompare, True)
         self.assertEqual(block.steps[0].ignore, ['Time:'])
         self.assertEqual(block.steps[0].paths, ['output/leftpath', 'output/rightpath'])
         self.assertEqual(block.steps[0].strategy, diffStrategy.IgnoreLeftOrphans)
 def test_basic(self):
     with open('TestFiles/GeneratorLooper_test/test_basic/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         block = generateSerialBlock(data)
         self.assertEqual(block.entries, [{'color': 'red', 'shape': 'circle'}, {'color': 'yellow', 'shape': 'square'}, {'shape': 'triangle'}])
         self.assertEqual(block.failfast, False)
         self.assertEqual(block.steps[0].steps, [])
         self.assertEqual(block.steps[0].entries, [{'color': 'red', 'shape': 'circle'}, {'color': 'yellow', 'shape': 'circle'}, {'color': 'red', 'shape': 'square'}, {'color': 'yellow', 'shape': 'square'}, {'color': 'red', 'shape': 'triangle'}, {'color': 'yellow', 'shape': 'triangle'}])
         self.assertEqual(block.steps[0].steps, [])
 def test_parallel(self):
     with open('TestFiles/GeneratorLooper_test/test_parallel/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         block = generateSerialBlock(data)
         self.assertTrue(isinstance(block.steps[0], Parallel))
         self.assertEqual(block.failfast, False)
         self.assertEqual(block.steps[0].entries, [{'color': 'red', 'shape': 'circle'}, {'color': 'yellow', 'shape': 'circle'}, {'color': 'red', 'shape': 'square'}, {'color': 'yellow', 'shape': 'square'}, {'color': 'red', 'shape': 'triangle'}, {'color': 'yellow', 'shape': 'triangle'}])
         self.assertEqual(block.steps[0].max_workers, 5)
         self.assertTrue(isinstance(block.steps[0].steps[0], Serial))
 def test_invalid_exitcode(self):
     with open(
             'TestFiles/GeneratorRunBlock_test/test_invalid_exitcode/script.yaml'
     ) as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         with self.assertRaisesRegex(
                 GeneratorException,
                 "field 'exitCode' expects an integer at line .*") as e:
             block = generateSerialBlock(data)
 def test_basic(self):
     with open('TestFiles/GeneratorRunBlock_test/test_basic/script.yaml'
               ) as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         block = generateSerialBlock(data)
         self.assertTrue(isinstance(block.steps[0], RunBlock))
         self.assertEqual(block.steps[0].cmd, "echo $shapes $color")
         self.assertEqual(block.steps[0].exitcode, 0)
         self.assertEqual(block.steps[0].inputfile, 'input/inp.txt')
         self.assertEqual(block.steps[0].outputfile, 'output/out.txt')
 def test_invalid_paths_three_paths(self):
     with open('TestFiles/GeneratorDiffBlock_test/test_invalid_paths_three_paths/script.yaml') as f:
         with self.assertRaisesRegex(GeneratorException, "Field 'paths' expects two paths at line 4") as e:
             data = yaml.load(f, Loader=SafeLineLoader)
             block = generateSerialBlock(data)
 def test_invalid_ignore(self):
     with open('TestFiles/GeneratorDiffBlock_test/test_invalid_ignore/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         with self.assertRaisesRegex(GeneratorException, "field 'ignore' expects a list at line .*") as e:
             block = generateSerialBlock(data)
 def test_invalid_strategy(self):
     with open('TestFiles/GeneratorDiffBlock_test/test_invalid_strategy/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         with self.assertRaisesRegex(GeneratorException, "Invalid value 'IgnoreLeftOrphanss' for field 'strategy' at line .*") as e:
             block = generateSerialBlock(data)
 def test_simple_fail(self):
     with open('TestFiles/GeneratorDiffBlock_test/test_simple_fail/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         with self.assertRaisesRegex(GeneratorException, "'diff' block not recognized") as e:
             block = generateSerialBlock(data)
 def test_parallel_invalid_max_workers(self):
     with open('TestFiles/GeneratorLooper_test/test_parallel_invalid_max_workers/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         with self.assertRaisesRegex(GeneratorException, "field 'max_workers' expects an integer at line .*") as e:
             block = generateSerialBlock(data)
 def test_invalid_entries_field(self):
     with open('TestFiles/GeneratorLooper_test/test_invalid_entries_field/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         with self.assertRaisesRegex(GeneratorException, "Only one of the following keys are allowed: .*") as e:
             block = generateSerialBlock(data)
 def test_multipleEntries(self):
     with open('TestFiles/GeneratorLooper_test/test_multipleEntries/script.yaml') as f:
         data = yaml.load(f, Loader=SafeLineLoader)
         block = generateSerialBlock(data)
         self.assertEqual(block.entries, [{'color': 'red', 'shape': 'circle'}, {'color': 'yellow', 'shape': 'square'}, {'shape': 'triangle'}, {'fruit': 'apple', 'vegetable': 'onion'}, {'fruit': 'apple', 'vegetable': 'carot'}, {'fruit': 'banana', 'vegetable': 'onion'}, {'fruit': 'banana', 'vegetable': 'carot'}])
         self.assertEqual(block.steps, [])