46
46
{"name" : "REASON_HomeImp" , "type" : "integer" },
47
47
]
48
48
49
+
49
50
class BadModel :
50
51
attr = None
51
52
53
+
52
54
@pytest .fixture
53
55
def bad_model ():
54
56
return BadModel ()
@@ -78,6 +80,7 @@ def sklearn_model(train_data):
78
80
model .fit (X , y )
79
81
return model
80
82
83
+
81
84
@pytest .fixture
82
85
def change_dir ():
83
86
"""Change working directory for the duration of the test."""
@@ -711,9 +714,7 @@ def test_create_requirements_json(change_dir):
711
714
},
712
715
]
713
716
unittest .TestCase .maxDiff = None
714
- unittest .TestCase ().assertCountEqual (
715
- json_dict , expected
716
- )
717
+ unittest .TestCase ().assertCountEqual (json_dict , expected )
717
718
718
719
719
720
class TestAssessBiasHelpers (unittest .TestCase ):
@@ -887,15 +888,16 @@ def test_errors(self):
887
888
class TestModelCardGeneration (unittest .TestCase ):
888
889
def test_generate_outcome_average_interval (self ):
889
890
df = pd .DataFrame ({"input" : [3 , 2 , 1 ], "output" : [1 , 2 , 3 ]})
890
- assert (
891
- jf .generate_outcome_average (df , ["input" ], "prediction" ) ==
892
- {'eventAverage' : 2.0 }
893
- )
891
+ assert jf .generate_outcome_average (df , ["input" ], "prediction" ) == {
892
+ "eventAverage" : 2.0
893
+ }
894
894
895
895
def test_generate_outcome_average_classification (self ):
896
896
df = pd .DataFrame ({"input" : [3 , 2 ], "output" : [0 , 1 ]})
897
- event_percentage = jf .generate_outcome_average (df , ["input" ], "classification" , 1 )
898
- assert ('eventPercentage' in event_percentage )
897
+ event_percentage = jf .generate_outcome_average (
898
+ df , ["input" ], "classification" , 1
899
+ )
900
+ assert "eventPercentage" in event_percentage
899
901
900
902
def test_generate_outcome_average_interval_non_numeric_output (self ):
901
903
df = pd .DataFrame ({"input" : [3 , 2 , 1 ], "output" : ["one" , "two" , "three" ]})
@@ -912,47 +914,51 @@ class TestGetSelectionStatisticValue(unittest.TestCase):
912
914
"_GINI_" : 1 ,
913
915
"_C_" : 2 ,
914
916
"_TAU_" : None ,
915
- "_DataRole_" : "TRAIN"
917
+ "_DataRole_" : "TRAIN" ,
916
918
}
917
919
}
918
920
]
919
921
}
920
922
}
921
923
tmp_dir = tempfile .TemporaryDirectory ()
922
924
with open (Path (tmp_dir .name ) / "dmcas_fitstat.json" , "w+" ) as f :
923
- f .write (json .dumps (model_file_dict [' dmcas_fitstat.json' ]))
925
+ f .write (json .dumps (model_file_dict [" dmcas_fitstat.json" ]))
924
926
925
927
def test_get_statistic_dict_default (self ):
926
928
selection_statistic = jf .get_selection_statistic_value (self .model_file_dict )
927
- assert ( selection_statistic == 1 )
929
+ assert selection_statistic == 1
928
930
929
931
def test_get_statistic_dict_custom (self ):
930
- selection_statistic = jf .get_selection_statistic_value (self .model_file_dict , "_C_" )
931
- assert (selection_statistic == 2 )
932
+ selection_statistic = jf .get_selection_statistic_value (
933
+ self .model_file_dict , "_C_"
934
+ )
935
+ assert selection_statistic == 2
932
936
933
937
def test_get_blank_statistic_dict (self ):
934
938
with pytest .raises (RuntimeError ):
935
939
jf .get_selection_statistic_value (self .model_file_dict , "_TAU_" )
936
940
937
941
def test_get_statistics_path_default (self ):
938
942
selection_statistic = jf .get_selection_statistic_value (Path (self .tmp_dir .name ))
939
- assert ( selection_statistic == 1 )
943
+ assert selection_statistic == 1
940
944
941
945
def test_get_statistics_path_custom (self ):
942
- selection_statistic = jf .get_selection_statistic_value (Path (self .tmp_dir .name ), "_C_" )
943
- assert (selection_statistic == 2 )
946
+ selection_statistic = jf .get_selection_statistic_value (
947
+ Path (self .tmp_dir .name ), "_C_"
948
+ )
949
+ assert selection_statistic == 2
944
950
945
951
def test_get_blank_statistic_path (self ):
946
952
with pytest .raises (RuntimeError ):
947
953
jf .get_selection_statistic_value (Path (self .tmp_dir .name ), "_TAU_" )
948
954
949
955
def test_get_statistics_str_default (self ):
950
956
selection_statistic = jf .get_selection_statistic_value (self .tmp_dir .name )
951
- assert ( selection_statistic == 1 )
957
+ assert selection_statistic == 1
952
958
953
959
def test_get_statistics_str_custom (self ):
954
960
selection_statistic = jf .get_selection_statistic_value (self .tmp_dir .name , "_C_" )
955
- assert ( selection_statistic == 2 )
961
+ assert selection_statistic == 2
956
962
957
963
def test_get_blank_statistic_str (self ):
958
964
with pytest .raises (RuntimeError ):
@@ -961,69 +967,66 @@ def test_get_blank_statistic_str(self):
961
967
962
968
class TestUpdateModelProperties (unittest .TestCase ):
963
969
def setUp (self ):
964
- self .model_file_dict = {
965
- "ModelProperties.json" :
966
- {
967
- "example" : "property"
968
- }
969
- }
970
+ self .model_file_dict = {"ModelProperties.json" : {"example" : "property" }}
970
971
self .tmp_dir = tempfile .TemporaryDirectory ()
971
972
with open (Path (self .tmp_dir .name ) / "ModelProperties.json" , "w+" ) as f :
972
- f .write (json .dumps (self .model_file_dict [' ModelProperties.json' ]))
973
+ f .write (json .dumps (self .model_file_dict [" ModelProperties.json" ]))
973
974
974
975
def tearDown (self ):
975
976
self .tmp_dir .cleanup ()
976
977
977
978
def test_update_model_properties_dict (self ):
978
- update_dict = {' new' : ' arg' , ' newer' : ' thing' }
979
+ update_dict = {" new" : " arg" , " newer" : " thing" }
979
980
jf .update_model_properties (self .model_file_dict , update_dict )
980
- assert ( self .model_file_dict [' ModelProperties.json' ][ ' example' ] == ' property' )
981
- assert ( self .model_file_dict [' ModelProperties.json' ][ ' new' ] == ' arg' )
982
- assert ( self .model_file_dict [' ModelProperties.json' ][ ' newer' ] == ' thing' )
981
+ assert self .model_file_dict [" ModelProperties.json" ][ " example" ] == " property"
982
+ assert self .model_file_dict [" ModelProperties.json" ][ " new" ] == " arg"
983
+ assert self .model_file_dict [" ModelProperties.json" ][ " newer" ] == " thing"
983
984
984
985
def test_update_model_properties_dict_overwrite (self ):
985
- update_dict = {' new' : ' arg' , ' example' : ' thing' }
986
+ update_dict = {" new" : " arg" , " example" : " thing" }
986
987
jf .update_model_properties (self .model_file_dict , update_dict )
987
- assert ( self .model_file_dict [' ModelProperties.json' ][ ' example' ] == ' thing' )
988
- assert ( self .model_file_dict [' ModelProperties.json' ][ ' new' ] == ' arg' )
988
+ assert self .model_file_dict [" ModelProperties.json" ][ " example" ] == " thing"
989
+ assert self .model_file_dict [" ModelProperties.json" ][ " new" ] == " arg"
989
990
990
991
def test_update_model_properties_dict_number (self ):
991
992
update_dict = {"number" : 1 }
992
993
jf .update_model_properties (self .model_file_dict , update_dict )
993
- assert ( self .model_file_dict [' ModelProperties.json' ][ ' number' ] == '1' )
994
+ assert self .model_file_dict [" ModelProperties.json" ][ " number" ] == "1"
994
995
995
996
def test_update_model_properties_dict_round_number (self ):
996
- update_dict = {' number' : 0.123456789012345 }
997
+ update_dict = {" number" : 0.123456789012345 }
997
998
jf .update_model_properties (self .model_file_dict , update_dict )
998
- assert (self .model_file_dict ['ModelProperties.json' ]['number' ] == '0.12345678901234' )
999
+ assert (
1000
+ self .model_file_dict ["ModelProperties.json" ]["number" ] == "0.12345678901234"
1001
+ )
999
1002
1000
1003
def test_update_model_properties_str (self ):
1001
- update_dict = {' new' : ' arg' , ' newer' : ' thing' }
1004
+ update_dict = {" new" : " arg" , " newer" : " thing" }
1002
1005
jf .update_model_properties (self .tmp_dir .name , update_dict )
1003
- with open (Path (self .tmp_dir .name ) / ' ModelProperties.json' , 'r' ) as f :
1006
+ with open (Path (self .tmp_dir .name ) / " ModelProperties.json" , "r" ) as f :
1004
1007
model_properties = json .load (f )
1005
- assert ( model_properties [' example' ] == ' property' )
1006
- assert ( model_properties [' new' ] == ' arg' )
1007
- assert ( model_properties [' newer' ] == ' thing' )
1008
+ assert model_properties [" example" ] == " property"
1009
+ assert model_properties [" new" ] == " arg"
1010
+ assert model_properties [" newer" ] == " thing"
1008
1011
1009
1012
def test_update_model_properties_str_overwrite (self ):
1010
- update_dict = {' new' : ' arg' , ' example' : ' thing' }
1013
+ update_dict = {" new" : " arg" , " example" : " thing" }
1011
1014
jf .update_model_properties (self .tmp_dir .name , update_dict )
1012
- with open (Path (self .tmp_dir .name ) / ' ModelProperties.json' , 'r' ) as f :
1015
+ with open (Path (self .tmp_dir .name ) / " ModelProperties.json" , "r" ) as f :
1013
1016
model_properties = json .load (f )
1014
- assert ( model_properties [' example' ] == ' thing' )
1015
- assert ( model_properties [' new' ] == ' arg' )
1017
+ assert model_properties [" example" ] == " thing"
1018
+ assert model_properties [" new" ] == " arg"
1016
1019
1017
1020
def test_update_model_properties_str_number (self ):
1018
1021
update_dict = {"number" : 1 }
1019
1022
jf .update_model_properties (self .tmp_dir .name , update_dict )
1020
- with open (Path (self .tmp_dir .name ) / ' ModelProperties.json' , 'r' ) as f :
1023
+ with open (Path (self .tmp_dir .name ) / " ModelProperties.json" , "r" ) as f :
1021
1024
model_properties = json .load (f )
1022
- assert ( model_properties [' number' ] == '1' )
1025
+ assert model_properties [" number" ] == "1"
1023
1026
1024
1027
def test_update_model_properties_str_round_number (self ):
1025
- update_dict = {' number' : 0.123456789012345 }
1028
+ update_dict = {" number" : 0.123456789012345 }
1026
1029
jf .update_model_properties (self .tmp_dir .name , update_dict )
1027
- with open (Path (self .tmp_dir .name ) / ' ModelProperties.json' , 'r' ) as f :
1030
+ with open (Path (self .tmp_dir .name ) / " ModelProperties.json" , "r" ) as f :
1028
1031
model_properties = json .load (f )
1029
- assert ( model_properties [' number' ] == ' 0.12345678901234' )
1032
+ assert model_properties [" number" ] == " 0.12345678901234"
0 commit comments