Skip to content
Permalink
Browse files

Use assertIsInstance instead of assertTrue(isinstance())

  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 0340320 commit 2f0f6a98c6e56a5706e7814688acbe87917fe963
@@ -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)


@@ -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)


@@ -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)


@@ -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)


@@ -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)


@@ -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)


@@ -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)


@@ -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)


@@ -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)


@@ -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)


@@ -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__':
@@ -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)))

@@ -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)
@@ -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):
@@ -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())
@@ -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())
@@ -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):
@@ -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):

0 comments on commit 2f0f6a9

Please sign in to comment.
You can’t perform that action at this time.