Skip to content

Commit

Permalink
Modernise test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 12, 2021
1 parent cf43c60 commit a09ffc8
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tests/src/python/test_qgsrelation.py
Expand Up @@ -85,22 +85,22 @@ def tearDown(self):

def test_isValid(self):
rel = QgsRelation()
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.setId('rel1')
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.setName('Relation Number One')
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.setReferencingLayer(self.referencingLayer.id())
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.setReferencedLayer(self.referencedLayer.id())
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.addFieldPair('foreignkey', 'y')
assert rel.isValid()
self.assertTrue(rel.isValid())

def test_getRelatedFeatures(self):
rel = QgsRelation()
Expand All @@ -116,7 +116,7 @@ def test_getRelatedFeatures(self):
self.assertEqual(rel.getRelatedFeaturesFilter(feat), '"foreignkey" = 123')

it = rel.getRelatedFeatures(feat)
assert [a.attributes() for a in it] == [['test1', 123], ['test2', 123]]
self.assertEqual([a.attributes() for a in it], [['test1', 123], ['test2', 123]])

def test_getRelatedFeaturesWithQuote(self):
rel = QgsRelation()
Expand All @@ -130,7 +130,7 @@ def test_getRelatedFeaturesWithQuote(self):
feat = self.referencedLayer.getFeature(3)

it = rel.getRelatedFeatures(feat)
assert next(it).attributes() == ["foobar'bar", 124]
self.assertEqual(next(it).attributes(), ["foobar'bar", 124])

def test_getReferencedFeature(self):
rel = QgsRelation()
Expand All @@ -144,8 +144,8 @@ def test_getReferencedFeature(self):

f = rel.getReferencedFeature(feat)

assert f.isValid()
assert f[0] == 'foo'
self.assertTrue(f.isValid())
self.assertEqual(f[0], 'foo')

# try mixing up the field pair field name cases -- we should be tolerant to this
rel2 = QgsRelation()
Expand All @@ -159,8 +159,8 @@ def test_getReferencedFeature(self):

f = rel2.getReferencedFeature(feat)

assert f.isValid()
assert f[0] == 'foo'
self.assertTrue(f.isValid())
self.assertEqual(f[0], 'foo')

def test_fieldPairs(self):
rel = QgsRelation()
Expand All @@ -171,7 +171,7 @@ def test_fieldPairs(self):
rel.setReferencedLayer(self.referencedLayer.id())
rel.addFieldPair('foreignkey', 'y')

assert (rel.fieldPairs() == {'foreignkey': 'y'})
self.assertEqual(rel.fieldPairs(), {'foreignkey': 'y'})

def testValidRelationAfterChangingStyle(self):
# load project
Expand Down

0 comments on commit a09ffc8

Please sign in to comment.