Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensure base class setup/tear down methods are always called
  • 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