Exemple #1
0
    def testFailJobOnMerge(self):
        from Ganga.GPI import CustomMerger

        self.runJobSlice()
        tmpdir = tempfile.mktemp()
        os.mkdir(tmpdir)

        file_name = os.path.join(tmpdir, 'merge.py')
        with open(file_name, 'w') as module_file:
            module_file.write("""def mergefiles(file_list, output_file):
    '''Free script for merging files'''
    return False
        """)

        cm = CustomMerger(module=file_name)
        cm.files = ['out.txt', 'out2.txt']
        with pytest.raises(PostProcessException):
            cm.merge(self.jobslice, tmpdir)

        j = self.jobslice[0].copy()
        j.splitter = CopySplitter()
        j.postprocessors = cm
        j.submit()

        run_until_state(j, state='failed')
        assert j.status == 'failed'
Exemple #2
0
    def testFailJobOnMerge(self):
        from Ganga.GPI import CustomMerger

        self.runJobSlice()
        tmpdir = tempfile.mktemp()
        os.mkdir(tmpdir)

        file_name = os.path.join(tmpdir, 'merge.py')
        with open(file_name, 'w') as module_file:
            module_file.write("""def mergefiles(file_list, output_file):
    '''Free script for merging files'''
    return False
        """)

        cm = CustomMerger(module=file_name)
        cm.files = ['out.txt', 'out2.txt']
        with pytest.raises(PostProcessException):
            cm.merge(self.jobslice, tmpdir)

        j = self.jobslice[0].copy()
        j.splitter = CopySplitter()
        j.postprocessors = cm
        j.submit()

        run_until_state(j, state='failed')
        assert j.status == 'failed'
Exemple #3
0
    def testSimpleCustomMerge(self):
        from Ganga.GPI import CustomMerger

        self.runJobSlice()
        tmpdir = tempfile.mktemp()
        os.mkdir(tmpdir)

        file_name = os.path.join(tmpdir, 'merge.py')
        with open(file_name, 'w') as module_file:
            module_file.write("""from __future__ import print_function
def mergefiles(file_list, output_file):
    '''Free script for merging files'''
    
    with file(output_file,'w') as out:
        for f in file_list:
            print(f, file=out)
    
    return True
        """)

        cm = CustomMerger(module=file_name)
        cm.files = ['out.txt', 'out2.txt']
        assert cm.merge(self.jobslice, tmpdir), 'Merge should complete'
        assert os.path.exists(os.path.join(tmpdir, 'out.txt')), 'out.txt must exist'
        assert os.path.exists(os.path.join(tmpdir, 'out2.txt')), 'out2.txt must exist'
Exemple #4
0
    def testSimpleCustomMerge(self):
        from Ganga.GPI import CustomMerger

        self.runJobSlice()
        tmpdir = tempfile.mktemp()
        os.mkdir(tmpdir)

        file_name = os.path.join(tmpdir, 'merge.py')
        with open(file_name, 'w') as module_file:
            module_file.write("""from __future__ import print_function
def mergefiles(file_list, output_file):
    '''Free script for merging files'''
    
    with file(output_file,'w') as out:
        for f in file_list:
            print(f, file=out)
    
    return True
        """)

        cm = CustomMerger(module=file_name)
        cm.files = ['out.txt', 'out2.txt']
        assert cm.merge(self.jobslice, tmpdir), 'Merge should complete'
        assert os.path.exists(os.path.join(tmpdir,
                                           'out.txt')), 'out.txt must exist'
        assert os.path.exists(os.path.join(tmpdir,
                                           'out2.txt')), 'out2.txt must exist'