| 
1 |  | -import json, os  | 
2 |  | -import unittest  | 
3 |  | -import warnings  | 
4 |  | - | 
 | 1 | +import json, os, unittest, warnings  | 
 | 2 | +import pandas as pd  | 
 | 3 | +import numpy as np  | 
5 | 4 | from api import ScryApiException, ScryApi  | 
6 |  | - | 
 | 5 | +from test_data import *  | 
7 | 6 | from categories import create_category  | 
8 | 7 | from model import db, Categories  | 
9 | 8 | 
 
  | 
@@ -157,7 +156,7 @@ def test_null_in_not_null_column(self):  | 
157 | 156 | 
 
  | 
158 | 157 |         self.assertEqual(  | 
159 | 158 |                 error.exception.response['error'],  | 
160 |  | -                [{'IATA': [{'IsNull': [['2', None]]}]}, {'ICAO': [{'IsNull': [['0', None], ['1', None]]}]}, {'Callsign': [{'IsNull': [['1', None]]}]}, {'Country': [{'IsNull': [['1', None]]}]}]  | 
 | 159 | +                [{'IATA': [{'IsNull': [['2', 'nan']]}]}, {'ICAO': [{'IsNull': [['0', 'nan'], ['1', 'nan']]}]}, {'Callsign': [{'IsNull': [['1', 'nan']]}]}, {'Country': [{'IsNull': [['1', 'nan']]}]}]  | 
161 | 160 | 
 
  | 
162 | 161 |             )  | 
163 | 162 | 
 
  | 
@@ -214,6 +213,69 @@ def test_insert_schedule_data_successfully(self):  | 
214 | 213 |         {'message': 'Success'})  | 
215 | 214 | 
 
  | 
216 | 215 | 
 
  | 
 | 216 | + | 
 | 217 | +class DataTest(unittest.TestCase):  | 
 | 218 | + | 
 | 219 | +    df  = pd.DataFrame(data={'col1': ['a', 1,np.nan,np.nan], 'col2': [1, 'a',1,2.2]})  | 
 | 220 | + | 
 | 221 | +    meta=[{"col1":{"DataType": "Int","IsUnique": "true"}},  | 
 | 222 | +         {"col2":{"DataType": "Int","IsUnique": "true"}}]  | 
 | 223 | + | 
 | 224 | + | 
 | 225 | +    def test_is_null(self,df=df):  | 
 | 226 | +        self.assertEqual(  | 
 | 227 | +            serie_to_list (testIsNull(df['col1']).fillna(''))  | 
 | 228 | +            ,[[2, ''], [3, '']])  | 
 | 229 | + | 
 | 230 | + | 
 | 231 | +    def test_is_unique(self,df=df):  | 
 | 232 | +        self.assertEqual(  | 
 | 233 | +            serie_to_list (testIsUnique(df['col2']))  | 
 | 234 | +            ,[[0, 1], [2, 1]])  | 
 | 235 | + | 
 | 236 | + | 
 | 237 | +    def test_is_int(self,df=df):  | 
 | 238 | +        self.assertEqual(  | 
 | 239 | +            serie_to_list (testDataType(df['col2'],'Int'))  | 
 | 240 | +            ,[[1, 'a'], [3, 2.2]])  | 
 | 241 | + | 
 | 242 | + | 
 | 243 | +    def test_is_float(self,df=df):  | 
 | 244 | +        self.assertEqual(  | 
 | 245 | +            serie_to_list (testDataType(df['col2'],'Float'))  | 
 | 246 | +            ,[[1, 'a']])  | 
 | 247 | + | 
 | 248 | + | 
 | 249 | +    def test_standard(self):  | 
 | 250 | +        s=pd.Series(['2018-07-06T23:45:43','2018-07-06 23:45:43','2018-07-06T24:45:43'])  | 
 | 251 | + | 
 | 252 | +        self.assertEqual(  | 
 | 253 | +            serie_to_list (testDataType(s,'StandardTime'))  | 
 | 254 | +            ,[[1, '2018-07-06 23:45:43'], [2, '2018-07-06T24:45:43']])  | 
 | 255 | + | 
 | 256 | + | 
 | 257 | +    def test_all_tests_for_column(self,df=df):  | 
 | 258 | +        self.assertEqual(  | 
 | 259 | +            test_column(df['col1'],{"DataType": "Int","IsUnique": "true"})  | 
 | 260 | +            ,[{'DataType': [[0, 'a'], [2, 'nan'], [3, 'nan']]}, {'IsNull': [[2, 'nan'], [3, 'nan']]}])  | 
 | 261 | + | 
 | 262 | + | 
 | 263 | +    def test_all_tests_for_dataframe_with_errors(self, df=df, meta=meta):  | 
 | 264 | +        self.assertEqual(  | 
 | 265 | +            full_test(df, meta),  | 
 | 266 | +            (False, [{'col1': [{'DataType': [[0, 'a'], [2, 'nan'], [3, 'nan']]}, {'IsNull': [[2, 'nan'], [3, 'nan']]}]}, {'col2': [{'DataType': [[1, 'a'], [3, 2.2]]}, {'IsUnique': [[0, 1], [2, 1]]}]}])  | 
 | 267 | +            )  | 
 | 268 | + | 
 | 269 | + | 
 | 270 | +    def test_all_tests_for_dataframe_all_tests_pass_without_error(self, df=df, meta=meta):  | 
 | 271 | +        df  = pd.DataFrame(data={'col1': [2, 1,3,4], 'col2': [1, 2,3,4]})  | 
 | 272 | + | 
 | 273 | +        self.assertEqual(  | 
 | 274 | +            full_test(df, meta),  | 
 | 275 | +            (True, [])  | 
 | 276 | +            )  | 
 | 277 | + | 
 | 278 | + | 
217 | 279 | if __name__ == '__main__':  | 
218 | 280 |     initialize_categories()  | 
219 | 281 |     unittest.main()  | 
 | 
0 commit comments