예제 #1
0
  def testPhoneNumStandardiserNone(self):
    """Test phone number standardiser routines"""

    return

    ps = standardisation.PhoneNumStandardiser(descript = \
                                              'Test phone number standardiser',
                                          input_fields = ['in_phonenum'],
                                          output_fiel = ['country_code',
                                                         None,
                                                         'area_code', 'number',
                                                         None])

    rs = standardisation.RecordStandardiser(descr = 'Test record standardiser',
                                            input_dataset = self.in_ds,
                                            output_dataset = self.out_ds,
                                            comp_stand_list = [ps])

    for (phonenum_str, phonenum_res) in self.phonenums:

      clean_phonenum_str = ps.clean_component(phonenum_str)
      test_phonenum_res =  ps.standardise(phonenum_str, clean_phonenum_str)

      assert phonenum_res == test_phonenum_res, \
             'Wrong phone number standardisation: %s, should be: %s' % \
             (str(test_phonenum_res), str(phonenum_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_country_code = rec_list[3]
      test_country_name = rec_list[4]
      test_area_code =    rec_list[5]
      test_number =       rec_list[6]
      test_extension =    rec_list[7]

      true_country_code = self.phonenums[i][1][0]
      true_area_code =    self.phonenums[i][1][2]
      true_number =       self.phonenums[i][1][3]

      assert test_country_code == true_country_code, \
             (i, rec_list[3:8], self.phonenums[i][1])
      assert test_country_name == '', \
             (i, rec_list[3:8], self.phonenums[i][1])
      assert test_area_code == true_area_code, \
             (i, rec_list[3:8], self.phonenums[i][1])
      assert test_number == true_number, \
             (i, rec_list[3:8], self.phonenums[i][1])
      assert test_extension == '', \
             (i, rec_list[3:8], self.phonenums[i][1])

      i += 1
예제 #2
0
    def testPhoneNumStandardiserNone(self):
        """Test phone number standardiser routines"""

        return

        ps = standardisation.PhoneNumStandardiser(
            descript="Test phone number standardiser",
            input_fields=["in_phonenum"],
            output_fiel=["country_code", None, "area_code", "number", None],
        )

        rs = standardisation.RecordStandardiser(
            descr="Test record standardiser",
            input_dataset=self.in_ds,
            output_dataset=self.out_ds,
            comp_stand_list=[ps],
        )

        for (phonenum_str, phonenum_res) in self.phonenums:

            clean_phonenum_str = ps.clean_component(phonenum_str)
            test_phonenum_res = ps.standardise(phonenum_str,
                                               clean_phonenum_str)

            assert phonenum_res == test_phonenum_res, (
                "Wrong phone number standardisation: %s, should be: %s" %
                (str(test_phonenum_res), str(phonenum_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_country_code = rec_list[3]
            test_country_name = rec_list[4]
            test_area_code = rec_list[5]
            test_number = rec_list[6]
            test_extension = rec_list[7]

            true_country_code = self.phonenums[i][1][0]
            true_area_code = self.phonenums[i][1][2]
            true_number = self.phonenums[i][1][3]

            assert test_country_code == true_country_code, (
                i,
                rec_list[3:8],
                self.phonenums[i][1],
            )
            assert test_country_name == "", (i, rec_list[3:8],
                                             self.phonenums[i][1])
            assert test_area_code == true_area_code, (
                i,
                rec_list[3:8],
                self.phonenums[i][1],
            )
            assert test_number == true_number, (i, rec_list[3:8],
                                                self.phonenums[i][1])
            assert test_extension == "", (i, rec_list[3:8],
                                          self.phonenums[i][1])

            i += 1