Make test_translations test our tree

In order to run the correct classes, Python test framework adjusts
sys.path. However, these changes are not propagated to subprocesses.
Therefore, the test actually tries to test installed Swift, not
the one in which it is running.

The usual suggestion is to run "python setup.py develop" before
testing, but it's annoying and error-prone. If you forget it,
you may test the code in /usr very easily, and never know.

Let's just pass the correct path to subprocess. Much safer.

Change-Id: Ic71314e8462cf6e0579d704ffe9fbbfac7e6ba24
This commit is contained in:
Pete Zaitcev 2013-10-04 23:18:07 -06:00
parent 34340ddf49
commit c7e65db27d

View File

@ -3,6 +3,8 @@
import os
import unittest
import string
import sys
try:
from subprocess import check_output
@ -27,15 +29,17 @@ except ImportError:
os.environ['LC_ALL'] = 'eo'
os.environ['SWIFT_LOCALEDIR'] = os.path.dirname(__file__)
from swift import gettext_ as _
class TestTranslations(unittest.TestCase):
def test_translations(self):
translated_message = check_output(['python', __file__])
path = ':'.join(sys.path)
translated_message = check_output(['python', __file__, path])
self.assertEquals(translated_message, 'testo mesaĝon\n')
if __name__ == "__main__":
sys.path = string.split(sys.argv[1], ':')
from swift import gettext_ as _
print _('test message')