def test_task(self):
     with open("test_template.txt", "w") as fp:
         fp.write("option1 = {{opt1}}\noption2 = {{opt2}}")
     t = TemplateWriterTask(
         {
             "context": {"opt1": 5.0, "opt2": "fast method"},
             "template_file": "test_template.txt",
             "output_file": "out_template.txt",
             "template_dir": ".",
         }
     )
     t.run_task({})
     self.assertTrue(os.path.exists("out_template.txt"))
     with open("out_template.txt") as fp:
         for line in fp:
             if "option1" in line:
                 self.assertTrue("5.0" in line)
             if "option2" in line:
                 self.assertTrue("fast method" in line)
     os.remove("out_template.txt")
     if os.path.exists("test_template.txt"):
         os.remove("test_template.txt")
Esempio n. 2
0
 def test_task(self):
     with open('test_template.txt', 'w') as fp:
         fp.write("option1 = {{opt1}}\noption2 = {{opt2}}")
     t = TemplateWriterTask({
         'context': {
             'opt1': 5.0,
             'opt2': 'fast method'
         },
         'template_file': 'test_template.txt',
         'output_file': 'out_template.txt',
         'template_dir': '.'
     })
     t.run_task({})
     self.assertTrue(os.path.exists('out_template.txt'))
     with open('out_template.txt') as fp:
         for line in fp:
             if "option1" in line:
                 self.assertTrue("5.0" in line)
             if "option2" in line:
                 self.assertTrue("fast method" in line)
     os.remove('out_template.txt')
     if os.path.exists('test_template.txt'):
         os.remove('test_template.txt')
Esempio n. 3
0
    def test_multi_fw_complex(self):

        dest1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'inputs.txt')
        dest2 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'temp_file.txt')
        self._teardown([dest1, dest2])
        try:
            # create the Firework consisting of multiple tasks
            firetask1 = TemplateWriterTask({'context': {'opt1': 5.0, 'opt2': 'fast method'}, 'template_file': 'simple_template.txt', 'output_file': dest1})
            firetask2 = FileTransferTask({'files': [{'src': dest1, 'dest': dest2}], 'mode': 'copy'})
            fw = Firework([firetask1, firetask2])

            # store workflow and launch it locally, single shot
            self.lp.add_wf(fw)
            launch_rocket(self.lp, self.fworker)

            # read inputs.txt, words.txt, dest
            for d in [dest1, dest2]:
                with open(d) as f:
                    self.assertEqual(f.read(), 'option1 = 5.0\noption2 = fast method')

        finally:
            self._teardown([dest1, dest2])
Esempio n. 4
0
    def test_multi_fw_complex(self):

        dest1 = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             "inputs.txt")
        dest2 = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             "temp_file.txt")
        self._teardown([dest1, dest2])
        try:
            # create the Firework consisting of multiple tasks
            firetask1 = TemplateWriterTask({
                "context": {
                    "opt1": 5.0,
                    "opt2": "fast method"
                },
                "template_file": "simple_template.txt",
                "output_file": dest1,
            })
            firetask2 = FileTransferTask({
                "files": [{
                    "src": dest1,
                    "dest": dest2
                }],
                "mode":
                "copy"
            })
            fw = Firework([firetask1, firetask2])

            # store workflow and launch it locally, single shot
            self.lp.add_wf(fw)
            launch_rocket(self.lp, self.fworker)

            # read inputs.txt, words.txt, dest
            for d in [dest1, dest2]:
                with open(d) as f:
                    self.assertEqual(f.read(),
                                     "option1 = 5.0\noption2 = fast method")

        finally:
            self._teardown([dest1, dest2])