@@ -23,49 +23,53 @@ def test_read_in_features_without_flex():
2323 {"feature" : "gender" , "value" : "female" , "min" : "4" , "max" : "6" },
2424 {"feature" : "gender" , "value" : "non-binary-other" , "min" : "0" , "max" : "1" },
2525 ]
26- features = read_in_features (head , body )
26+ features , feature_column_name , feature_value_column_name = read_in_features (head , body )
2727 assert list (features .keys ()) == ["gender" ]
2828 assert sorted (features ["gender" ].keys ()) == ["female" , "male" , "non-binary-other" ]
2929 assert minimum_selection (features ) == 8
3030 assert maximum_selection (features ) == 13
31+ assert feature_column_name == "feature"
32+ assert feature_value_column_name == "value"
3133
3234
3335def test_read_in_features_with_flex ():
3436 """
3537 Test a basic import with a single feature/category
3638 """
37- head = FEATURE_FILE_FIELD_NAMES_FLEX
39+ head = FEATURE_FILE_FIELD_NAMES_FLEX_OLD
3840 body = [
3941 {
40- "feature " : "gender" ,
41- "value " : "male" ,
42+ "category " : "gender" ,
43+ "name " : "male" ,
4244 "min" : "4" ,
4345 "max" : "6" ,
4446 "min_flex" : "4" ,
4547 "max_flex" : "6" ,
4648 },
4749 {
48- "feature " : "gender" ,
49- "value " : "female" ,
50+ "category " : "gender" ,
51+ "name " : "female" ,
5052 "min" : "4" ,
5153 "max" : "6" ,
5254 "min_flex" : "4" ,
5355 "max_flex" : "6" ,
5456 },
5557 {
56- "feature " : "gender" ,
57- "value " : "non-binary-other" ,
58+ "category " : "gender" ,
59+ "name " : "non-binary-other" ,
5860 "min" : "0" ,
5961 "max" : "1" ,
6062 "min_flex" : "0" ,
6163 "max_flex" : "1" ,
6264 },
6365 ]
64- features = read_in_features (head , body )
66+ features , feature_column_name , feature_value_column_name = read_in_features (head , body )
6567 assert list (features .keys ()) == ["gender" ]
6668 assert sorted (features ["gender" ].keys ()) == ["female" , "male" , "non-binary-other" ]
6769 assert minimum_selection (features ) == 8
6870 assert maximum_selection (features ) == 13
71+ assert feature_column_name == "category"
72+ assert feature_value_column_name == "name"
6973
7074
7175def test_read_in_features_without_flex_old_names ():
@@ -78,7 +82,7 @@ def test_read_in_features_without_flex_old_names():
7882 {"category" : "gender" , "name" : "female" , "min" : "4" , "max" : "6" },
7983 {"category" : "gender" , "name" : "non-binary-other" , "min" : "0" , "max" : "1" },
8084 ]
81- features = read_in_features (head , body )
85+ features , _ , _ = read_in_features (head , body )
8286 assert list (features .keys ()) == ["gender" ]
8387 assert sorted (features ["gender" ].keys ()) == ["female" , "male" , "non-binary-other" ]
8488 assert minimum_selection (features ) == 8
@@ -116,7 +120,7 @@ def test_read_in_features_with_flex_old_names():
116120 "max_flex" : "1" ,
117121 },
118122 ]
119- features = read_in_features (head , body )
123+ features , _ , _ = read_in_features (head , body )
120124 assert list (features .keys ()) == ["gender" ]
121125 assert sorted (features ["gender" ].keys ()) == ["female" , "male" , "non-binary-other" ]
122126 assert minimum_selection (features ) == 8
@@ -136,7 +140,7 @@ def test_multiple_features_without_flex(self):
136140 {"feature" : "age" , "value" : "31-50" , "min" : "2" , "max" : "5" },
137141 {"feature" : "age" , "value" : "51+" , "min" : "1" , "max" : "2" },
138142 ]
139- features = read_in_features (head , body )
143+ features , _ , _ = read_in_features (head , body )
140144
141145 # Check we have both features
142146 assert sorted (features .keys ()) == ["age" , "gender" ]
@@ -189,7 +193,7 @@ def test_multiple_features_with_flex(self):
189193 "max_flex" : "5" ,
190194 },
191195 ]
192- features = read_in_features (head , body )
196+ features , _ , _ = read_in_features (head , body )
193197
194198 assert sorted (features .keys ()) == ["education" , "gender" ]
195199 assert minimum_selection (features ) == 4 # max(4, 3) = 4
@@ -226,7 +230,7 @@ def test_extra_headers_ignored(self):
226230 "suggest max" ,
227231 ] # extra "suggest min/max" headers
228232 body = [{"feature" : "gender" , "value" : "male" , "min" : "1" , "max" : "2" }]
229- features = read_in_features (head , body )
233+ features , _ , _ = read_in_features (head , body )
230234
231235 assert list (features .keys ()) == ["gender" ]
232236 assert list (features ["gender" ].keys ()) == ["male" ]
@@ -243,7 +247,7 @@ def test_blank_feature_name_skipped(self):
243247 }, # blank feature, should be skipped
244248 {"feature" : "gender" , "value" : "female" , "min" : "2" , "max" : "3" },
245249 ]
246- features = read_in_features (head , body )
250+ features , _ , _ = read_in_features (head , body )
247251
248252 assert list (features .keys ()) == ["gender" ]
249253 assert list (features ["gender" ].keys ()) == ["female" ]
@@ -441,7 +445,7 @@ def test_string_values_stripped(self):
441445 {"feature" : " gender " , "value" : " male " , "min" : "1" , "max" : "2" },
442446 {"feature" : "gender" , "value" : "female" , "min" : "2" , "max" : "3" },
443447 ]
444- features = read_in_features (head , body )
448+ features , _ , _ = read_in_features (head , body )
445449
446450 assert "gender" in features
447451 assert sorted (features ["gender" ].keys ()) == ["female" , "male" ]
@@ -453,7 +457,7 @@ def test_numeric_feature_names_and_values(self):
453457 {"feature" : 123 , "value" : 456 , "min" : "1" , "max" : "2" },
454458 {"feature" : 123 , "value" : 789 , "min" : "2" , "max" : "3" },
455459 ]
456- features = read_in_features (head , body )
460+ features , _ , _ = read_in_features (head , body )
457461
458462 assert "123" in features
459463 assert sorted (features ["123" ].keys ()) == ["456" , "789" ]
@@ -469,7 +473,7 @@ def test_old_column_names_without_flex(self):
469473 {"category" : "gender" , "name" : "male" , "min" : "1" , "max" : "2" },
470474 {"category" : "gender" , "name" : "female" , "min" : "2" , "max" : "3" },
471475 ]
472- features = read_in_features (head , body )
476+ features , _ , _ = read_in_features (head , body )
473477
474478 assert "gender" in features
475479 assert sorted (features ["gender" ].keys ()) == ["female" , "male" ]
@@ -495,7 +499,7 @@ def test_old_column_names_with_flex(self):
495499 "max_flex" : "4" ,
496500 },
497501 ]
498- features = read_in_features (head , body )
502+ features , _ , _ = read_in_features (head , body )
499503
500504 assert "gender" in features
501505 assert sorted (features ["gender" ].keys ()) == ["female" , "male" ]
@@ -547,7 +551,7 @@ def test_case_insensitive_features(self):
547551 {"feature" : "gender" , "value" : "Male" , "min" : "2" , "max" : "4" },
548552 {"feature" : "gender" , "value" : "Female" , "min" : "2" , "max" : "4" },
549553 ]
550- features = read_in_features (head , body )
554+ features , _ , _ = read_in_features (head , body )
551555
552556 # Should be able to access with different case
553557 assert "male" in features ["gender" ]
@@ -570,7 +574,7 @@ def test_case_insensitive_feature_values(self):
570574 {"feature" : "gender" , "value" : "Male" , "min" : "2" , "max" : "4" },
571575 {"feature" : "gender" , "value" : "Female" , "min" : "2" , "max" : "4" },
572576 ]
573- features = read_in_features (head , body )
577+ features , _ , _ = read_in_features (head , body )
574578
575579 # Should be able to access with different case
576580 assert "male" in features ["gender" ]
@@ -595,7 +599,7 @@ def test_case_insensitive_with_mixed_case_input(self):
595599 {"feature" : "ethnicity" , "value" : "White British" , "min" : "1" , "max" : "2" },
596600 {"feature" : "ETHNICITY" , "value" : "Asian" , "min" : "1" , "max" : "2" },
597601 ]
598- features = read_in_features (head , body )
602+ features , _ , _ = read_in_features (head , body )
599603
600604 # Check all variations work
601605 assert "male" in features ["gender" ]
0 commit comments