python-patch icon indicating copy to clipboard operation
python-patch copied to clipboard

Unit test possibly checking for wrong value

Open JonathanHolvey opened this issue 7 years ago • 0 comments

While running the unit tests on a modified branch of Python Patch, I've been trying to debug some of the failed tests I'm seeing. The first of these, test_multiline_false_on_other_file() would appear to be working correctly with the master branch, and failing with my branch, however, by manually checking the test patch and target files, I believe that the wrong value is being checked for.

The test uses the method assertFalse() on the return value of can_patch(), which in turn calls _match_file_hunks(). The False value here is coming from _match_file_hunks() when checking hunk 1 of the patch 01uni_multi.patch aginst updatedlg.cpp.

This is the hunk in question:

@@ -94,11 +94,13 @@
     lst->InsertColumn(1, _("Version"));
     lst->InsertColumn(2, _("Installed"));
     lst->InsertColumn(3, _("Size"), wxLIST_FORMAT_RIGHT);
+    lst->InsertColumn(4, _("Rev"));
 
-    lst->SetColumnWidth(0, lst->GetSize().x - (64 * 3) - 2); // 1st column takes all remaining space
+    lst->SetColumnWidth(0, lst->GetSize().x - (64 * 3 + 40) - 6 ); // 1st column takes all remaining space
     lst->SetColumnWidth(1, 64);
     lst->SetColumnWidth(2, 64);
     lst->SetColumnWidth(3, 64);
+    lst->SetColumnWidth(4, 40);
 }
 
 void UpdateDlg::AddRecordToList(UpdateRec* rec)

and here is the relevant section of updatedlg.cpp, starting from line 94:

    lst->InsertColumn(1, _("Version"));
    lst->InsertColumn(2, _("Installed"));
    lst->InsertColumn(3, _("Size"), wxLIST_FORMAT_RIGHT);

    lst->SetColumnWidth(0, lst->GetSize().x - (64 * 3) - 2); // 1st column takes all remaining space
    lst->SetColumnWidth(1, 64);
    lst->SetColumnWidth(2, 64);
    lst->SetColumnWidth(3, 64);
}

void UpdateDlg::AddRecordToList(UpdateRec* rec)

Checking still deeper I found that when it fails, _match_file_hunks() is in fact making the following comparison, between line 97 of the target file and the fourth line of the patch hunk, rather than the fifth:

b'' != b'    lst->InsertColumn(4, _("Rev"));'

As far as I can tell, a bug somewhere in patch.py is causing an addition line in the patch to be compared with the target file, and the unit test checking for this has been set up incorrectly, since the patch seems to be valid for the files it modifies.

Can anyone throw some light on to what exactly test_multiline_false_on_other_file() is intended to check? Am I correct in my deductions above, or have I overlooked something?

JonathanHolvey avatar Dec 26 '16 08:12 JonathanHolvey