Source code for svir.test.unit.test_translations

# coding=utf-8
"""Safe Translations Test.

.. note:: This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.

"""

# This file was generated from the QGIS Plugin builder plugin
# See https://github.com/g-sherman/Qgis-Plugin-Builder/


__author__ = 'ismailsunni@yahoo.co.id'
__date__ = '12/10/2011'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
                 'Disaster Reduction')
import unittest
import os

from qgis.PyQt.QtCore import QCoreApplication, QTranslator

from qgis.testing import start_app
from qgis.testing.mocked import get_iface

QGIS_APP = start_app()
IFACE = get_iface()


[docs]class SafeTranslationsTest(unittest.TestCase): """Test translations work."""
[docs] def setUp(self): """Runs before each test.""" if 'LANG' in iter(os.environ.keys()): os.environ.__delitem__('LANG')
[docs] def tearDown(self): """Runs after each test.""" if 'LANG' in iter(os.environ.keys()): os.environ.__delitem__('LANG')
[docs] def test_qgis_translations(self): """Test that translations work.""" parent_path = os.path.join( __file__, os.pardir, os.pardir, os.pardir) dir_path = os.path.abspath(parent_path) file_path = os.path.join( dir_path, 'i18n', 'it.qm') translator = QTranslator() translator.load(file_path) QCoreApplication.installTranslator(translator) expected_message = 'Buon giorno' real_message = QCoreApplication.translate("@default", 'Good morning') self.assertEqual(real_message, expected_message)
if __name__ == "__main__": suite = unittest.makeSuite(SafeTranslationsTest) runner = unittest.TextTestRunner(verbosity=2) runner.run(suite)