Esempio n. 1
0
    def test_parser(self):
        test_args = [
            '-p', self.project_id, '-d', self.dataset_id, '-b',
            self.sandbox_dataset_id, '--data_stage', 'ehr'
        ]
        parser = cc.get_parser()
        args = parser.parse_args(test_args)
        self.assertIn(args.data_stage, DataStage)

        test_args = [
            '-p', self.project_id, '-d', self.dataset_id, '-b',
            self.sandbox_dataset_id, '--data_stage', 'unspecified'
        ]
        parser = cc.get_parser()
        self.assertRaises(SystemExit, parser.parse_args, test_args)

        test_args = [
            '-p', self.project_id, '-d', self.dataset_id, '-b',
            self.sandbox_dataset_id, '--data_stage', 'unknown'
        ]
        parser = cc.get_parser()
        self.assertRaises(SystemExit, parser.parse_args, test_args)
Esempio n. 2
0
    def test_fetch_args_kwargs(self):
        expected_kwargs = {
            'mapping_dataset_id': self.mapping_dataset_id,
            'combined_dataset_id': self.combined_dataset_id
        }
        expected_kwargs_list = []
        for k, v in expected_kwargs.items():
            expected_kwargs_list.extend([f'--{k}', v])

        test_args = [
            '-p', self.project_id, '-d', self.dataset_id, '-b',
            self.sandbox_dataset_id, '--data_stage', 'ehr'
        ]
        expected_args = {
            'project_id': self.project_id,
            'dataset_id': self.dataset_id,
            'sandbox_dataset_id': self.sandbox_dataset_id,
            'data_stage': DataStage.EHR,
            'console_log': False,
            'list_queries': False
        }
        parser = cc.get_parser()
        actual_args, actual_kwargs = cc.fetch_args_kwargs(
            parser, test_args + expected_kwargs_list)
        self.assertDictEqual(actual_args.__dict__, expected_args)
        self.assertDictEqual(expected_kwargs, actual_kwargs)

        actual_args, actual_kwargs = cc.fetch_args_kwargs(
            parser, test_args + ['--v', '-1'])
        self.assertDictEqual(actual_args.__dict__, expected_args)
        self.assertDictEqual({'v': '-1'}, actual_kwargs)

        test_args_incorrect = test_args + ['-v', 'value']
        self.assertRaises(RuntimeError, cc.fetch_args_kwargs, parser,
                          test_args_incorrect)

        test_args_incorrect = test_args + ['--v', 'v', '--odd']
        self.assertRaises(RuntimeError, cc.fetch_args_kwargs, parser,
                          test_args_incorrect)