forked from github/pelican
Make sure locale is what we want before/after the tests
The locale is a global state, and it was not properly reset to
whatever it was before the unitttest possibly changed it.
This is now fixed.
Not restoring the locale led to weird issues: depending on
the order chosen by "python -m unittest discover" to run
the unit tests, some tests would apparently randomly fail
due to the locale not being what was expected.
For example, test_period_in_timeperiod_archive would
call mock('posts/1970/ 1月/index.html',...) instead of
expected mock('posts/1970/Jan/index.html',...) and fail.
This commit is contained in:
parent
e97e9b5ae5
commit
7277c95fb5
7 changed files with 44 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals, print_function
|
|||
import os
|
||||
import re
|
||||
|
||||
import locale
|
||||
from pelican.tools.pelican_import import wp2fields, fields2pelican, decode_wp_content, build_header, build_markdown_header, get_attachments, download_attachments
|
||||
from pelican.tests.support import (unittest, temporary_folder, mute,
|
||||
skipIfNoExecutable)
|
||||
|
|
@ -30,9 +31,14 @@ except ImportError:
|
|||
class TestWordpressXmlImporter(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.old_locale = locale.setlocale(locale.LC_ALL)
|
||||
locale.setlocale(locale.LC_ALL, str('C'))
|
||||
self.posts = list(wp2fields(WORDPRESS_XML_SAMPLE))
|
||||
self.custposts = list(wp2fields(WORDPRESS_XML_SAMPLE, True))
|
||||
|
||||
def tearDown(self):
|
||||
locale.setlocale(locale.LC_ALL, self.old_locale)
|
||||
|
||||
def test_ignore_empty_posts(self):
|
||||
self.assertTrue(self.posts)
|
||||
for title, content, fname, date, author, categ, tags, kind, format in self.posts:
|
||||
|
|
@ -261,8 +267,13 @@ class TestBuildHeader(unittest.TestCase):
|
|||
@unittest.skipUnless(BeautifulSoup, 'Needs BeautifulSoup module')
|
||||
class TestWordpressXMLAttachements(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.old_locale = locale.setlocale(locale.LC_ALL)
|
||||
locale.setlocale(locale.LC_ALL, str('C'))
|
||||
self.attachments = get_attachments(WORDPRESS_XML_SAMPLE)
|
||||
|
||||
def tearDown(self):
|
||||
locale.setlocale(locale.LC_ALL, self.old_locale)
|
||||
|
||||
def test_recognise_attachments(self):
|
||||
self.assertTrue(self.attachments)
|
||||
self.assertTrue(len(self.attachments.keys()) == 3)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue