Skip to content

Commit de2550f

Browse files
committedMay 14, 2020
Test updates
1 parent c83cf0e commit de2550f

File tree

1 file changed

+51
-36
lines changed

1 file changed

+51
-36
lines changed
 

‎tests/src/python/test_qgsvectorlayer.py

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import tempfile
1717
import shutil
1818

19-
from qgis.PyQt.QtCore import QDate, QDateTime, QVariant, Qt
19+
from qgis.PyQt.QtCore import QDate, QDateTime, QVariant, Qt, QDateTime, QDate, QTime
2020
from qgis.PyQt.QtGui import QPainter, QColor
2121
from qgis.PyQt.QtXml import QDomDocument
2222

@@ -211,27 +211,27 @@ class TestQgsVectorLayer(unittest.TestCase, FeatureSourceTestCase):
211211
@classmethod
212212
def getSource(cls):
213213
vl = QgsVectorLayer(
214-
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
214+
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time&key=pk',
215215
'test', 'memory')
216216
assert (vl.isValid())
217217

218218
f1 = QgsFeature()
219-
f1.setAttributes([5, -200, NULL, 'NuLl', '5'])
219+
f1.setAttributes([5, -200, NULL, 'NuLl', '5', QDateTime(QDate(2020, 5, 4), QTime(12, 13, 14)), QDate(2020, 5, 2), QTime(12, 13, 1)])
220220
f1.setGeometry(QgsGeometry.fromWkt('Point (-71.123 78.23)'))
221221

222222
f2 = QgsFeature()
223-
f2.setAttributes([3, 300, 'Pear', 'PEaR', '3'])
223+
f2.setAttributes([3, 300, 'Pear', 'PEaR', '3', NULL, NULL, NULL])
224224

225225
f3 = QgsFeature()
226-
f3.setAttributes([1, 100, 'Orange', 'oranGe', '1'])
226+
f3.setAttributes([1, 100, 'Orange', 'oranGe', '1', QDateTime(QDate(2020, 5, 3), QTime(12, 13, 14)), QDate(2020, 5, 3), QTime(12, 13, 14)])
227227
f3.setGeometry(QgsGeometry.fromWkt('Point (-70.332 66.33)'))
228228

229229
f4 = QgsFeature()
230-
f4.setAttributes([2, 200, 'Apple', 'Apple', '2'])
230+
f4.setAttributes([2, 200, 'Apple', 'Apple', '2', QDateTime(QDate(2020, 5, 4), QTime(12, 14, 14)), QDate(2020, 5, 4), QTime(12, 14, 14)])
231231
f4.setGeometry(QgsGeometry.fromWkt('Point (-68.2 70.8)'))
232232

233233
f5 = QgsFeature()
234-
f5.setAttributes([4, 400, 'Honey', 'Honey', '4'])
234+
f5.setAttributes([4, 400, 'Honey', 'Honey', '4', QDateTime(QDate(2021, 5, 4), QTime(13, 13, 14)), QDate(2021, 5, 4), QTime(13, 13, 14)])
235235
f5.setGeometry(QgsGeometry.fromWkt('Point (-65.32 78.3)'))
236236

