def Xtest_Afrikaans(self): """Test that Afrikaans translations are working""" # Note this has really bad side effects - lots of tests suddenly start # breaking when this test is enabled....disabled for now, but I have # left the test here for now as it illustrates one potential avenue # that can be pursued if dynamically changing the language to unit test # different locales ever becomes a requirement. # Be sure nose tests all run cleanly before reintroducing this! # This is part test and part demonstrator of how to reload inasafe # Now see if the same function is delivered for the function # Because of the way impact plugins are loaded in inasafe # (see http://effbot.org/zone/metaclass-plugins.htm) # lang in the context of the ugettext function in inasafe libs # must be imported late so that i18n is set up already from common.utilities import ugettext as _ myUntranslatedString = 'Temporarily Closed' myExpectedString = 'Tydelik gesluit' # afrikaans myTranslation = _(myUntranslatedString) myMessage = '\nTranslated: %s\nGot: %s\nExpected: %s' % ( myUntranslatedString, myTranslation, myExpectedString) assert myTranslation == myExpectedString, myMessage myParent = QWidget() myCanvas = QgsMapCanvas(myParent) myIface = QgisInterface(myCanvas) # reload all inasafe modules so that i18n get picked up afresh # this is the part that produces bad side effects for myMod in sys.modules.values(): try: if ('storage' in str(myMod) or 'impact' in str(myMod)): print 'Reloading:', str(myMod) reload(myMod) except NameError: pass myPlugin = ISPlugin(myIface) myPlugin.setupI18n('af') # afrikaans myLang = os.environ['LANG'] assert myLang == 'af' from gui.is_safe_interface import getSafeImpactFunctions #myFunctions = getSafeImpactFunctions() #print myFunctions myFunctions = getSafeImpactFunctions('Tydelik gesluit') assert len(myFunctions) > 0
def getRunner(self): """ Factory to create a new runner thread. Requires three parameters to be set before execution can take place: * Hazard layer - a path to a raster (string) * Exposure layer - a path to a vector hazard layer (string). * Function - a function name that defines how the Hazard assessment will be computed (string). Args: None. Returns: None Raises: InsufficientParametersException if not all parameters are set. """ self._filename = None self._result = None if self._hazardLayer is None or self._hazardLayer == '': myMessage = self.tr('Error: Hazard layer not set.') raise InsufficientParametersException(myMessage) if self._exposureLayer is None or self._exposureLayer == '': myMessage = self.tr('Error: Exposure layer not set.') raise InsufficientParametersException(myMessage) if self._function is None or self._function == '': myMessage = self.tr('Error: Function not set.') raise InsufficientParametersException(myMessage) # Call impact calculation engine try: myHazardLayer = readSafeLayer(self._hazardLayer) myExposureLayer = readSafeLayer(self._exposureLayer) except: raise myFunctions = getSafeImpactFunctions(self._function) myFunction = myFunctions[0][self._function] return ISImpactCalculatorThread(myHazardLayer, myExposureLayer, myFunction)