diff options
| author | 2014-10-21 10:33:17 -0300 | |
|---|---|---|
| committer | 2014-10-21 10:33:17 -0300 | |
| commit | 2d14c4b384c7000e264674a92b16e010a510ac05 (patch) | |
| tree | 7676db09f338e46e053170b1c9f7594120b9d434 /tests/test_integration.py | |
| parent | 2d2e97ac540c94e15ac5eccc7d32f3dfb3eea1bc (diff) | |
| parent | 5ec02211214350ee558fd9f6bb052264fd24f75e (diff) | |
Merge tag 'upstream/7.1.0'
Upstream version 7.1.0
Diffstat (limited to 'tests/test_integration.py')
| -rw-r--r-- | tests/test_integration.py | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/tests/test_integration.py b/tests/test_integration.py index 9f982d8..28b2965 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,13 +1,10 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals, print_function, absolute_import -# This code is so you can run the samples without installing the package, -# and should be before any import touching nikola, in any file under tests/ import os import sys -sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) -import codecs +import io import locale import shutil import subprocess @@ -21,8 +18,11 @@ from nikola import __main__ import nikola import nikola.plugins.command import nikola.plugins.command.init +import nikola.utils -from .base import BaseTestCase, cd +from .base import BaseTestCase, cd, LocaleSupportInTesting + +LocaleSupportInTesting.initialize() class EmptyBuildTest(BaseTestCase): @@ -33,6 +33,8 @@ class EmptyBuildTest(BaseTestCase): @classmethod def setUpClass(cls): """Setup a demo site.""" + # for tests that need bilingual support override languaje_settings + cls.languaje_settings() cls.startdir = os.getcwd() cls.tmpdir = tempfile.mkdtemp() cls.target_dir = os.path.join(cls.tmpdir, "target") @@ -42,6 +44,10 @@ class EmptyBuildTest(BaseTestCase): cls.build() @classmethod + def languaje_settings(cls): + LocaleSupportInTesting.initialize_locales_for_testing("unilingual") + + @classmethod def fill_site(self): """Add any needed initial content.""" self.init_command.create_empty_site(self.target_dir) @@ -79,6 +85,10 @@ class EmptyBuildTest(BaseTestCase): del sys.modules['conf'] except KeyError: pass + # clear LocaleBorg state + nikola.utils.LocaleBorg.reset() + if hasattr(self.__class__, "ol"): + delattr(self.__class__, "ol") def test_build(self): """Ensure the build did something.""" @@ -96,7 +106,7 @@ class DemoBuildTest(EmptyBuildTest): self.init_command.copy_sample_site(self.target_dir) self.init_command.create_configuration(self.target_dir) # File for Issue #374 (empty post text) - with codecs.open(os.path.join(self.target_dir, 'posts', 'empty.txt'), "wb+", "utf8") as outf: + with io.open(os.path.join(self.target_dir, 'posts', 'empty.txt'), "w+", encoding="utf8") as outf: outf.write( ".. title: foobar\n" ".. slug: foobar\n" @@ -105,12 +115,12 @@ class DemoBuildTest(EmptyBuildTest): def test_index_in_sitemap(self): sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml") - sitemap_data = codecs.open(sitemap_path, "r", "utf8").read() + sitemap_data = io.open(sitemap_path, "r", encoding="utf8").read() self.assertTrue('<loc>http://getnikola.com/index.html</loc>' in sitemap_data) def test_avoid_double_slash_in_rss(self): rss_path = os.path.join(self.target_dir, "output", "rss.xml") - rss_data = codecs.open(rss_path, "r", "utf8").read() + rss_data = io.open(rss_path, "r", encoding="utf8").read() self.assertFalse('http://getnikola.com//' in rss_data) @@ -120,7 +130,7 @@ class RepeatedPostsSetting(DemoBuildTest): def patch_site(self): """Set the SITE_URL to have a path""" conf_path = os.path.join(self.target_dir, "conf.py") - with codecs.open(conf_path, "ab", "utf8") as outf: + with io.open(conf_path, "a", encoding="utf8") as outf: outf.write('\nPOSTS = (("posts/*.txt", "posts", "post.tmpl"),("posts/*.txt", "posts", "post.tmpl"))\n') @@ -135,17 +145,17 @@ class FuturePostTest(EmptyBuildTest): self.init_command.create_configuration(self.target_dir) # Change COMMENT_SYSTEM_ID to not wait for 5 seconds - with codecs.open(os.path.join(self.target_dir, 'conf.py'), "ab+", "utf8") as outf: + with io.open(os.path.join(self.target_dir, 'conf.py'), "a+", encoding="utf8") as outf: outf.write('\nCOMMENT_SYSTEM_ID = "nikolatest"\n') - with codecs.open(os.path.join(self.target_dir, 'posts', 'empty1.txt'), "wb+", "utf8") as outf: + with io.open(os.path.join(self.target_dir, 'posts', 'empty1.txt'), "w+", encoding="utf8") as outf: outf.write( ".. title: foo\n" ".. slug: foo\n" ".. date: %s\n" % (current_time() + datetime.timedelta(-1)).strftime('%Y-%m-%d %H:%M:%S') ) - with codecs.open(os.path.join(self.target_dir, 'posts', 'empty2.txt'), "wb+", "utf8") as outf: + with io.open(os.path.join(self.target_dir, 'posts', 'empty2.txt'), "w+", encoding="utf8") as outf: outf.write( ".. title: bar\n" ".. slug: bar\n" @@ -161,8 +171,8 @@ class FuturePostTest(EmptyBuildTest): self.assertTrue(os.path.isfile(index_path)) self.assertTrue(os.path.isfile(foo_path)) self.assertTrue(os.path.isfile(bar_path)) - index_data = codecs.open(index_path, "r", "utf8").read() - sitemap_data = codecs.open(sitemap_path, "r", "utf8").read() + index_data = io.open(index_path, "r", encoding="utf8").read() + sitemap_data = io.open(sitemap_path, "r", encoding="utf8").read() self.assertTrue('foo.html' in index_data) self.assertFalse('bar.html' in index_data) self.assertTrue('foo.html' in sitemap_data) @@ -182,34 +192,24 @@ class TranslatedBuildTest(EmptyBuildTest): dataname = "translated_titles" - def __init__(self, *a, **kw): - super(TranslatedBuildTest, self).__init__(*a, **kw) - try: - self.oldlocale = locale.getlocale() - locale.setlocale(locale.LC_ALL, ("pl_PL", "utf8")) - except: - pytest.skip() - @classmethod - def tearDownClass(self): - try: - locale.setlocale(locale.LC_ALL, self.oldlocale) - except: - pass - super(TranslatedBuildTest, self).tearDownClass() + def languaje_settings(cls): + LocaleSupportInTesting.initialize_locales_for_testing("bilingual") + # the other languaje + cls.ol = LocaleSupportInTesting.langlocales["other"][0] def test_translated_titles(self): """Check that translated title is picked up.""" en_file = os.path.join(self.target_dir, "output", "stories", "1.html") - pl_file = os.path.join(self.target_dir, "output", "pl", "stories", "1.html") + pl_file = os.path.join(self.target_dir, "output", self.ol, "stories", "1.html") # Files should be created self.assertTrue(os.path.isfile(en_file)) self.assertTrue(os.path.isfile(pl_file)) # And now let's check the titles - with codecs.open(en_file, 'r', 'utf8') as inf: + with io.open(en_file, 'r', encoding='utf8') as inf: doc = lxml.html.parse(inf) self.assertEqual(doc.find('//title').text, 'Foo | Demo Site') - with codecs.open(pl_file, 'r', 'utf8') as inf: + with io.open(pl_file, 'r', encoding='utf8') as inf: doc = lxml.html.parse(inf) self.assertEqual(doc.find('//title').text, 'Bar | Demo Site') @@ -220,15 +220,15 @@ class TranslationsPatternTest1(TranslatedBuildTest): @classmethod def patch_site(self): """Set the TRANSLATIONS_PATTERN to the old v6 default""" - os.rename(os.path.join(self.target_dir, "stories", "1.pl.txt"), - os.path.join(self.target_dir, "stories", "1.txt.pl") + os.rename(os.path.join(self.target_dir, "stories", "1.%s.txt" % self.ol), + os.path.join(self.target_dir, "stories", "1.txt.%s" % self.ol) ) conf_path = os.path.join(self.target_dir, "conf.py") - with codecs.open(conf_path, "rb", "utf-8") as inf: + with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() data = data.replace('TRANSLATIONS_PATTERN = "{path}.{lang}.{ext}"', 'TRANSLATIONS_PATTERN = "{path}.{ext}.{lang}"') - with codecs.open(conf_path, "wb+", "utf8") as outf: + with io.open(conf_path, "w+", encoding="utf8") as outf: outf.write(data) @@ -252,14 +252,14 @@ class TranslationsPatternTest2(TranslatedBuildTest): def patch_site(self): """Set the TRANSLATIONS_PATTERN to the old v6 default""" conf_path = os.path.join(self.target_dir, "conf.py") - os.rename(os.path.join(self.target_dir, "stories", "1.pl.txt"), - os.path.join(self.target_dir, "stories", "1.txt.pl") + os.rename(os.path.join(self.target_dir, "stories", "1.%s.txt" % self.ol), + os.path.join(self.target_dir, "stories", "1.txt.%s" % self.ol) ) - with codecs.open(conf_path, "rb", "utf-8") as inf: + with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() data = data.replace('TRANSLATIONS_PATTERN = "{path}.{lang}.{ext}"', 'TRANSLATIONS_PATTERN = "{path}.{ext}.{lang}"') - with codecs.open(conf_path, "wb+", "utf8") as outf: + with io.open(conf_path, "w+", encoding="utf8") as outf: outf.write(data) @@ -270,11 +270,11 @@ class RelativeLinkTest(DemoBuildTest): def patch_site(self): """Set the SITE_URL to have a path""" conf_path = os.path.join(self.target_dir, "conf.py") - with codecs.open(conf_path, "rb", "utf-8") as inf: + with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() data = data.replace('SITE_URL = "http://getnikola.com/"', 'SITE_URL = "http://getnikola.com/foo/bar/"') - with codecs.open(conf_path, "wb+", "utf8") as outf: + with io.open(conf_path, "w+", encoding="utf8") as outf: outf.write(data) def test_relative_links(self): @@ -294,7 +294,7 @@ class RelativeLinkTest(DemoBuildTest): def test_index_in_sitemap(self): """Test that the correct path is in sitemap, and not the wrong one.""" sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml") - sitemap_data = codecs.open(sitemap_path, "r", "utf8").read() + sitemap_data = io.open(sitemap_path, "r", encoding="utf8").read() self.assertFalse('<loc>http://getnikola.com/</loc>' in sitemap_data) self.assertTrue('<loc>http://getnikola.com/foo/bar/index.html</loc>' in sitemap_data) @@ -327,20 +327,20 @@ class TestCheckAbsoluteSubFolder(TestCheck): @classmethod def patch_site(self): conf_path = os.path.join(self.target_dir, "conf.py") - with codecs.open(conf_path, "rb", "utf-8") as inf: + with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() data = data.replace('SITE_URL = "http://getnikola.com/"', 'SITE_URL = "http://getnikola.com/foo/"') data = data.replace("# URL_TYPE = 'rel_path'", "URL_TYPE = 'absolute'") - with codecs.open(conf_path, "wb+", "utf8") as outf: + with io.open(conf_path, "w+", encoding="utf8") as outf: outf.write(data) outf.flush() def test_index_in_sitemap(self): """Test that the correct path is in sitemap, and not the wrong one.""" sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml") - sitemap_data = codecs.open(sitemap_path, "r", "utf8").read() + sitemap_data = io.open(sitemap_path, "r", encoding="utf8").read() self.assertTrue('<loc>http://getnikola.com/foo/index.html</loc>' in sitemap_data) @@ -354,13 +354,13 @@ class TestCheckFullPathSubFolder(TestCheckAbsoluteSubFolder): @classmethod def patch_site(self): conf_path = os.path.join(self.target_dir, "conf.py") - with codecs.open(conf_path, "rb", "utf-8") as inf: + with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() data = data.replace('SITE_URL = "http://getnikola.com/"', 'SITE_URL = "http://getnikola.com/foo/"') data = data.replace("# URL_TYPE = 'rel_path'", "URL_TYPE = 'full_path'") - with codecs.open(conf_path, "wb+", "utf8") as outf: + with io.open(conf_path, "w+", encoding="utf8") as outf: outf.write(data) outf.flush() @@ -378,7 +378,7 @@ class TestCheckFailure(DemoBuildTest): def test_check_files_fail(self): with cd(self.target_dir): - with codecs.open(os.path.join("output", "foobar"), "wb+", "utf8") as outf: + with io.open(os.path.join("output", "foobar"), "w+", encoding="utf8") as outf: outf.write("foo") try: __main__.main(['check', '-f']) @@ -393,7 +393,7 @@ class RelativeLinkTest2(DemoBuildTest): def patch_site(self): """Set the SITE_URL to have a path""" conf_path = os.path.join(self.target_dir, "conf.py") - with codecs.open(conf_path, "rb", "utf-8") as inf: + with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() data = data.replace('("stories/*.txt", "stories", "story.tmpl"),', '("stories/*.txt", "", "story.tmpl"),') @@ -401,7 +401,7 @@ class RelativeLinkTest2(DemoBuildTest): '("stories/*.rst", "", "story.tmpl"),') data = data.replace('# INDEX_PATH = ""', 'INDEX_PATH = "blog"') - with codecs.open(conf_path, "wb+", "utf8") as outf: + with io.open(conf_path, "w+", encoding="utf8") as outf: outf.write(data) outf.flush() @@ -422,7 +422,7 @@ class RelativeLinkTest2(DemoBuildTest): def test_index_in_sitemap(self): """Test that the correct path is in sitemap, and not the wrong one.""" sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml") - sitemap_data = codecs.open(sitemap_path, "r", "utf8").read() + sitemap_data = io.open(sitemap_path, "r", encoding="utf8").read() self.assertFalse('<loc>http://getnikola.com/</loc>' in sitemap_data) self.assertTrue('<loc>http://getnikola.com/blog/index.html</loc>' in sitemap_data) @@ -434,11 +434,11 @@ class MonthlyArchiveTest(DemoBuildTest): def patch_site(self): """Set the SITE_URL to have a path""" conf_path = os.path.join(self.target_dir, "conf.py") - with codecs.open(conf_path, "rb", "utf-8") as inf: + with io.open(conf_path, "r", encoding="utf-8") as inf: data = inf.read() data = data.replace('# CREATE_MONTHLY_ARCHIVE = False', 'CREATE_MONTHLY_ARCHIVE = True') - with codecs.open(conf_path, "wb+", "utf8") as outf: + with io.open(conf_path, "w+", encoding="utf8") as outf: outf.write(data) outf.flush() |
