Esempio n. 1
0
    def testDateStandardiser(
            self):  # - - - - - - - - - - - - - - - - - - - - -
        """Test date standardiser routines"""

        return

        ds = standardisation.DateStandardiser(
            descript="Test date standardiser",
            parse_form=self.date_parse_formats,
            input_fields=["in_date"],
            output_fiel=["day", "month", "year"],
        )

        rs = standardisation.RecordStandardiser(
            descr="Test record standardiser",
            input_dataset=self.in_ds,
            output_dataset=self.out_ds,
            comp_stand_list=[ds],
            pass_fiel=[("pass1", "out_pass1"), ("pass2", "out_pass2")],
        )

        for (date_str, date_res) in self.dates:

            clean_date_str = ds.clean_component(date_str)
            test_date_res = ds.standardise(date_str, clean_date_str)

            assert date_res == test_date_res, (
                "Wrong date standardisation: %s, should be: %s" %
                (str(test_date_res), str(date_res)))

        rs.standardise()  # Use record standardiser and write output file

        # Test the content of the output data set
        #
        test_ds = dataset.DataSetCSV(
            description="Test standardised data set",
            access_mode="read",
            rec_ident="rec_id",
            field_list=[],
            header_line=True,
            write_header=True,
            file_name="test-standardised-dataset.csv",
        )

        i = 0
        for (rec_id, rec_list) in test_ds.readall():
            test_day = rec_list[0]
            test_month = rec_list[1]
            test_year = rec_list[2]

            true_day = self.dates[i][1][0]
            true_month = self.dates[i][1][1]
            true_year = self.dates[i][1][2]

            assert test_day == true_day, (i, rec_list[0:3], self.dates[i][1])
            assert test_month == true_month, (i, rec_list[0:3],
                                              self.dates[i][1])
            assert test_year == true_year, (i, rec_list[0:3], self.dates[i][1])

            i += 1
Esempio n. 2
0
    def testDateStandardiser(
            self):  # - - - - - - - - - - - - - - - - - - - - -
        """Test date standardiser routines"""

        return

        ds = standardisation.DateStandardiser(
            descript='Test date standardiser',
            parse_form=self.date_parse_formats,
            input_fields=['in_date'],
            output_fiel=['day', 'month', 'year'])

        rs = standardisation.RecordStandardiser(
            descr='Test record standardiser',
            input_dataset=self.in_ds,
            output_dataset=self.out_ds,
            comp_stand_list=[ds],
            pass_fiel=[('pass1', 'out_pass1'), ('pass2', 'out_pass2')])

        for (date_str, date_res) in self.dates:

            clean_date_str = ds.clean_component(date_str)
            test_date_res = ds.standardise(date_str, clean_date_str)

            assert date_res == test_date_res, \
                   'Wrong date standardisation: %s, should be: %s' % \
                   (str(test_date_res), str(date_res))

        rs.standardise()  # Use record standardiser and write output file

        # Test the content of the output data set
        #
        test_ds = dataset.DataSetCSV(description='Test standardised data set',
                                     access_mode='read',
                                     rec_ident='rec_id',
                                     field_list=[],
                                     header_line=True,
                                     write_header=True,
                                     file_name='test-standardised-dataset.csv')

        i = 0
        for (rec_id, rec_list) in test_ds.readall():
            test_day = rec_list[0]
            test_month = rec_list[1]
            test_year = rec_list[2]

            true_day = self.dates[i][1][0]
            true_month = self.dates[i][1][1]
            true_year = self.dates[i][1][2]

            assert test_day == true_day, (i, rec_list[0:3], self.dates[i][1])
            assert test_month == true_month, (i, rec_list[0:3],
                                              self.dates[i][1])
            assert test_year == true_year, (i, rec_list[0:3], self.dates[i][1])

            i += 1