Skip to content

Commit

Permalink
Use assertIsInstance instead of assertTrue(isinstance())
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 0340320 commit 2f0f6a9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
44 changes: 22 additions & 22 deletions python/plugins/processing/tests/ParametersTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def testScriptCode(self):
parameter = ParameterBoolean('myName', 'myDescription')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterBoolean))
self.assertIsInstance(result, ParameterBoolean)
self.assertFalse(result.optional)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterBoolean))
self.assertIsInstance(result, ParameterBoolean)
self.assertTrue(result.optional)


Expand Down Expand Up @@ -138,12 +138,12 @@ def testScriptCode(self):
parameter = ParameterCrs('myName', 'myDescription')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterCrs))
self.assertIsInstance(result, ParameterCrs)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterCrs))
self.assertIsInstance(result, ParameterCrs)
self.assertTrue(result.optional)


Expand Down Expand Up @@ -192,12 +192,12 @@ def testScriptCode(self):
parameter = ParameterExtent('myName', 'myDescription')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterExtent))
self.assertIsInstance(result, ParameterExtent)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterExtent))
self.assertIsInstance(result, ParameterExtent)
self.assertTrue(result.optional)


Expand Down Expand Up @@ -234,12 +234,12 @@ def testScriptCode(self):
parameter = ParameterPoint('myName', 'myDescription')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterPoint))
self.assertIsInstance(result, ParameterPoint)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterPoint))
self.assertIsInstance(result, ParameterPoint)
self.assertTrue(result.optional)


Expand Down Expand Up @@ -354,12 +354,12 @@ def testScriptCode(self):
parameter = ParameterFile('myName', 'myDescription')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterFile))
self.assertIsInstance(result, ParameterFile)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterFile))
self.assertIsInstance(result, ParameterFile)
self.assertTrue(result.optional)


Expand Down Expand Up @@ -476,12 +476,12 @@ def testScriptCode(self):
parameter = ParameterMultipleInput('myName', 'myDescription')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterMultipleInput))
self.assertIsInstance(result, ParameterMultipleInput)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterMultipleInput))
self.assertIsInstance(result, ParameterMultipleInput)
self.assertTrue(result.optional)


Expand Down Expand Up @@ -542,12 +542,12 @@ def testScriptCode(self):
parameter = ParameterNumber('myName', 'myDescription')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterNumber))
self.assertIsInstance(result, ParameterNumber)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterNumber))
self.assertIsInstance(result, ParameterNumber)
self.assertTrue(result.optional)


Expand Down Expand Up @@ -577,12 +577,12 @@ def testScriptCode(self):
parameter = ParameterString('myName', 'myDescription', default='test')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterString))
self.assertIsInstance(result, ParameterString)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterString))
self.assertIsInstance(result, ParameterString)
self.assertTrue(result.optional)


Expand Down Expand Up @@ -612,12 +612,12 @@ def testScriptCode(self):
parameter = ParameterExpression('myName', 'myDescription', default='test')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterExpression))
self.assertIsInstance(result, ParameterExpression)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterExpression))
self.assertIsInstance(result, ParameterExpression)
self.assertTrue(result.optional)


Expand All @@ -640,12 +640,12 @@ def testScriptCode(self):
'myName', 'myDesc', parent_name)
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterTableField))
self.assertIsInstance(result, ParameterTableField)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterTableField))
self.assertIsInstance(result, ParameterTableField)
self.assertTrue(result.optional)


Expand All @@ -656,12 +656,12 @@ def testScriptCode(self):
'myName', 'myDesc')
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterTable))
self.assertIsInstance(result, ParameterTable)

parameter.optional = True
code = parameter.getAsScriptCode()
result = getParameterFromString(code)
self.assertTrue(isinstance(result, ParameterTable))
self.assertIsInstance(result, ParameterTable)
self.assertTrue(result.optional)

if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_provider_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ def testDateTimeTypes(self):
f = next(vl.getFeatures(QgsFeatureRequest()))

