Skip to content

Commit

Permalink
Ensure base class setup/tear down methods are always called
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 26, 2023
1 parent f2878a4 commit c8ae430
Show file tree
Hide file tree
Showing 161 changed files with 250 additions and 116 deletions.
2 changes: 2 additions & 0 deletions tests/src/python/test_authmanager_oauth2_ows.py
Expand Up @@ -131,6 +131,7 @@ def setUpAuth(cls):

@classmethod
def setUpClass(cls):
super().setUpClass()
"""Run before all tests:
Creates an auth configuration"""
cls.port = QGIS_SERVER_ENDPOINT_PORT
Expand Down Expand Up @@ -179,6 +180,7 @@ def tearDownClass(cls):
cls.server.kill()
rmtree(QGIS_AUTH_DB_DIR_PATH)
del cls.server
super().tearDownClass()

def setUp(self):
"""Run before each test."""
Expand Down
6 changes: 1 addition & 5 deletions tests/src/python/test_authmanager_ogr.py
Expand Up @@ -60,6 +60,7 @@ def setUpAuth(cls):

@classmethod
def setUpClass(cls):
super().setUpClass()
"""Run before all tests:
Creates an auth configuration"""
cls.username = 'username'
Expand All @@ -68,11 +69,6 @@ def setUpClass(cls):
cls.hostname = 'localhost'
cls.setUpAuth()

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
pass

def setUp(self):
"""Run before each test."""
pass
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_authmanager_ogr_postgres.py
Expand Up @@ -136,6 +136,7 @@ def setUpAuth(cls):
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
super().setUpClass()
cls.port = QGIS_POSTGRES_SERVER_PORT
cls.username = 'username'
cls.password = 'password'
Expand Down Expand Up @@ -185,6 +186,7 @@ def tearDownClass(cls):
time.sleep(2)
rmtree(QGIS_AUTH_DB_DIR_PATH)
rmtree(cls.tempfolder)
super().tearDownClass()

def setUp(self):
"""Run before each test."""
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_authmanager_password_ows.py
Expand Up @@ -61,6 +61,7 @@ class TestAuthManager(unittest.TestCase):
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
super().setUpClass()
cls.port = QGIS_SERVER_ENDPOINT_PORT
# Clean env just to be sure
env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
Expand Down Expand Up @@ -108,6 +109,7 @@ def tearDownClass(cls):
cls.server.terminate()
rmtree(QGIS_AUTH_DB_DIR_PATH)
del cls.server
super().tearDownClass()

def setUp(self):
"""Run before each test."""
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_authmanager_password_postgres.py
Expand Up @@ -77,6 +77,7 @@ class TestAuthManager(unittest.TestCase):
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
super().setUpClass()
cls.username = 'docker'
cls.password = 'docker'
cls.dbname = 'qgis_test'
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_authmanager_pki_ows.py
Expand Up @@ -97,6 +97,7 @@ def setUpAuth(cls):
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
super().setUpClass()
cls.port = QGIS_SERVER_ENDPOINT_PORT
# Clean env just to be sure
env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
Expand Down Expand Up @@ -130,6 +131,7 @@ def tearDownClass(cls):
cls.server.terminate()
rmtree(QGIS_AUTH_DB_DIR_PATH)
del cls.server
super().tearDownClass()

def setUp(self):
"""Run before each test."""
Expand Down
6 changes: 1 addition & 5 deletions tests/src/python/test_authmanager_pki_postgres.py
Expand Up @@ -84,15 +84,11 @@ def setUpAuth(cls):
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
super().setUpClass()

cls.certsdata_path = os.path.join(unitTestDataPath('auth_system'), 'certs_keys_2048')
cls.setUpAuth()

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
super().tearDownClass()

def setUp(self):
"""Run before each test."""
super().setUp()
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_authmanager_proxy.py
Expand Up @@ -40,6 +40,7 @@ class TestAuthManager(unittest.TestCase):
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
super().setUpClass()
# Enable auth
# os.environ['QGIS_AUTH_PASSWORD_FILE'] = QGIS_AUTH_PASSWORD_FILE
authm = QgsApplication.authManager()
Expand All @@ -56,6 +57,7 @@ def setUpClass(cls):
def tearDownClass(cls):
"""Run after all tests"""
rmtree(QGIS_AUTH_DB_DIR_PATH)
super().tearDownClass()

