Skip to content
Permalink
Browse files
Merge pull request #1897 from getnikola/mock-1.1.4
Mock 1.1.4
  • Loading branch information
Kwpolska committed Jul 20, 2015
2 parents e5c0122 + 72083ce commit 105446b7b6c30f3dde83cf13c94d11bfeeddecb6
Showing with 47 additions and 46 deletions.
  1. +1 −0 CHANGES.txt
  2. +5 −2 nikola/post.py
  3. +1 −1 requirements-tests.txt
  4. +8 −13 tests/test_command_import_wordpress.py
  5. +6 −3 tests/test_rss_feeds.py
  6. +26 −27 tests/test_utils.py
@@ -4,6 +4,7 @@ New in master
Bugfixes
--------

* Fix reSt and markdown title extraction from documents (Issue #1895)
* Minor improvements in the extending document.
* Re-add the hack to kill nikola auto on ^C (Issue #1893)

@@ -853,10 +853,12 @@ def _get_metadata_from_file(meta_data):
False
>>> 'title' in g(["",".. title: FooBar"]) # for #520
True
>>> 'title' in g([".. foo: bar","","FooBar", "------"]) # for #1895
True
"""
meta = {}

seen_meta_flag = False
re_md_title = re.compile(r'^{0}([^{0}].*)'.format(re.escape('#')))
# Assuming rst titles are going to be at least 4 chars long
# otherwise this detects things like ''' wich breaks other markups.
@@ -868,7 +870,7 @@ def _get_metadata_from_file(meta_data):
# and since we are here because it's a 1-file post
# let's be flexible on what we accept, so, skip empty
# first lines.
if not line and i > 0:
if not line and not seen_meta_flag and i > 0:
break
if 'title' not in meta:
match = re_meta(line, 'title')
@@ -888,6 +890,7 @@ def _get_metadata_from_file(meta_data):
match = re_meta(line)
if match[0]:
meta[match[0]] = match[1]
seen_meta_flag = True

return meta

@@ -1,5 +1,5 @@
-r requirements-extras.txt
mock==1.1.3
mock==1.1.4
coverage==3.7.1
pytest==2.7.2
pytest-cov==1.8.1
@@ -2,8 +2,6 @@
from __future__ import unicode_literals, absolute_import

import os
import sys


import unittest
import mock
@@ -441,21 +439,18 @@ def test_get_configuration_output_path(self):
self.assertTrue(self.import_command.name in config_path_with_timestamp)

def test_write_content_does_not_detroy_text(self):
content = b"""<h1>Installation</h1>
Follow the instructions <a title="Installing Jenkins" href="https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins">described here</a>.
<h1>Plugins</h1>
There are many plugins.
<h2>Violations</h2>
You can use the <a title="Jenkins Plugin: Violations" href="https://wiki.jenkins-ci.org/display/JENKINS/Violations">Violations</a> plugin."""
content = b"""FOO"""
open_mock = mock.mock_open()
with mock.patch('nikola.plugins.basic_import.open', open_mock, create=True):
self.import_command.write_content('some_file', content)

open_mock.assert_called_once_with('some_file', 'wb+')
call_context = open_mock()
call_context.write.assert_called_once_with(
content.join([b'<html><body>', b'</body></html>']))
#import pdb; pdb.set_trace()
open_mock.assert_has_calls([
mock.call(u'some_file', u'wb+'),
mock.call().__enter__(),
mock.call().write(b'<html><body><p>FOO</p></body></html>'),
mock.call().__exit__(None, None, None)]
)

def test_configure_redirections(self):
"""
@@ -91,9 +91,12 @@ def setUp(self):
# lxml will complain if the encoding is specified in the
# xml when running with unicode strings.
# We do not include this in our content.
open_handle = opener_mock()
file_content = [call[1][0]
for call in open_handle.mock_calls[1:-1]][0]
try:
file_content = [
call[1][0]
for call in opener_mock.mock_calls[2:-1]][0]
except IndexError:
import pdb; pdb.set_trace()
splitted_content = file_content.split('\n')
self.encoding_declaration = splitted_content[0]
content_without_encoding_declaration = splitted_content[1:]
@@ -18,13 +18,13 @@ class dummy(object):

class GetMetaTest(unittest.TestCase):
def test_getting_metadata_from_content(self):
file_metadata = [".. title: Nikola needs more tests!\n",
".. slug: write-tests-now\n",
".. date: 2012/09/15 19:52:05\n",
".. tags:\n",
".. link:\n",
".. description:\n",
"Post content\n"]
file_metadata = ".. title: Nikola needs more tests!\n"\
".. slug: write-tests-now\n"\
".. date: 2012/09/15 19:52:05\n"\
".. tags:\n"\
".. link:\n"\
".. description:\n"\
"Post content\n"

opener_mock = mock.mock_open(read_data=file_metadata)
opener_mock.return_value.readlines.return_value = file_metadata
@@ -45,13 +45,13 @@ def test_getting_metadata_from_content(self):
self.assertTrue(nsm)

def test_get_title_from_rest(self):
file_metadata = [".. slug: write-tests-now\n",
".. date: 2012/09/15 19:52:05\n",
".. tags:\n",
".. link:\n",
".. description:\n",
"Post Title\n",
"----------\n"]
file_metadata = ".. slug: write-tests-now\n"\
".. date: 2012/09/15 19:52:05\n"\
".. tags:\n"\
".. link:\n"\
".. description:\n\n"\
"Post Title\n"\
"----------\n"

opener_mock = mock.mock_open(read_data=file_metadata)
opener_mock.return_value.readlines.return_value = file_metadata
@@ -72,11 +72,11 @@ def test_get_title_from_rest(self):
self.assertTrue(nsm)

def test_get_title_from_fname(self):
file_metadata = [".. slug: write-tests-now\n",
".. date: 2012/09/15 19:52:05\n",
".. tags:\n",
".. link:\n",
".. description:\n"]
file_metadata = ".. slug: write-tests-now\n"\
".. date: 2012/09/15 19:52:05\n"\
".. tags:\n"\
".. link:\n"\
".. description:\n"

opener_mock = mock.mock_open(read_data=file_metadata)
opener_mock.return_value.readlines.return_value = file_metadata
@@ -97,12 +97,12 @@ def test_get_title_from_fname(self):
self.assertTrue(nsm)

def test_use_filename_as_slug_fallback(self):
file_metadata = [".. title: Nikola needs more tests!\n",
".. date: 2012/09/15 19:52:05\n",
".. tags:\n",
".. link:\n",
".. description:\n",
"Post content\n"]
file_metadata = ".. title: Nikola needs more tests!\n"\
".. date: 2012/09/15 19:52:05\n"\
".. tags:\n"\
".. link:\n"\
".. description:\n\n"\
"Post content\n"

opener_mock = mock.mock_open(read_data=file_metadata)
opener_mock.return_value.readlines.return_value = file_metadata
@@ -113,7 +113,6 @@ def test_use_filename_as_slug_fallback(self):

with mock.patch('nikola.post.io.open', opener_mock, create=True):
meta, nsm = get_meta(post, 'Slugify this')

self.assertEqual('Nikola needs more tests!', meta['title'])
self.assertEqual('slugify-this', meta['slug'])
self.assertEqual('2012/09/15 19:52:05', meta['date'])
@@ -250,7 +249,7 @@ def test_string_input(self):
except NameError: # Python 3
u = str(S)

cn = S() # no language specified
cn = S() # no language specified
cr = S('xx') # real language specified
cf = S('zz') # fake language specified

0 comments on commit 105446b

Please sign in to comment.