예제 #1
0
    def test_PipeLine_actually(self):

        # Write a file to test
        f = tempfile.NamedTemporaryFile(mode='w+t',
                                        suffix='.csv',
                                        prefix='test_Job_title_fix_Co',
                                        delete=False)
        f.write('LAT, LONG, a_test, b_test,BUILDING\n')
        f.write('1., 2., 3., 30.,TAB\n')
        f.write('4., 5., 6., 60.,DSG\n')
        f.close()
        f2 = tempfile.NamedTemporaryFile(suffix='.csv',
                                         prefix='test_Job_title_fix_Co',
                                         delete=False)
        f2.close()
        atts = {
            'file_name': f.name,
            context.EX_LAT: 'LAT',
            context.EX_LONG: 'LONG'
        }
        caj1 = workflow.ConfigAwareJob(JOBS[LOADCSVEXPOSURE], atts_to_add=atts)

        atts = {'var': 'con_test', 'value': 'yeah'}
        caj2 = workflow.ConfigAwareJob(JOBS[CONSTANT], atts_to_add=atts)
        atts = {'var': 'con2_test', 'value': 30}
        caj3 = workflow.ConfigAwareJob(JOBS[CONSTANT], atts_to_add=atts)

        calc_list = [caj1, caj2, caj3, CALCS['add_test']]
        cont_in = context.Context()
        cont_in.set_prov_label('Test label')

        the_pipeline = pipeline.PipeLine(calc_list)
        the_pipeline.run(cont_in)
        cont_dict = cont_in.save_exposure_atts(f2.name)
        os.remove(f2.name)
        if parallel.STATE.rank == 0:
            self.assertTrue(allclose(cont_dict['c_test'], asarray([33., 66.])))
            self.assertEqual(cont_dict['BUILDING'].tolist(), ['TAB', 'DSG'])
            self.assertTrue(
                allclose(cont_dict['con2_test'], asarray([30., 30.])))
            self.assertEqual(cont_dict['con_test'].tolist(), ['yeah', 'yeah'])
        os.remove(f.name)
예제 #2
0
 def test_BuilderII(self):
     a_test = 5
     b_test = 2
     caj = workflow.ConfigAwareJob(CALCS['constant_test'],
                                   atts_to_add={'constant': 5})
     calc_list = [CALCS['add_test'], CALCS['multiply_test'], caj]
     cont_in = context.Context()
     cont_in.exposure_att = {'a_test': a_test, 'b_test': b_test}
     the_pipeline = pipeline.PipeLine(calc_list)
     the_pipeline.run(cont_in)
     self.assertEqual(cont_in.exposure_att['d_test'], 35)
     self.assertEqual(cont_in.exposure_att['g_test'], 10)
예제 #3
0
def add_job(jobs, new_job, atts=None):
    """
    Given a list of jobs, add a new job and it's att's to the job.

    :param jobs: A list of jobs.
    :param new_job: The new job, as a string.
    :param atts: The attributes of the new job.
    """
    if atts is None:
        atts = {}
    job_inst = _get_job_or_calc(new_job)
    validate_job_instance(job_inst, atts)
    caj = workflow.ConfigAwareJob(job_inst, atts_to_add=atts)
    jobs.append(caj)