def setUp(self):
"""Run before each test."""
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_authsettingswidget.py
Expand Up @@ -39,6 +39,7 @@ class TestAuthenticationWidget(unittest.TestCase):
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
super().setUpClass()
# Enable auth
# os.environ['QGIS_AUTH_PASSWORD_FILE'] = QGIS_AUTH_PASSWORD_FILE
authm = QgsApplication.authManager()
Expand All @@ -55,6 +56,7 @@ def setUpClass(cls):
def tearDownClass(cls):
"""Run after all tests"""
rmtree(QGIS_AUTH_DB_DIR_PATH)
super().tearDownClass()

def setUp(self):
"""Run before each test."""
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_db_manager_gpkg.py
Expand Up @@ -33,6 +33,7 @@ class TestPyQgsDBManagerGpkg(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()

QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain("TestPyQgsDBManagerGpkg.com")
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_db_manager_postgis.py
Expand Up @@ -205,6 +205,7 @@ def addConnectionConfig(cls, conn_name, uri):
def setUpClass(cls):
"""Run before all tests"""
# start ans setup server
super().setUpClass()
cls.setUpServer()

# start a standalone qgis application
Expand All @@ -224,6 +225,7 @@ def tearDownClass(cls):
rmtree(QGIS_AUTH_DB_DIR_PATH)
rmtree(cls.tempfolder)
QgsSettings().clear()
super().tearDownClass()

###########################################

Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_db_manager_spatialite.py
Expand Up @@ -31,6 +31,7 @@ class TestPyQgsDBManagerSpatialite(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()

QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain("TestPyQgsDBManagerSpatialite.com")
Expand Down Expand Up @@ -58,6 +59,7 @@ def tearDownClass(cls):

QgsSettings().clear()
shutil.rmtree(cls.basetestpath, True)
super().tearDownClass()

def testSupportedDbTypes(self):
self.assertIn('spatialite', supportedDbTypes())
Expand Down
10 changes: 0 additions & 10 deletions tests/src/python/test_layer_dependencies.py
Expand Up @@ -39,16 +39,6 @@

class TestLayerDependencies(unittest.TestCase):

@classmethod
def setUpClass(cls):
"""Run before all tests"""
pass

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
pass

def setUp(self):
"""Run before each test."""
# create a temp SpatiaLite db with a trigger
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_offline_editing_wfs.py
Expand Up @@ -52,6 +52,7 @@ class TestWFST(unittest.TestCase, OfflineTestBase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()
cls.port = QGIS_SERVER_OFFLINE_PORT
# Create tmp folder
cls.temp_path = tempfile.mkdtemp()
Expand Down Expand Up @@ -79,6 +80,7 @@ def setUpClass(cls):
def tearDownClass(cls):
"""Run after all tests"""
rmtree(cls.temp_path)
super().tearDownClass()

def setUp(self):
"""Run before each test."""
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_plugindependencies.py
Expand Up @@ -30,6 +30,7 @@ class PluginDependenciesTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Runs at start."""
super().setUpClass()

QCoreApplication.setOrganizationName("QGIS")
QCoreApplication.setOrganizationDomain("qgis.org")
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_processing_importintopostgis.py
Expand Up @@ -40,6 +40,7 @@ class TestExportToPostGis(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()
QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain(
"QGIS_TestPyQgsExportToPostgis.com")
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/test_processing_packagelayers.py
Expand Up @@ -52,6 +52,7 @@ class TestPackageLayers(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()
QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain(
"QGIS_TestPyQgsPackageLayers.com")
Expand Down
10 changes: 0 additions & 10 deletions tests/src/python/test_project_storage_base.py
Expand Up @@ -23,16 +23,6 @@

class TestPyQgsProjectStorageBase:

@classmethod
def setUpClass(cls):
"""Run before all tests"""
pass

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
pass

def dropProjectsTable(self):
"""Drop existing project storage table"""
pass
Expand Down
4 changes: 0 additions & 4 deletions tests/src/python/test_project_storage_oracle.py
Expand Up @@ -60,10 +60,6 @@ def setUpClass(cls):

assert cls.con.open()

@classmethod
def tearDownClass(cls):
"""Run after all tests"""

def execSQLCommand(self, sql, ignore_errors=False):
self.assertTrue(self.con)
query = QSqlQuery(self.con)
Expand Down
4 changes: 0 additions & 4 deletions tests/src/python/test_project_storage_postgres.py
Expand Up @@ -54,10 +54,6 @@ def setUpClass(cls):
cls.provider = 'postgres'
cls.project_storage_type = 'postgresql'

@classmethod
def tearDownClass(cls):
"""Run after all tests"""

def execSQLCommand(self, sql):
self.assertTrue(self.con)
cur = self.con.cursor()
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_provider_afs.py
Expand Up @@ -93,6 +93,7 @@ def treat_time_as_string(self):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()

QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain("TestPyQgsAFSProvider.com")
Expand Down Expand Up @@ -695,6 +696,7 @@ def tearDownClass(cls):
QgsSettings().clear()
# shutil.rmtree(cls.basetestpath, True)
cls.vl = None # so as to properly close the provider and remove any temporary file
super().tearDownClass()

def testGetFeaturesSubsetAttributes2(self):
""" Override and skip this test for AFS provider, as it's actually more efficient for the AFS provider to return
Expand Down
5 changes: 1 addition & 4 deletions tests/src/python/test_provider_gpx.py
Expand Up @@ -41,15 +41,12 @@ def createLayer(cls):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()
# Create test layer
cls.vl = cls.createLayer()
assert (cls.vl.isValid())
cls.source = cls.vl.dataProvider()

@classmethod
def tearDownClass(cls):
"""Run after all tests"""

@property
def pk_name(self):
"""Return the primary key name, override if different than the default 'pk'"""
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_provider_hana.py
Expand Up @@ -56,6 +56,7 @@ class TestPyQgsHanaProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()
cls.uri = 'driver=\'/usr/sap/hdbclient/libodbcHDB.so\' host=localhost port=30015 user=SYSTEM ' \
'password=mypassword sslEnabled=true sslValidateCertificate=False'
if 'QGIS_HANA_TEST_DB' in os.environ:
Expand All @@ -80,6 +81,7 @@ def tearDownClass(cls):

QgsHanaProviderUtils.cleanUp(cls.conn, cls.schemaName)
cls.conn.close()
super().tearDownClass()

def createVectorLayer(self, conn_parameters, layer_name):
layer = QgsHanaProviderUtils.createVectorLayer(self.uri + ' ' + conn_parameters, layer_name)
Expand Down
11 changes: 3 additions & 8 deletions tests/src/python/test_provider_memory.py
Expand Up @@ -82,6 +82,7 @@ def createLayer(cls):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()
# Create test layer
cls.vl = cls.createLayer()
assert (cls.vl.isValid())
Expand Down Expand Up @@ -113,10 +114,6 @@ def setUpClass(cls):

cls.poly_provider.addFeatures([f1, f2, f3, f4])

@classmethod
def tearDownClass(cls):
"""Run after all tests"""

def getEditableLayer(self):
return self.createLayer()

Expand Down Expand Up @@ -1020,7 +1017,9 @@ class TestPyQgsMemoryProviderIndexed(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()
# Create test layer

cls.vl = QgsVectorLayer(
'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',
'test', 'memory')
Expand Down Expand Up @@ -1080,10 +1079,6 @@ def setUpClass(cls):

cls.poly_provider.addFeatures([f1, f2, f3, f4])

@classmethod
def tearDownClass(cls):
"""Run after all tests"""

def testGetFeaturesSubsetAttributes2(self):
""" Override and skip this test for memory provider, as it's actually more efficient for the memory provider to return
its features as direct copies (due to implicit sharing of QgsFeature)
Expand Down
6 changes: 1 addition & 5 deletions tests/src/python/test_provider_mssql.py
Expand Up @@ -45,6 +45,7 @@ class TestPyQgsMssqlProvider(unittest.TestCase, ProviderTestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
super().setUpClass()
# These are the connection details for the SQL Server instance running on Travis
cls.dbconn = "service='testsqlserver' user=sa password='<YourStrong!Passw0rd>' "
if 'QGIS_MSSQLTEST_DB' in os.environ:
Expand All @@ -70,11 +71,6 @@ def setUpClass(cls):
md = QgsProviderRegistry.instance().providerMetadata('mssql')
cls.conn_api = md.createConnection(cls.dbconn, {})

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
pass

def setUp(self):
for t in ['new_table', 'new_table_multipoint', 'new_table_multipolygon']:
self.execSQLCommand(f'DROP TABLE IF EXISTS qgis_test.[{t}]')
Expand Down

0 comments on commit c8ae430

Please sign in to comment.