Squish: Introduce helper function for checking for strings

In Python3 type unicode is unavailable since it's implicit with "str".
The new functions helps porting code.

Change-Id: I5de0fa182acbbaf267ed51f66f658cb9c884f4c5
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Robert Löhning
2021-10-29 14:38:35 +02:00
parent 4980f71dd5
commit 7a8ca55f77
5 changed files with 23 additions and 16 deletions

View File

@@ -37,7 +37,7 @@ def placeCursorToLine(editor, line, isRegex=False):
return waitForObject(editor) return waitForObject(editor)
isDarwin = platform.system() == 'Darwin' isDarwin = platform.system() == 'Darwin'
if not isinstance(editor, (str, unicode)): if not isString(editor):
editor = objectMap.realName(editor) editor = objectMap.realName(editor)
oldPosition = 0 oldPosition = 0
jumpToFirstLine(getEditor()) jumpToFirstLine(getEditor())
@@ -120,7 +120,7 @@ def replaceEditorContent(editor, newcontent):
type(editor, newcontent) type(editor, newcontent)
def typeLines(editor, lines): def typeLines(editor, lines):
if isinstance(lines, (str, unicode)): if isString(lines):
lines = [lines] lines = [lines]
if isinstance(lines, (list, tuple)): if isinstance(lines, (list, tuple)):
for line in lines: for line in lines:

View File

@@ -35,10 +35,10 @@ def changeFilePermissions(dirPath, readPerm, writePerm, excludeFileNames=None):
permission |= stat.S_IWRITE permission |= stat.S_IWRITE
if excludeFileNames == None: if excludeFileNames == None:
excludeFileNames = [] excludeFileNames = []
elif isinstance(excludeFileNames, (str, unicode)): elif isString(excludeFileNames):
excludeFileNames = [excludeFileNames] excludeFileNames = [excludeFileNames]
if not isinstance(excludeFileNames, (tuple, list)): if not isinstance(excludeFileNames, (tuple, list)):
test.warning("File names to exclude must be of type str, unicode, list, tuple or None - " test.warning("File names to exclude must be of type str, list, tuple or None - "
"ignoring parameter this time.") "ignoring parameter this time.")
excludeFileNames = [] excludeFileNames = []
if not os.path.isdir(dirPath): if not os.path.isdir(dirPath):

View File

@@ -95,8 +95,8 @@ def setRunInTerminal(wantedKit, runInTerminal=True):
switchViewTo(ViewConstants.EDIT) switchViewTo(ViewConstants.EDIT)
def __getTargetFromToolTip__(toolTip): def __getTargetFromToolTip__(toolTip):
if toolTip == None or not isinstance(toolTip, (str, unicode)): if toolTip == None or not isString(toolTip):
test.warning("Parameter toolTip must be of type str or unicode and can't be None!") test.warning("Parameter toolTip must be of type str and can't be None!")
return None return None
pattern = re.compile(".*<b>Kit:</b>(.*)<b>Deploy.*") pattern = re.compile(".*<b>Kit:</b>(.*)<b>Deploy.*")
target = pattern.match(toolTip) target = pattern.match(toolTip)
@@ -108,7 +108,7 @@ def __getTargetFromToolTip__(toolTip):
def getExecutableAndTargetFromToolTip(toolTip): def getExecutableAndTargetFromToolTip(toolTip):
target = __getTargetFromToolTip__(toolTip) target = __getTargetFromToolTip__(toolTip)
if toolTip == None or not isinstance(toolTip, (str, unicode)): if toolTip == None or not isString(toolTip):
return None, target return None, target
pattern = re.compile('.*<b>Run:</b>(.*)</.*') pattern = re.compile('.*<b>Run:</b>(.*)</.*')
exe = pattern.match(toolTip) exe = pattern.match(toolTip)

View File

