Fix minor bugs in test_intl.py causing tests to fail under python 2.5

os.path.relpath not defined in Python 2.5, use equivalent from
sphinx.util.pycompat

Also avoid trying to create an existing directory when remnants exist
of an earlier failed build
This commit is contained in:
Jonathan Waltman 2012-12-11 01:36:50 -06:00
parent 6748b60d39
commit 29f768e48f

View File

@ -15,6 +15,8 @@ import re
import os import os
from StringIO import StringIO from StringIO import StringIO
from sphinx.util.pycompat import relpath
from util import * from util import *
from util import SkipTest from util import SkipTest
@ -23,6 +25,8 @@ warnfile = StringIO()
def setup_module(): def setup_module():
# Delete remnants left over after failed build
(test_root / 'xx').rmtree(True)
(test_root / 'xx' / 'LC_MESSAGES').makedirs() (test_root / 'xx' / 'LC_MESSAGES').makedirs()
# Compile all required catalogs into binary format (*.mo). # Compile all required catalogs into binary format (*.mo).
for dirpath, dirs, files in os.walk(test_root): for dirpath, dirs, files in os.walk(test_root):
@ -30,18 +34,13 @@ def setup_module():
for f in [f for f in files if f.endswith('.po')]: for f in [f for f in files if f.endswith('.po')]:
po = dirpath / f po = dirpath / f
mo = test_root / 'xx' / 'LC_MESSAGES' / ( mo = test_root / 'xx' / 'LC_MESSAGES' / (
os.path.relpath(po[:-3], test_root) + '.mo') relpath(po[:-3], test_root) + '.mo')
if not mo.parent.exists(): if not mo.parent.exists():
mo.parent.makedirs() mo.parent.makedirs()
try: try:
p = Popen(['msgfmt', po, '-o', mo], p = Popen(['msgfmt', po, '-o', mo],
stdout=PIPE, stderr=PIPE) stdout=PIPE, stderr=PIPE)
except OSError: except OSError:
# The test will fail the second time it's run if we don't
# tear down here. Not sure if there's a more idiomatic way
# of ensuring that teardown gets run in the event of an
# exception from the setup function.
teardown_module()
raise SkipTest # most likely msgfmt was not found raise SkipTest # most likely msgfmt was not found
else: else:
stdout, stderr = p.communicate() stdout, stderr = p.communicate()