2121# * *
2222# ***************************************************************************
2323
24+ """ Test the Change Branch GUI code"""
25+
26+ # pylint: disable=wrong-import-position, deprecated-module, too-many-return-statements
27+
2428import sys
2529import unittest
2630from unittest .mock import patch , Mock , MagicMock
4549
4650
4751class MockFilter (QtCore .QSortFilterProxyModel ):
52+ """Replaces a filter with a non-filter that simply always returns whatever it's given"""
53+
4854 def mapToSource (self , something ):
4955 return something
5056
5157
5258class MockChangeBranchDialogModel (QtCore .QAbstractTableModel ):
59+ """Replace a data-connected model with a static one for testing"""
5360
5461 branches = [
5562 {"ref_name" : "ref1" , "upstream" : "us1" },
@@ -64,16 +71,20 @@ def __init__(self, _: str, parent=None) -> None:
6471 super ().__init__ (parent )
6572
6673 def rowCount (self , parent : QtCore .QModelIndex = QtCore .QModelIndex ()) -> int :
74+ """Number of rows: should always return 3"""
6775 if parent .isValid ():
6876 return 0
6977 return len (self .branches )
7078
7179 def columnCount (self , parent : QtCore .QModelIndex = QtCore .QModelIndex ()) -> int :
80+ """Number of columns (identical to non-mocked version)"""
7281 if parent .isValid ():
7382 return 0
7483 return 3 # Local name, remote name, date
7584
7685 def data (self , index : QtCore .QModelIndex , role : int = QtCore .Qt .DisplayRole ):
86+ """Mock returns static untranslated strings for DisplayRole, no tooltips at all, and otherwise matches
87+ the non-mock version"""
7788 if not index .isValid ():
7889 return None
7990 row = index .row ()
@@ -98,6 +109,7 @@ def headerData(
98109 orientation : QtCore .Qt .Orientation ,
99110 role : int = QtCore .Qt .DisplayRole ,
100111 ):
112+ """Mock returns untranslated strings for DisplayRole, and no tooltips at all"""
101113 if orientation == QtCore .Qt .Vertical :
102114 return None
103115 if role != QtCore .Qt .DisplayRole :
@@ -106,12 +118,13 @@ def headerData(
106118 return "Local"
107119 if section == 1 :
108120 return "Remote tracking"
109- elif section == 2 :
121+ if section == 2 :
110122 return "Last Updated"
111- else :
112- return None
123+ return None
113124
114125 def currentBranch (self ) -> str :
126+ """Mock returns a static string stored in the class: that string could be modified to return something else
127+ by tests that require it."""
115128 return self .current_branch
116129
117130
0 commit comments