#!/usr/bin/python
# -*- coding: utf-8 -*-

'''Unit tests to test QTranslator and translation in general.'''

import os
import unittest
from PySide.QtCore import *

from helper import UsesQCoreApplication

class TranslationTest(UsesQCoreApplication):
    '''Test case for Qt translation facilities.'''

    def setUp(self):
        super(TranslationTest, self).setUp()
        self.trdir = os.path.join(os.path.dirname(__file__), 'translations')
        # os.system is probably not the best way to do it
        os.system('lrelease %s/*.ts > /dev/null' % self.trdir)

    def tearDown(self):
        os.system('rm %s/*.qm > /dev/null' % self.trdir)
        super(TranslationTest, self).tearDown()

    def testLatin(self):
        #Set string value to Latin
        translator = QTranslator()
        translator.load(os.path.join(self.trdir, 'trans_latin.qm'))
        self.app.installTranslator(translator)

        obj = QObject()
        obj.setObjectName(obj.tr('Hello World!'))
        self.assertEqual(obj.objectName(), u'Orbis, te saluto!')

    def testRussian(self):
        #Set string value to Russian
        translator = QTranslator()
        translator.load(os.path.join(self.trdir, 'trans_russian.qm'))
        self.app.installTranslator(translator)

        obj = QObject()
        obj.setObjectName(obj.tr('Hello World!'))
        self.assertEqual(obj.objectName(), u'привет мир!')

    def testUtf8(self):
        translator = QTranslator()
        translator.load(os.path.join(self.trdir, 'trans_russian.qm'))
        self.app.installTranslator(translator)

        obj = QObject()
        obj.setObjectName(obj.trUtf8('Hello World!'))
        self.assertEqual(obj.objectName(), u'привет мир!')

    def testTranslateWithNoneDisambiguation(self):
        value = 'String here'
        obj = QCoreApplication.translate('context', value, None, QCoreApplication.UnicodeUTF8)
        self.assert_(isinstance(obj, unicode))
        self.assertEqual(obj, value)

if __name__ == '__main__':
    unittest.main()


@@ -112,16 +112,28 @@
 port os%0A
+import glob%0A
 import u
@@ -512,151 +512,213 @@
  it%0A
-        os.system('lrelease %25s/*.ts %3E /dev/null' %25 self.trdir)%0A%0A    def tearDown(self):%0A        os.system('rm %25s/*.qm %3E /dev/null' %25 self.trdir
+%09for file in glob.glob('%25s/*.ts'  %25 self.trdir):%0A%09    self.assertFalse(os.system('lrelease -silent %25s' %25 file))%0A%0A    def tearDown(self):%0A%09for file in glob.glob('%25s/*.qm'  %25 self.trdir):%0A%09    os.remove(file
 )%0A  

Remove OS specific commands from translation test.