Beispiel #1
0
    def test_report_headers__valid_schema_type__headers_as_list__report_correctly_generated(self, schema_type, non_oed):
        num_headers = np.random.choice(range(1, len(GROUPED_SCHEMA[schema_type])))
        oed = np.random.choice(list(GROUPED_SCHEMA[schema_type]), size=num_headers, replace=False).tolist()
        non_oed = ['non oed ' + s for s in non_oed]

        required_but_missing = [h for h, v in GROUPED_SCHEMA[schema_type].items() if v['required'] == 'R' and h not in oed]

        headers = oed + non_oed
        shuffle(headers)

        report = report_headers(schema_type, headers)

        if not (required_but_missing or non_oed):
            self.assertEqual(list(report), [])
        else:
            for line in report:
                self.assertIsNotNone(re.match(r'^:1:(-)?\d+:.*$', line))
Beispiel #2
0
    def test_report_headers__valid_schema_type__headers_as_file__report_correctly_generated(self, schema_type, non_oed):
        num_headers = np.random.choice(range(1, len(GROUPED_SCHEMA[schema_type])))
        oed = np.random.choice(list(GROUPED_SCHEMA[schema_type]), size=num_headers, replace=False).tolist()
        non_oed = ['non oed ' + s for s in non_oed]

        required_but_missing = [h for h, v in GROUPED_SCHEMA[schema_type].items() if v['required'] == 'R' and h not in oed]

        headers = oed + non_oed
        shuffle(headers)
        header_str = ','.join(headers)

        with NamedTemporaryFile('w') as file:
            file.write(header_str + '\n')
            file.flush()

            report = report_headers(schema_type, file.name)

            if not (required_but_missing or non_oed):
                self.assertEqual(list(report), [])
            else:
                for line in report:
                    self.assertIsNotNone(re.match(r'^{}:1.*$'.format(file.name), line))
Beispiel #3
0
 def test_report_headers__invalid_or_no_headers__oed_reporting_error_raised(self, schema_type, headers):
     with self.assertRaises(ReportingError):
         list(report_headers(schema_type, headers))
Beispiel #4
0
 def test_report_file__invalid_or_no_headers__oed_reporting_error_raised(self, schema_type):
     with NamedTemporaryFile('w') as file:
         with self.assertRaises(ReportingError):
             list(report_headers(schema_type, file.name))