Skip to content

Commit 08c256a

Browse files
committed
added data testing unit test
1 parent 0262bab commit 08c256a

File tree

1 file changed

+68
-6
lines changed

1 file changed

+68
-6
lines changed

test_server.py

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
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
54
from api import ScryApiException, ScryApi
6-
5+
from test_data import *
76
from categories import create_category
87
from model import db, Categories
98

@@ -157,7 +156,7 @@ def test_null_in_not_null_column(self):
157156

158157
self.assertEqual(
159158
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']]}]}]
161160

162161
)
163162

@@ -214,6 +213,69 @@ def test_insert_schedule_data_successfully(self):
214213
{'message': 'Success'})
215214

216215

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+
217279
if __name__ == '__main__':
218280
initialize_categories()
219281
unittest.main()

0 commit comments

Comments
 (0)