237237
vl.dataProvider().addFeatures([f1, f2, f3, f4, f5])
@@ -3058,27 +3058,27 @@ class TestQgsVectorLayerSourceAddedFeaturesInBuffer(unittest.TestCase, FeatureSo
30583058
@classmethod
30593059
def getSource(cls):
30603060
vl = QgsVectorLayer(
3061-
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
3061+
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time&key=pk',
30623062
'test', 'memory')
30633063
assert (vl.isValid())
30643064

30653065
f1 = QgsFeature()
3066-
f1.setAttributes([5, -200, NULL, 'NuLl', '5'])
3066+
f1.setAttributes([5, -200, NULL, 'NuLl', '5', QDateTime(QDate(2020, 5, 4), QTime(12, 13, 14)), QDate(2020, 5, 2), QTime(12, 13, 1)])
30673067
f1.setGeometry(QgsGeometry.fromWkt('Point (-71.123 78.23)'))
30683068

30693069
f2 = QgsFeature()
3070-
f2.setAttributes([3, 300, 'Pear', 'PEaR', '3'])
3070+
f2.setAttributes([3, 300, 'Pear', 'PEaR', '3', NULL, NULL, NULL])
30713071

30723072
f3 = QgsFeature()
3073-
f3.setAttributes([1, 100, 'Orange', 'oranGe', '1'])
3073+
f3.setAttributes([1, 100, 'Orange', 'oranGe', '1', QDateTime(QDate(2020, 5, 3), QTime(12, 13, 14)), QDate(2020, 5, 3), QTime(12, 13, 14)])
30743074
f3.setGeometry(QgsGeometry.fromWkt('Point (-70.332 66.33)'))
30753075

30763076
f4 = QgsFeature()
3077-
f4.setAttributes([2, 200, 'Apple', 'Apple', '2'])
3077+
f4.setAttributes([2, 200, 'Apple', 'Apple', '2', QDateTime(QDate(2020, 5, 4), QTime(12, 14, 14)), QDate(2020, 5, 4), QTime(12, 14, 14)])
30783078
f4.setGeometry(QgsGeometry.fromWkt('Point (-68.2 70.8)'))
30793079

30803080
f5 = QgsFeature()
3081-
f5.setAttributes([4, 400, 'Honey', 'Honey', '4'])
3081+
f5.setAttributes([4, 400, 'Honey', 'Honey', '4', QDateTime(QDate(2021, 5, 4), QTime(13, 13, 14)), QDate(2021, 5, 4), QTime(13, 13, 14)])
30823082
f5.setGeometry(QgsGeometry.fromWkt('Point (-65.32 78.3)'))
30833083

30843084
# create a layer with features only in the added features buffer - not the provider
@@ -3122,25 +3122,25 @@ class TestQgsVectorLayerSourceChangedGeometriesInBuffer(unittest.TestCase, Featu
31223122
@classmethod
31233123
def getSource(cls):
31243124
vl = QgsVectorLayer(
3125-
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
3125+
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time&key=pk',
31263126
'test', 'memory')
31273127
assert (vl.isValid())
31283128

31293129
f1 = QgsFeature()
3130-
f1.setAttributes([5, -200, NULL, 'NuLl', '5'])
3130+
f1.setAttributes([5, -200, NULL, 'NuLl', '5', QDateTime(QDate(2020, 5, 4), QTime(12, 13, 14)), QDate(2020, 5, 2), QTime(12, 13, 1)])
31313131

31323132
f2 = QgsFeature()
3133-
f2.setAttributes([3, 300, 'Pear', 'PEaR', '3'])
3133+
f2.setAttributes([3, 300, 'Pear', 'PEaR', '3', NULL, NULL, NULL])
31343134
f2.setGeometry(QgsGeometry.fromWkt('Point (-70.5 65.2)'))
31353135

31363136
f3 = QgsFeature()
3137-
f3.setAttributes([1, 100, 'Orange', 'oranGe', '1'])
3137+
f3.setAttributes([1, 100, 'Orange', 'oranGe', '1', QDateTime(QDate(2020, 5, 3), QTime(12, 13, 14)), QDate(2020, 5, 3), QTime(12, 13, 14)])
31383138

31393139
f4 = QgsFeature()
3140-
f4.setAttributes([2, 200, 'Apple', 'Apple', '2'])
3140+
f4.setAttributes([2, 200, 'Apple', 'Apple', '2', QDateTime(QDate(2020, 5, 4), QTime(12, 14, 14)), QDate(2020, 5, 4), QTime(12, 14, 14)])
31413141

31423142
f5 = QgsFeature()
3143-
f5.setAttributes([4, 400, 'Honey', 'Honey', '4'])
3143+
f5.setAttributes([4, 400, 'Honey', 'Honey', '4', QDateTime(QDate(2021, 5, 4), QTime(13, 13, 14)), QDate(2021, 5, 4), QTime(13, 13, 14)])
31443144

31453145
vl.dataProvider().addFeatures([f1, f2, f3, f4, f5])
31463146

@@ -3186,27 +3186,27 @@ class TestQgsVectorLayerSourceChangedAttributesInBuffer(unittest.TestCase, Featu
31863186
@classmethod
31873187
def getSource(cls):
31883188
vl = QgsVectorLayer(
3189-
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
3189+
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time&key=pk',
31903190
'test', 'memory')
31913191
assert (vl.isValid())
31923192

31933193
f1 = QgsFeature()
3194-
f1.setAttributes([5, 200, 'a', 'b', 'c'])
3194+
f1.setAttributes([5, 200, 'a', 'b', 'c', QDateTime(2020, 4, 5, 1, 2, 3), QDate(2020, 4, 5), QTime(1, 2, 3)])
31953195
f1.setGeometry(QgsGeometry.fromWkt('Point (-71.123 78.23)'))
31963196

31973197
f2 = QgsFeature()
3198-
f2.setAttributes([3, -200, 'd', 'e', 'f'])
3198+
f2.setAttributes([3, -200, 'd', 'e', 'f', QDateTime(2020, 4, 5, 1, 2, 3), QDate(2020, 4, 5), QTime(1, 2, 3)])
31993199

32003200
f3 = QgsFeature()
3201-
f3.setAttributes([1, -100, 'g', 'h', 'i'])
3201+
f3.setAttributes([1, -100, 'g', 'h', 'i', QDateTime(2020, 4, 5, 1, 2, 3), QDate(2020, 4, 5), QTime(1, 2, 3)])
32023202
f3.setGeometry(QgsGeometry.fromWkt('Point (-70.332 66.33)'))
32033203

32043204
f4 = QgsFeature()
3205-
f4.setAttributes([2, -200, 'j', 'k', 'l'])
3205+
f4.setAttributes([2, -200, 'j', 'k', 'l', QDateTime(2020, 4, 5, 1, 2, 3), QDate(2020, 4, 5), QTime(1, 2, 3)])
32063206
f4.setGeometry(QgsGeometry.fromWkt('Point (-68.2 70.8)'))
32073207

32083208
f5 = QgsFeature()
3209-
f5.setAttributes([4, 400, 'm', 'n', 'o'])
3209+
f5.setAttributes([4, 400, 'm', 'n', 'o', QDateTime(2020, 4, 5, 1, 2, 3), QDate(2020, 4, 5), QTime(1, 2, 3)])
32103210
f5.setGeometry(QgsGeometry.fromWkt('Point (-65.32 78.3)'))
32113211

32123212
vl.dataProvider().addFeatures([f1, f2, f3, f4, f5])
@@ -3219,26 +3219,41 @@ def getSource(cls):
32193219
vl.changeAttributeValue(ids[5], 2, NULL)
32203220
vl.changeAttributeValue(ids[5], 3, 'NuLl')
32213221
vl.changeAttributeValue(ids[5], 4, '5')
3222+
vl.changeAttributeValue(ids[5], 5, QDateTime(QDate(2020, 5, 4), QTime(12, 13, 14)))
3223+
vl.changeAttributeValue(ids[5], 6, QDate(2020, 5, 2))
3224+
vl.changeAttributeValue(ids[5], 7, QTime(12, 13, 1))
32223225

32233226
vl.changeAttributeValue(ids[3], 1, 300)
32243227
vl.changeAttributeValue(ids[3], 2, 'Pear')
32253228
vl.changeAttributeValue(ids[3], 3, 'PEaR')
32263229
vl.changeAttributeValue(ids[3], 4, '3')
3230+
vl.changeAttributeValue(ids[3], 5, NULL)
3231+
vl.changeAttributeValue(ids[3], 6, NULL)
3232+
vl.changeAttributeValue(ids[3], 7, NULL)
32273233

32283234
vl.changeAttributeValue(ids[1], 1, 100)
32293235
vl.changeAttributeValue(ids[1], 2, 'Orange')
32303236
vl.changeAttributeValue(ids[1], 3, 'oranGe')
32313237
vl.changeAttributeValue(ids[1], 4, '1')
3238+
vl.changeAttributeValue(ids[1], 5, QDateTime(QDate(2020, 5, 3), QTime(12, 13, 14)))
3239+
vl.changeAttributeValue(ids[1], 6, QDate(2020, 5, 3))
3240+
vl.changeAttributeValue(ids[1], 7, QTime(12, 13, 14))
32323241

32333242
vl.changeAttributeValue(ids[2], 1, 200)
32343243
vl.changeAttributeValue(ids[2], 2, 'Apple')
32353244
vl.changeAttributeValue(ids[2], 3, 'Apple')
32363245
vl.changeAttributeValue(ids[2], 4, '2')
3246+
vl.changeAttributeValue(ids[2], 5, QDateTime(QDate(2020, 5, 4), QTime(12, 14, 14)))
3247+
vl.changeAttributeValue(ids[2], 6, QDate(2020, 5, 4))
3248+
vl.changeAttributeValue(ids[2], 7, QTime(12, 14, 14))
32373249

32383250
vl.changeAttributeValue(ids[4], 1, 400)
32393251
vl.changeAttributeValue(ids[4], 2, 'Honey')
32403252
vl.changeAttributeValue(ids[4], 3, 'Honey')
32413253
vl.changeAttributeValue(ids[4], 4, '4')
3254+
vl.changeAttributeValue(ids[4], 5, QDateTime(QDate(2021, 5, 4), QTime(13, 13, 14)))
3255+
vl.changeAttributeValue(ids[4], 6, QDate(2021, 5, 4))
3256+
vl.changeAttributeValue(ids[4], 7, QTime(13, 13, 14))
32423257

32433258
return vl
32443259

@@ -3287,28 +3302,28 @@ class TestQgsVectorLayerSourceDeletedFeaturesInBuffer(unittest.TestCase, Feature
32873302
@classmethod
32883303
def getSource(cls):
32893304
vl = QgsVectorLayer(
3290-
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk',
3305+
'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time&&key=pk',
32913306
'test', 'memory')
32923307
assert (vl.isValid())
32933308

32943309
# add a bunch of similar features to the provider
32953310
b1 = QgsFeature()
3296-
b1.setAttributes([5, -300, 'Apple', 'PEaR', '1'])
3311+
b1.setAttributes([5, -300, 'Apple', 'PEaR', '1', QDateTime(QDate(2020, 5, 5), QTime(12, 11, 14)), QDate(2020, 5, 1), QTime(10, 13, 1)])
32973312
b1.setGeometry(QgsGeometry.fromWkt('Point (-70.332 66.33)'))
32983313

32993314
b2 = QgsFeature()
3300-
b2.setAttributes([3, 100, 'Orange', 'NuLl', '2'])
3315+
b2.setAttributes([3, 100, 'Orange', 'NuLl', '2', QDateTime(QDate(2020, 5, 1), QTime(12, 13, 14)), QDate(2020, 5, 9), QTime(9, 13, 1)])
33013316
b2.setGeometry(QgsGeometry.fromWkt('Point (-71.123 78.23)'))
33023317

33033318
b3 = QgsFeature()
3304-
b3.setAttributes([1, -200, 'Honey', 'oranGe', '5'])
3319+
b3.setAttributes([1, -200, 'Honey', 'oranGe', '5', QDateTime(QDate(2020, 5, 1), QTime(12, 13, 14)), QDate(2020, 5, 19), QTime(2, 13, 1)])
33053320

33063321
b4 = QgsFeature()
3307-
b4.setAttributes([2, 400, 'Pear', 'Honey', '3'])
3322+
b4.setAttributes([2, 400, 'Pear', 'Honey', '3', QDateTime(QDate(2020, 4, 4), QTime(12, 13, 14)), QDate(2020, 4, 2), QTime(4, 13, 1)])
33083323
b4.setGeometry(QgsGeometry.fromWkt('Point (-65.32 78.3)'))
33093324

33103325
b5 = QgsFeature()
3311-
b5.setAttributes([4, 200, NULL, 'oranGe', '3'])
3326+
b5.setAttributes([4, 200, NULL, 'oranGe', '3', QDateTime(QDate(2019, 5, 4), QTime(12, 13, 14)), QDate(2019, 5, 2), QTime(1, 13, 1)])
33123327
b5.setGeometry(QgsGeometry.fromWkt('Point (-68.2 70.8)'))
33133328

33143329
vl.dataProvider().addFeatures([b1, b2, b3, b4, b5])
@@ -3317,22 +3332,22 @@ def getSource(cls):
33173332

33183333
# here's our good features
33193334
f1 = QgsFeature()
3320-
f1.setAttributes([5, -200, NULL, 'NuLl', '5'])
3335+
f1.setAttributes([5, -200, NULL, 'NuLl', '5', QDateTime(QDate(2020, 5, 4), QTime(12, 13, 14)), QDate(2020, 5, 2), QTime(12, 13, 1)])
33213336
f1.setGeometry(QgsGeometry.fromWkt('Point (-71.123 78.23)'))
33223337

33233338
f2 = QgsFeature()
3324-
f2.setAttributes([3, 300, 'Pear', 'PEaR', '3'])
3339+
f2.setAttributes([3, 300, 'Pear', 'PEaR', '3', NULL, NULL, NULL])
33253340

33263341
f3 = QgsFeature()
3327-
f3.setAttributes([1, 100, 'Orange', 'oranGe', '1'])
3342+
f3.setAttributes([1, 100, 'Orange', 'oranGe', '1', QDateTime(QDate(2020, 5, 3), QTime(12, 13, 14)), QDate(2020, 5, 3), QTime(12, 13, 14)])
33283343
f3.setGeometry(QgsGeometry.fromWkt('Point (-70.332 66.33)'))
33293344

33303345
f4 = QgsFeature()
3331-
f4.setAttributes([2, 200, 'Apple', 'Apple', '2'])
3346+
f4.setAttributes([2, 200, 'Apple', 'Apple', '2', QDateTime(QDate(2020, 5, 4), QTime(12, 14, 14)), QDate(2020, 5, 4), QTime(12, 14, 14)])
33323347
f4.setGeometry(QgsGeometry.fromWkt('Point (-68.2 70.8)'))
33333348

33343349
f5 = QgsFeature()
3335-
f5.setAttributes([4, 400, 'Honey', 'Honey', '4'])
3350+
f5.setAttributes([4, 400, 'Honey', 'Honey', '4', QDateTime(QDate(2021, 5, 4), QTime(13, 13, 14)), QDate(2021, 5, 4), QTime(13, 13, 14)])
33363351
f5.setGeometry(QgsGeometry.fromWkt('Point (-65.32 78.3)'))
33373352

33383353
vl.dataProvider().addFeatures([f1, f2, f3, f4, f5])

0 commit comments

Comments
 (0)
Please sign in to comment.