Merge pull request #268 from AndreaCrotti/unittest2

Clean up testing modules
This commit is contained in:
Alexis Metaireau 2012-03-21 17:56:48 -07:00
commit 9009ed7e43
7 changed files with 24 additions and 31 deletions

View file

@ -1,9 +1,20 @@
__all__ = [
'temporary_folder',
'get_article',
'unittest',
]
from contextlib import contextmanager from contextlib import contextmanager
from tempfile import mkdtemp from tempfile import mkdtemp
from shutil import rmtree from shutil import rmtree
from pelican.contents import Article from pelican.contents import Article
try:
import unittest2 as unittest
except ImportError:
import unittest
@contextmanager @contextmanager
def temporary_folder(): def temporary_folder():

View file

@ -1,9 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import with_statement
try: from .support import unittest
from unittest2 import TestCase, skip
except ImportError, e:
from unittest import TestCase, skip # NOQA
from pelican.contents import Page from pelican.contents import Page
from pelican.settings import _DEFAULT_CONFIG from pelican.settings import _DEFAULT_CONFIG
@ -14,7 +11,8 @@ from jinja2.utils import generate_lorem_ipsum
TEST_CONTENT = str(generate_lorem_ipsum(n=1)) TEST_CONTENT = str(generate_lorem_ipsum(n=1))
TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False) TEST_SUMMARY = generate_lorem_ipsum(n=1, html=False)
class TestPage(TestCase):
class TestPage(unittest.TestCase):
def setUp(self): def setUp(self):
super(TestPage, self).setUp() super(TestPage, self).setUp()
@ -117,7 +115,6 @@ class TestPage(TestCase):
try: try:
page = Page(**page_kwargs) page = Page(**page_kwargs)
self.assertEqual(page.locale_date, u'2015-09-13(\u65e5)') self.assertEqual(page.locale_date, u'2015-09-13(\u65e5)')
# above is unicode in Japanese: 2015-09-13(“ú)
except locale_module.Error: except locale_module.Error:
# The constructor of ``Page`` will try to set the locale to # The constructor of ``Page`` will try to set the locale to
# ``ja_JP.utf8``. But this attempt will failed when there is no # ``ja_JP.utf8``. But this attempt will failed when there is no
@ -126,4 +123,4 @@ class TestPage(TestCase):
# #
# Until we find some other method to test this functionality, we # Until we find some other method to test this functionality, we
# will simply skip this test. # will simply skip this test.
skip("There is no locale %s in this system." % locale) unittest.skip("There is no locale %s in this system." % locale)

View file

@ -1,13 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
try:
import unittest2 as unittest from mock import MagicMock
except ImportError, e:
import unittest # NOQA
from pelican.generators import ArticlesGenerator from pelican.generators import ArticlesGenerator
from pelican.settings import _DEFAULT_CONFIG from pelican.settings import _DEFAULT_CONFIG
from .support import unittest
from mock import MagicMock
class TestArticlesGenerator(unittest.TestCase): class TestArticlesGenerator(unittest.TestCase):

View file

@ -1,7 +1,7 @@
import unittest import unittest
import os import os
from support import temporary_folder from .support import temporary_folder
from pelican import Pelican from pelican import Pelican
from pelican.settings import read_settings from pelican.settings import read_settings

View file

@ -1,13 +1,10 @@
# coding: utf-8 # coding: utf-8
try:
import unittest2 as unittest
except ImportError, e:
import unittest
import datetime import datetime
import os import os
from pelican import readers from pelican import readers
from .support import unittest
CUR_DIR = os.path.dirname(__file__) CUR_DIR = os.path.dirname(__file__)
CONTENT_PATH = os.path.join(CUR_DIR, 'content') CONTENT_PATH = os.path.join(CUR_DIR, 'content')

View file

@ -1,14 +1,10 @@
try:
import unittest2
except ImportError, e:
import unittest as unittest2
from os.path import dirname, abspath, join from os.path import dirname, abspath, join
from pelican.settings import read_settings, _DEFAULT_CONFIG from pelican.settings import read_settings, _DEFAULT_CONFIG
from .support import unittest
class TestSettingsFromFile(unittest2.TestCase): class TestSettingsFromFile(unittest.TestCase):
"""Providing a file, it should read it, replace the default values and """Providing a file, it should read it, replace the default values and
append new values to the settings, if any append new values to the settings, if any
""" """

View file

@ -1,15 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
try:
import unittest2 as unittest
except ImportError:
import unittest # NOQA
import os import os
import datetime import datetime
import time import time
from pelican import utils from pelican import utils
from support import get_article from .support import get_article, unittest
class TestUtils(unittest.TestCase): class TestUtils(unittest.TestCase):