aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2014-10-21 10:33:15 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2014-10-21 10:33:15 -0300
commit5ec02211214350ee558fd9f6bb052264fd24f75e (patch)
treeb61e8c61a95d18a91d053e71dcbd7b30e47552a1 /tests
parent58c4878526dec5510f23c812274686787d8724ba (diff)
Imported Upstream version 7.1.0upstream/7.1.0
Diffstat (limited to 'tests')
-rw-r--r--tests/base.py3
-rw-r--r--tests/test_command_import_wordpress.py4
-rw-r--r--tests/test_command_init.py3
-rw-r--r--tests/test_commands.py3
-rw-r--r--tests/test_compile_markdown.py9
-rw-r--r--tests/test_integration.py106
-rw-r--r--tests/test_locale.py3
-rw-r--r--tests/test_plugin_importing.py3
-rw-r--r--tests/test_rss_feeds.py44
-rw-r--r--tests/test_rst_compiler.py11
-rw-r--r--tests/test_scheduling.py8
-rw-r--r--tests/test_utils.py15
12 files changed, 90 insertions, 122 deletions
diff --git a/tests/base.py b/tests/base.py
index c22fbb2..a244f6a 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -9,11 +9,8 @@
__all__ = ["BaseTestCase", "cd", "LocaleSupportInTesting"]
-# 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__), '..'))
from contextlib import contextmanager
diff --git a/tests/test_command_import_wordpress.py b/tests/test_command_import_wordpress.py
index 1a2e7d9..fafb10c 100644
--- a/tests/test_command_import_wordpress.py
+++ b/tests/test_command_import_wordpress.py
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, 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 unittest
@@ -216,6 +213,7 @@ class CommandImportWordpressTest(BasicCommandImportWordpress):
self.import_filename)
self.import_command.context = self.import_command.populate_context(
channel)
+ self.import_command.base_dir = ''
self.import_command.output_folder = 'new_site'
self.import_command.squash_newlines = True
self.import_command.no_downloads = False
diff --git a/tests/test_command_init.py b/tests/test_command_init.py
index d2171f8..9270497 100644
--- a/tests/test_command_init.py
+++ b/tests/test_command_init.py
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, 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 unittest
import mock
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 5c2370a..d70d164 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, 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 unittest
diff --git a/tests/test_compile_markdown.py b/tests/test_compile_markdown.py
index ace17cf..47cbdbb 100644
--- a/tests/test_compile_markdown.py
+++ b/tests/test_compile_markdown.py
@@ -1,14 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-# 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 shutil
import tempfile
import unittest
@@ -28,13 +25,13 @@ class CompileMarkdownTests(BaseTestCase):
self.compiler.set_site(FakeSite())
def compile(self, input_string):
- with codecs.open(self.input_path, "w+", "utf8") as input_file:
+ with io.open(self.input_path, "w+", encoding="utf8") as input_file:
input_file.write(input_string)
self.compiler.compile_html(self.input_path, self.output_path)
output_str = None
- with codecs.open(self.output_path, "r", "utf8") as output_path:
+ with io.open(self.output_path, "r", encoding="utf8") as output_path:
output_str = output_path.read()
return output_str
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()
diff --git a/tests/test_locale.py b/tests/test_locale.py
index 90f9edb..d24fdfb 100644
--- a/tests/test_locale.py
+++ b/tests/test_locale.py
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-# 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__), '..'))
# needed if @unittest.expectedFailure is used
diff --git a/tests/test_plugin_importing.py b/tests/test_plugin_importing.py
index aaba113..f41a1fd 100644
--- a/tests/test_plugin_importing.py
+++ b/tests/test_plugin_importing.py
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, 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 unittest
diff --git a/tests/test_rss_feeds.py b/tests/test_rss_feeds.py
index 3554a38..5eeb570 100644
--- a/tests/test_rss_feeds.py
+++ b/tests/test_rss_feeds.py
@@ -2,11 +2,8 @@
from __future__ import unicode_literals, 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__), '..'))
from collections import defaultdict
@@ -35,22 +32,25 @@ fake_conf['TRANSLATIONS_PATTERN'] = '{path}.{lang}.{ext}'
class FakeCompiler(object):
demote_headers = False
compile_html = None
+ extension = lambda self: '.html'
class RSSFeedTest(unittest.TestCase):
def setUp(self):
LocaleSupportInTesting.initialize_locales_for_testing('unilingual')
-
self.blog_url = "http://some.blog"
with mock.patch('nikola.post.get_meta',
- mock.Mock(return_value=({'title': 'post title',
- 'slug': 'awesome_article',
- 'date': '2012-10-01 22:41',
- 'author': None,
- 'tags': 'tags', 'link':
- 'link', 'description':
- 'description'}))):
+ mock.Mock(return_value=(
+ {'title': 'post title',
+ 'slug': 'awesome_article',
+ 'date': '2012-10-01 22:41',
+ 'author': None,
+ 'tags': 'tags',
+ 'link': 'link',
+ 'description': 'description',
+ 'enclosure': 'http://www.example.org/foo.mp3'}
+ ))):
with mock.patch('nikola.nikola.utils.os.path.isdir',
mock.Mock(return_value=True)):
with mock.patch('nikola.nikola.Post.text',
@@ -66,19 +66,19 @@ class RSSFeedTest(unittest.TestCase):
opener_mock = mock.mock_open()
- with mock.patch('nikola.nikola.codecs.open', opener_mock, create=True):
- nikola.nikola.utils.generic_rss_renderer('en',
- "blog_title",
- self.blog_url,
- "blog_description",
- [example_post,
- ],
- 'testfeed.rss',
- True,
- False)
+ with mock.patch('nikola.nikola.io.open', opener_mock, create=True):
+ nikola.nikola.Nikola().generic_rss_renderer('en',
+ "blog_title",
+ self.blog_url,
+ "blog_description",
+ [example_post,
+ ],
+ 'testfeed.rss',
+ True,
+ False)
opener_mock.assert_called_once_with(
- 'testfeed.rss', 'wb+', 'utf-8')
+ 'testfeed.rss', 'w+', encoding='utf-8')
# Python 3 / unicode strings workaround
# lxml will complain if the encoding is specified in the
diff --git a/tests/test_rst_compiler.py b/tests/test_rst_compiler.py
index 379aba2..1747332 100644
--- a/tests/test_rst_compiler.py
+++ b/tests/test_rst_compiler.py
@@ -27,14 +27,11 @@ always unquoted.
from __future__ import unicode_literals, 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
try:
from io import StringIO
except ImportError:
@@ -76,15 +73,15 @@ class ReSTExtensionTestCase(BaseTestCase):
inf = os.path.join(tmpdir, 'inf')
outf = os.path.join(tmpdir, 'outf')
depf = os.path.join(tmpdir, 'outf.dep')
- with codecs.open(inf, 'wb+', 'utf8') as f:
+ with io.open(inf, 'w+', encoding='utf8') as f:
f.write(rst)
self.html = self.compiler.compile_html(inf, outf)
- with codecs.open(outf, 'r', 'utf8') as f:
+ with io.open(outf, 'r', encoding='utf8') as f:
self.html = f.read()
os.unlink(inf)
os.unlink(outf)
if os.path.isfile(depf):
- with codecs.open(depf, 'r', 'utf8') as f:
+ with io.open(depf, 'r', encoding='utf8') as f:
self.assertEqual(self.deps, f.read())
os.unlink(depf)
else:
diff --git a/tests/test_scheduling.py b/tests/test_scheduling.py
index ae1cf92..fddb4ff 100644
--- a/tests/test_scheduling.py
+++ b/tests/test_scheduling.py
@@ -5,9 +5,6 @@ import datetime
import locale
import os
import sys
-# 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/
-sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import dateutil.parser
import dateutil.tz
@@ -46,10 +43,7 @@ class TestScheduling(BaseTestCase):
def test_get_date(self):
from nikola.plugins.command.new_post import get_date
- FMT = '%Y-%m-%d %H:%M:%S %Z'.format(
- locale.nl_langinfo(locale.D_FMT),
- locale.nl_langinfo(locale.T_FMT),
- )
+ FMT = '%Y-%m-%d %H:%M:%S %Z'
NOW = _NOW.strftime(FMT)
TODAY = dateutil.parser.parse(NOW)
RULE_TH = 'RRULE:FREQ=WEEKLY;BYDAY=TH'
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 44d309b..c392c02 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-# 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 unittest
@@ -36,7 +33,7 @@ class GetMetaTest(unittest.TestCase):
post.source_path = 'file_with_metadata'
post.metadata_path = 'file_with_metadata.meta'
- with mock.patch('nikola.post.codecs.open', opener_mock, create=True):
+ with mock.patch('nikola.post.io.open', opener_mock, create=True):
meta = get_meta(post)
self.assertEqual('Nikola needs more tests!', meta['title'])
@@ -62,7 +59,7 @@ class GetMetaTest(unittest.TestCase):
post.source_path = 'file_with_metadata'
post.metadata_path = 'file_with_metadata.meta'
- with mock.patch('nikola.post.codecs.open', opener_mock, create=True):
+ with mock.patch('nikola.post.io.open', opener_mock, create=True):
meta = get_meta(post)
self.assertEqual('Post Title', meta['title'])
@@ -86,7 +83,7 @@ class GetMetaTest(unittest.TestCase):
post.source_path = 'file_with_metadata'
post.metadata_path = 'file_with_metadata.meta'
- with mock.patch('nikola.post.codecs.open', opener_mock, create=True):
+ with mock.patch('nikola.post.io.open', opener_mock, create=True):
meta = get_meta(post, 'file_with_metadata')
self.assertEqual('file_with_metadata', meta['title'])
@@ -111,7 +108,7 @@ class GetMetaTest(unittest.TestCase):
post.source_path = 'Slugify this'
post.metadata_path = 'Slugify this.meta'
- with mock.patch('nikola.post.codecs.open', opener_mock, create=True):
+ with mock.patch('nikola.post.io.open', opener_mock, create=True):
meta = get_meta(post, 'Slugify this')
self.assertEqual('Nikola needs more tests!', meta['title'])
@@ -125,7 +122,7 @@ class GetMetaTest(unittest.TestCase):
post = dummy()
post.source_path = '2013-01-23-the_slug-dubdubtitle.md'
post.metadata_path = '2013-01-23-the_slug-dubdubtitle.meta'
- with mock.patch('nikola.post.codecs.open', create=True):
+ with mock.patch('nikola.post.io.open', create=True):
meta = get_meta(
post,
'(?P<date>\d{4}-\d{2}-\d{2})-(?P<slug>.*)-(?P<title>.*)\.md')
@@ -138,7 +135,7 @@ class GetMetaTest(unittest.TestCase):
post = dummy()
post.source_path = 'some/path/the_slug.md'
post.metadata_path = 'some/path/the_slug.meta'
- with mock.patch('nikola.post.codecs.open', create=True):
+ with mock.patch('nikola.post.io.open', create=True):
meta = get_meta(post)
self.assertEqual('the_slug', meta['slug'])