date_idx = vl.fields().lookupField('date_field')
self.assertTrue(isinstance(f.attributes()[date_idx], QDate))
self.assertIsInstance(f.attributes()[date_idx], QDate)
self.assertEqual(f.attributes()[date_idx], QDate(2004, 3, 4))
datetime_idx = vl.fields().lookupField('datetime_field')
self.assertTrue(isinstance(f.attributes()[datetime_idx], QDateTime))
self.assertIsInstance(f.attributes()[datetime_idx], QDateTime)
self.assertEqual(f.attributes()[datetime_idx], QDateTime(
QDate(2004, 3, 4), QTime(13, 41, 52)))

Expand Down
16 changes: 8 additions & 8 deletions tests/src/python/test_provider_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def partiallyCompiledFilters(self):
# HERE GO THE PROVIDER SPECIFIC TESTS
def testDefaultValue(self):
self.provider.setProviderProperty(QgsDataProvider.EvaluateDefaultValues, True)
self.assertTrue(isinstance(self.provider.defaultValue(0), int))
self.assertIsInstance(self.provider.defaultValue(0), int)
self.assertEqual(self.provider.defaultValue(1), NULL)
self.assertEqual(self.provider.defaultValue(2), 'qgis')
self.provider.setProviderProperty(QgsDataProvider.EvaluateDefaultValues, False)
Expand All @@ -110,13 +110,13 @@ def testDateTimeTypes(self):
f = next(vl.getFeatures(QgsFeatureRequest()))

date_idx = vl.fields().lookupField('date_field')
self.assertTrue(isinstance(f.attributes()[date_idx], QDate))
self.assertIsInstance(f.attributes()[date_idx], QDate)
self.assertEqual(f.attributes()[date_idx], QDate(2004, 3, 4))
time_idx = vl.fields().lookupField('time_field')
self.assertTrue(isinstance(f.attributes()[time_idx], QTime))
self.assertIsInstance(f.attributes()[time_idx], QTime)
self.assertEqual(f.attributes()[time_idx], QTime(13, 41, 52))
datetime_idx = vl.fields().lookupField('datetime_field')
self.assertTrue(isinstance(f.attributes()[datetime_idx], QDateTime))
self.assertIsInstance(f.attributes()[datetime_idx], QDateTime)
self.assertEqual(f.attributes()[datetime_idx], QDateTime(QDate(2004, 3, 4), QTime(13, 41, 52)))

def testQueryLayers(self):
Expand Down Expand Up @@ -370,7 +370,7 @@ def testHstore(self):
f = next(vl.getFeatures(QgsFeatureRequest()))

value_idx = vl.fields().lookupField('value')
self.assertTrue(isinstance(f.attributes()[value_idx], dict))
self.assertIsInstance(f.attributes()[value_idx], dict)
self.assertEqual(f.attributes()[value_idx], {'a': 'b', '1': '2'})

new_f = QgsFeature(vl.fields())
Expand Down Expand Up @@ -401,7 +401,7 @@ def testStringArray(self):
f = next(vl.getFeatures(QgsFeatureRequest()))

value_idx = vl.fields().lookupField('value')
self.assertTrue(isinstance(f.attributes()[value_idx], list))
self.assertIsInstance(f.attributes()[value_idx], list)
self.assertEqual(f.attributes()[value_idx], ['a', 'b', 'c'])

new_f = QgsFeature(vl.fields())
Expand Down Expand Up @@ -432,7 +432,7 @@ def testIntArray(self):
f = next(vl.getFeatures(QgsFeatureRequest()))

value_idx = vl.fields().lookupField('value')
self.assertTrue(isinstance(f.attributes()[value_idx], list))
self.assertIsInstance(f.attributes()[value_idx], list)
self.assertEqual(f.attributes()[value_idx], [1, 2, -5])

def testDoubleArray(self):
Expand All @@ -446,7 +446,7 @@ def testDoubleArray(self):
f = next(vl.getFeatures(QgsFeatureRequest()))

value_idx = vl.fields().lookupField('value')
self.assertTrue(isinstance(f.attributes()[value_idx], list))
self.assertIsInstance(f.attributes()[value_idx], list)
self.assertEqual(f.attributes()[value_idx], [1.1, 2, -5.12345])

def testNotNullConstraint(self):
Expand Down

0 comments on commit 2f0f6a9

Please sign in to comment.