4646 {"name" : "REASON_HomeImp" , "type" : "integer" },
4747]
4848
49+
4950class BadModel :
5051 attr = None
5152
53+
5254@pytest .fixture
5355def bad_model ():
5456 return BadModel ()
@@ -78,6 +80,7 @@ def sklearn_model(train_data):
7880 model .fit (X , y )
7981 return model
8082
83+
8184@pytest .fixture
8285def change_dir ():
8386 """Change working directory for the duration of the test."""
@@ -711,9 +714,7 @@ def test_create_requirements_json(change_dir):
711714 },
712715 ]
713716 unittest .TestCase .maxDiff = None
714- unittest .TestCase ().assertCountEqual (
715- json_dict , expected
716- )
717+ unittest .TestCase ().assertCountEqual (json_dict , expected )
717718
718719
719720class TestAssessBiasHelpers (unittest .TestCase ):
@@ -887,15 +888,16 @@ def test_errors(self):
887888class TestModelCardGeneration (unittest .TestCase ):
888889 def test_generate_outcome_average_interval (self ):
889890 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+ }
894894
895895 def test_generate_outcome_average_classification (self ):
896896 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
899901
900902 def test_generate_outcome_average_interval_non_numeric_output (self ):
901903 df = pd .DataFrame ({"input" : [3 , 2 , 1 ], "output" : ["one" , "two" , "three" ]})
@@ -912,47 +914,51 @@ class TestGetSelectionStatisticValue(unittest.TestCase):
912914 "_GINI_" : 1 ,
913915 "_C_" : 2 ,
914916 "_TAU_" : None ,
915- "_DataRole_" : "TRAIN"
917+ "_DataRole_" : "TRAIN" ,
916918 }
917919 }
918920 ]
919921 }
920922 }
921923 tmp_dir = tempfile .TemporaryDirectory ()
922924 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" ]))
924926
925927 def test_get_statistic_dict_default (self ):
926928 selection_statistic = jf .get_selection_statistic_value (self .model_file_dict )
927- assert ( selection_statistic == 1 )
929+ assert selection_statistic == 1
928930
929931 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
932936
933937 def test_get_blank_statistic_dict (self ):
934938 with pytest .raises (RuntimeError ):
935939 jf .get_selection_statistic_value (self .model_file_dict , "_TAU_" )
936940
937941 def test_get_statistics_path_default (self ):
938942 selection_statistic = jf .get_selection_statistic_value (Path (self .tmp_dir .name ))
939- assert ( selection_statistic == 1 )
943+ assert selection_statistic == 1
940944
941945 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
944950
945951 def test_get_blank_statistic_path (self ):
946952 with pytest .raises (RuntimeError ):
947953 jf .get_selection_statistic_value (Path (self .tmp_dir .name ), "_TAU_" )
948954
949955 def test_get_statistics_str_default (self ):
950956 selection_statistic = jf .get_selection_statistic_value (self .tmp_dir .name )
951- assert ( selection_statistic == 1 )
957+ assert selection_statistic == 1
952958
953959 def test_get_statistics_str_custom (self ):
954960 selection_statistic = jf .get_selection_statistic_value (self .tmp_dir .name , "_C_" )
955- assert ( selection_statistic == 2 )
961+ assert selection_statistic == 2
956962
957963 def test_get_blank_statistic_str (self ):
958964 with pytest .raises (RuntimeError ):
@@ -961,69 +967,66 @@ def test_get_blank_statistic_str(self):
961967
962968class TestUpdateModelProperties (unittest .TestCase ):
963969 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" }}
970971 self .tmp_dir = tempfile .TemporaryDirectory ()
971972 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" ]))
973974
974975 def tearDown (self ):
975976 self .tmp_dir .cleanup ()
976977
977978 def test_update_model_properties_dict (self ):
978- update_dict = {' new' : ' arg' , ' newer' : ' thing' }
979+ update_dict = {" new" : " arg" , " newer" : " thing" }
979980 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"
983984
984985 def test_update_model_properties_dict_overwrite (self ):
985- update_dict = {' new' : ' arg' , ' example' : ' thing' }
986+ update_dict = {" new" : " arg" , " example" : " thing" }
986987 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"
989990
990991 def test_update_model_properties_dict_number (self ):
991992 update_dict = {"number" : 1 }
992993 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"
994995
995996 def test_update_model_properties_dict_round_number (self ):
996- update_dict = {' number' : 0.123456789012345 }
997+ update_dict = {" number" : 0.123456789012345 }
997998 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+ )
9991002
10001003 def test_update_model_properties_str (self ):
1001- update_dict = {' new' : ' arg' , ' newer' : ' thing' }
1004+ update_dict = {" new" : " arg" , " newer" : " thing" }
10021005 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 :
10041007 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"
10081011
10091012 def test_update_model_properties_str_overwrite (self ):
1010- update_dict = {' new' : ' arg' , ' example' : ' thing' }
1013+ update_dict = {" new" : " arg" , " example" : " thing" }
10111014 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 :
10131016 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"
10161019
10171020 def test_update_model_properties_str_number (self ):
10181021 update_dict = {"number" : 1 }
10191022 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 :
10211024 model_properties = json .load (f )
1022- assert ( model_properties [' number' ] == '1' )
1025+ assert model_properties [" number" ] == "1"
10231026
10241027 def test_update_model_properties_str_round_number (self ):
1025- update_dict = {' number' : 0.123456789012345 }
1028+ update_dict = {" number" : 0.123456789012345 }
10261029 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 :
10281031 model_properties = json .load (f )
1029- assert ( model_properties [' number' ] == ' 0.12345678901234' )
1032+ assert model_properties [" number" ] == " 0.12345678901234"
0 commit comments