@@ -76,7 +76,7 @@ def ensureChecked(objectName, shouldBeChecked = True, timeout=20000):
# or the object itself. If it is an object, it must exist already. # or the object itself. If it is an object, it must exist already.
# param expectedState is the expected enable state of the object # param expectedState is the expected enable state of the object
def verifyEnabled(objectSpec, expectedState = True): def verifyEnabled(objectSpec, expectedState = True):
if isinstance(objectSpec, (str, unicode)): if isString(objectSpec):
waitFor("object.exists('" + str(objectSpec).replace("'", "\\'") + "')", 20000) waitFor("object.exists('" + str(objectSpec).replace("'", "\\'") + "')", 20000)
foundObject = findObject(objectSpec) foundObject = findObject(objectSpec)
else: else:
@@ -154,7 +154,7 @@ def which(program):
def cleanUpUserFiles(pathsToProFiles=None): def cleanUpUserFiles(pathsToProFiles=None):
if pathsToProFiles==None: if pathsToProFiles==None:
return False return False
if isinstance(pathsToProFiles, (str, unicode)): if isString(pathsToProFiles):
filelist = glob.glob(pathsToProFiles+".user*") filelist = glob.glob(pathsToProFiles+".user*")
elif isinstance(pathsToProFiles, (list, tuple)): elif isinstance(pathsToProFiles, (list, tuple)):
filelist = [] filelist = []
@@ -398,10 +398,10 @@ def enabledCheckBoxExists(text):
# this function verifies if the text matches the given # this function verifies if the text matches the given
# regex inside expectedTexts # regex inside expectedTexts
# param text must be a single str/unicode # param text must be a single str
# param expectedTexts can be str/unicode/list/tuple # param expectedTexts can be str/list/tuple
def regexVerify(text, expectedTexts): def regexVerify(text, expectedTexts):
if isinstance(expectedTexts, (str,unicode)): if isString(expectedTexts):
expectedTexts = [expectedTexts] expectedTexts = [expectedTexts]
for curr in expectedTexts: for curr in expectedTexts:
pattern = re.compile(curr) pattern = re.compile(curr)
@@ -453,7 +453,7 @@ def iterateQtVersions(keepOptionsOpen=False, alreadyOnOptionsDialog=False,
result.append({target:version}) result.append({target:version})
if additionalFunction: if additionalFunction:
try: try:
if isinstance(additionalFunction, (str, unicode)): if isString(additionalFunction):
currResult = globals()[additionalFunction](target, version, *argsForAdditionalFunc) currResult = globals()[additionalFunction](target, version, *argsForAdditionalFunc)
else: else:
currResult = additionalFunction(target, version, *argsForAdditionalFunc) currResult = additionalFunction(target, version, *argsForAdditionalFunc)
@@ -514,7 +514,7 @@ def iterateKits(keepOptionsOpen=False, alreadyOnOptionsDialog=False,
currentItem.replace(".", "\\.")]) currentItem.replace(".", "\\.")])
if additionalFunction: if additionalFunction:
try: try:
if isinstance(additionalFunction, (str, unicode)): if isString(additionalFunction):
currResult = globals()[additionalFunction](item, kitName, *argsForAdditionalFunc) currResult = globals()[additionalFunction](item, kitName, *argsForAdditionalFunc)
else: else:
currResult = additionalFunction(item, kitName, *argsForAdditionalFunc) currResult = additionalFunction(item, kitName, *argsForAdditionalFunc)
@@ -674,3 +674,10 @@ def getHelpViewer():
def getHelpTitle(): def getHelpTitle():
return str(getHelpViewer().title()) return str(getHelpViewer().title())
def isString(sth):
if sys.version_info.major > 2:
return isinstance(sth, str)
else:
return isinstance(sth, (str, unicode))

View File

@@ -306,7 +306,7 @@ def __compareCompilers__(foundCompilers, expectedCompilers):
if isinstance(currentFound, dict): if isinstance(currentFound, dict):
foundExp = False foundExp = False
for currentExp in expectedCompilers: for currentExp in expectedCompilers:
if isinstance(currentExp, (str, unicode)): if isString(currentExp):
continue continue
key = currentExp.keys()[0] key = currentExp.keys()[0]
# special case for (fuzzy) regex comparison on Windows (internal LLVM) # special case for (fuzzy) regex comparison on Windows (internal LLVM)
@@ -353,7 +353,7 @@ def __compareDebuggers__(foundDebuggers, expectedDebuggers):
def __lowerStrs__(iterable): def __lowerStrs__(iterable):
for it in iterable: for it in iterable:
if isinstance(it, (str, unicode)): if isString(it):
yield it.lower() yield it.lower()
else: else:
yield it yield it