Skip to content

Commit

Permalink
Fix localized data test on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 21, 2020
1 parent 600f93a commit 24b1851
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tests/src/python/test_qgslocalizeddatapathregistry.py
Expand Up @@ -12,19 +12,19 @@

import qgis # NOQA

from tempfile import NamedTemporaryFile, gettempdir
from tempfile import NamedTemporaryFile
import tempfile
from pathlib import Path
import os
import gc
import shutil
from qgis.core import (
QgsLocalizedDataPathRegistry,
QgsApplication,
QgsPathResolver,
QgsProject,
QgsVectorLayer
)
from qgis.PyQt.QtCore import QDir
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath

start_app()

Expand All @@ -38,6 +38,14 @@ class TestQgsLocalizedDataPathRegistry(unittest.TestCase):
Test resolving and saving localized data paths
"""

@classmethod
def setUpClass(cls):
cls.temp_path = tempfile.mkdtemp()

@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.temp_path)

def setUp(self):
QgsApplication.localizedDataPathRegistry().registerPath(BASE_PATH)

Expand All @@ -49,13 +57,12 @@ def testQgsLocalizedDataPathRegistry(self):
self.assertEqual(QgsApplication.localizedDataPathRegistry().globalPath(MAP_PATH), ABSOLUTE_PATH)

def testOrderOfPreference(self):
temp_dir = gettempdir()
os.mkdir('{}/data'.format(temp_dir))
alt_dir = '{}/{}'.format(temp_dir, MAP_PATH)
os.mkdir('{}/data'.format(self.temp_path))
alt_dir = '{}/{}'.format(self.temp_path, MAP_PATH)
Path(alt_dir).touch()
QgsApplication.localizedDataPathRegistry().registerPath(temp_dir, 0)
self.assertEqual(QgsApplication.localizedDataPathRegistry().globalPath(MAP_PATH), alt_dir)
QgsApplication.localizedDataPathRegistry().unregisterPath(temp_dir)
QgsApplication.localizedDataPathRegistry().registerPath(self.temp_path, 0)
self.assertEqual(QDir.toNativeSeparators(QgsApplication.localizedDataPathRegistry().globalPath(MAP_PATH)), QDir.toNativeSeparators(alt_dir))
QgsApplication.localizedDataPathRegistry().unregisterPath(self.temp_path)

def testWithResolver(self):
self.assertEqual(QgsPathResolver().readPath('localized:' + MAP_PATH), ABSOLUTE_PATH)
Expand Down

0 comments on commit 24b1851

Please sign in to comment.