1919runner = CliRunner ()
2020
2121
22+ # ----- Tests for validate() function -----
2223def test_validate_valid_task_number (gt_file , pred_file ):
23- """Check that the return type for validate() is a list, filter, or tuple."""
24+ """
25+ Test: validate() returns a list, filter, or tuple for valid
26+ task number.
27+ """
2428 task_number = 1
2529 errors = validate (
2630 task_number = task_number ,
@@ -31,7 +35,7 @@ def test_validate_valid_task_number(gt_file, pred_file):
3135
3236
3337def test_validate_invalid_task_number ():
34- """Check that error message about invalid task number is returned in the list of error messages ."""
38+ """Test: validate() notifies about invalid task number."""
3539 task_number = 99999
3640 errors = validate (
3741 task_number = task_number ,
@@ -41,42 +45,13 @@ def test_validate_invalid_task_number():
4145 assert f"Invalid challenge task number specified: `{ task_number } `" in errors
4246
4347
44- @patch ("validate.extract_gt_file" )
45- @patch ("validate.validate" )
46- def test_main_invalid_submission_type (
47- mock_validate , mock_extract_gt_file , groundtruth_dir , temp_dir
48- ):
49- invalid_file = os .path .join (temp_dir , "INVALID_predictions.txt" )
50- with open (invalid_file , "w" ) as f :
51- f .write ("foo" )
52- output_file = os .path .join (temp_dir , "results.json" )
53- result = runner .invoke (
54- app ,
55- [
56- "-p" ,
57- invalid_file ,
58- "-g" ,
59- groundtruth_dir ,
60- "-t" ,
61- "1" ,
62- "-o" ,
63- output_file ,
64- ],
65- )
66- assert result .exit_code == 0
67- assert result .stdout .strip () == "INVALID"
68- with open (output_file , "r" ) as f :
69- output_data = json .load (f )
70- assert output_data ["validation_status" ] == "INVALID"
71- mock_extract_gt_file .assert_not_called ()
72- mock_validate .assert_not_called ()
73-
74-
48+ # ----- Tests for main() function -----
7549@patch ("validate.extract_gt_file" )
7650@patch ("validate.validate" )
7751def test_main_valid_submission_type (
7852 mock_validate , mock_extract_gt_file , gt_file , pred_file , temp_dir
7953):
54+ """Test: final results should be INVALID or VALIDATED."""
8055 mock_extract_gt_file .return_value = gt_file
8156 mock_validate .return_value = []
8257 groundtruth_dir = os .path .dirname (gt_file )
@@ -111,26 +86,56 @@ def test_main_valid_submission_type(
11186 assert output_data ["validation_status" ] == "INVALID"
11287 assert not output_data ["validation_errors" ]
11388
114- print (mock_extract_gt_file .mock_calls )
115- print (mock_validate .mock_calls )
116-
11789 mock_extract_gt_file .assert_called_once_with (groundtruth_dir )
11890 mock_validate .assert_called_once_with (
11991 task_number = 1 , gt_file = gt_file , pred_file = pred_file
12092 )
12193
12294
95+ @patch ("validate.extract_gt_file" )
96+ @patch ("validate.validate" )
97+ def test_main_invalid_submission_type (
98+ mock_validate , mock_extract_gt_file , groundtruth_dir , temp_dir
99+ ):
100+ """Test: final results should be INVALID for incorrect submission type."""
101+ invalid_file = os .path .join (temp_dir , "INVALID_predictions.txt" )
102+ with open (invalid_file , "w" ) as f :
103+ f .write ("foo" )
104+ output_file = os .path .join (temp_dir , "results.json" )
105+ result = runner .invoke (
106+ app ,
107+ [
108+ "-p" ,
109+ invalid_file ,
110+ "-g" ,
111+ groundtruth_dir ,
112+ "-t" ,
113+ "1" ,
114+ "-o" ,
115+ output_file ,
116+ ],
117+ )
118+ assert result .exit_code == 0
119+ assert result .stdout .strip () == "INVALID"
120+ with open (output_file , "r" ) as f :
121+ output_data = json .load (f )
122+ assert output_data ["validation_status" ] == "INVALID"
123+ mock_extract_gt_file .assert_not_called ()
124+ mock_validate .assert_not_called ()
125+
126+
123127@patch ("validate.extract_gt_file" )
124128@patch ("validate.validate" )
125129def test_main_long_error_message (
126130 mock_validate , mock_extract_gt_file , gt_file , pred_file , temp_dir
127131):
132+ """Test: validation errors should never exceed 500 characters."""
128133 mock_extract_gt_file .return_value = gt_file
129134
130135 # Create a dummy string longer than 500 characters.
131136 long_error_message = "foo" * 500
132137 mock_validate .return_value = [long_error_message ]
133-
138+
134139 groundtruth_dir = os .path .dirname (gt_file )
135140 output_file = os .path .join (temp_dir , "results.json" )
136141
0 commit comments