예제 #1
0
    def test_acceptance_columnsMaxLength(self):
        # Log to file
        self.logger.debug("\n\n### Test Acceptance Columns Max Lenght\n")
        default_cols_max_lenght = self.db_columns_info.lengths
        test_columns_max_lenght = getColumnsMaxLength(self.anagrafica.df)

        # Test through all the columns
        for column_number, max_lenght in enumerate(default_cols_max_lenght):
            # If not Null
            if max_lenght:
                # Conditional assertion test
                if test_columns_max_lenght[column_number] > max_lenght:
                    column = self.anagrafica.df.iloc[:, column_number].map(
                        lambda x: getTrimmedLength(x))
                    condition = column > max_lenght
                    rows_to_check = column.loc[condition]
                    #TODO: sostituire iteritems() con metodo vettorizzato
                    for index, value in rows_to_check.iteritems():
                        # subTest allows no interruption if test fails
                        with self.subTest(max=max_lenght):
                            value_lenght = len(str(value).strip())
                            try:
                                self.assertGreaterEqual(
                                    value_lenght, max_lenght,
                                    "Column {}, row {} has {}".format(
                                        column_number, index, value_lenght))
                            except AssertionError:
                                pass

        self.logDifferences(default_cols_max_lenght, test_columns_max_lenght)
예제 #2
0
 def test_getTrimmedLength_int(self):
     value = 234
     self.assertEqual(getTrimmedLength(value), 3,
                      "Integer 234 must have length 3!")
예제 #3
0
 def test_getTrimmedLength_string(self):
     value = " Ciao ciao "
     self.assertEqual(getTrimmedLength(value), 9,
                      "String 'Ciao ciao ' must have length 9!")
예제 #4
0
 def test_getTrimmedLength_nan(self):
     value = np.nan
     self.assertFalse(getTrimmedLength(value), "Nan Length must be 0!")
예제 #5
0
 def test_getTrimmedLength_float(self):
     value = 234.02
     self.assertEqual(getTrimmedLength(value), 6,
                      "Float 234.02 must have length 6!")