예제 #1
0
    def test_files(self):
        mydir = osp.dirname(__file__)
        if SEATBELT_FILE and osp.isfile(SEATBELT_FILE):
            res_file = SEATBELT_FILE
        else:
            tmpdir = tempfile.gettempdir()
            res_file = osp.join(tmpdir, 'co2mpas_seatbelt_demos.dill')

        log.info(
            "\n  OVERWRITE_SEATBELT: %s \n"
            "  RUN_INPUT_FOLDER: %s \n"
            "  RUN_ALL_FILES: %s \n"
            "  SEATBELT_FILE: %s", OVERWRITE_SEATBELT, RUN_INPUT_FOLDER,
            RUN_ALL_FILES, res_file)

        if not OVERWRITE_SEATBELT and osp.isfile(res_file):
            old_results = sh.load_dispatcher(res_file)
            log.info("Old results loaded!")
        else:
            old_results = None

        path = RUN_INPUT_FOLDER or osp.join(mydir, '..', 'co2mpas', 'demos')
        file = (path if (RUN_ALL_FILES or RUN_INPUT_FOLDER) else osp.join(
            path, 'co2mpas_demo-0.xlsx'))

        model = vehicle_processing_model()

        results = []

        inp_files = file_finder([file])
        if not inp_files:
            raise AssertionError("DataCheck found no input-files in %r!" %
                                 file)

        for fpath in inp_files:
            fname = osp.splitext(osp.basename(fpath))[0]
            log.info('Processing: %s', fname)

            inputs = {
                'input_file_name': fpath,
                'variation': {
                    'flag.only_summary': True
                }
            }
            r = model.dispatch(inputs=inputs)
            r = sh.selector(['report', 'summary'], r['solution'])
            r.get('report', {}).pop('pipe', None)
            results.append(sorted(sh.stack_nested_keys(r)))

        if not OVERWRITE_SEATBELT and osp.isfile(res_file):
            log.info('Comparing...')
            self._check_results(results, old_results)
        else:
            os.environ["OVERWRITE_SEATBELT"] = '0'
            sh.save_dispatcher(results, res_file)
            log.info('Overwritten seat belt %r.', res_file)
예제 #2
0
 def test_load_dispatcher(self):
     sh.save_dispatcher(self.dsp, self.tmp)
     dsp = sh.load_dispatcher(self.tmp)
     self.assertEqual(dsp.dmap.nodes['a']['type'], 'data')
     self.assertEqual(dsp.dispatch()['b'], 6)
예제 #3
0
 def test_save_dispatcher(self):
     sh.save_dispatcher(self.dsp, self.tmp)