Skip to content

Commit

Permalink
use one FakeSite; fix bugs in markdown plugin magic
Browse files Browse the repository at this point in the history
Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Mar 27, 2014
1 parent dd5cc48 commit 29d90ab
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 92 deletions.
6 changes: 3 additions & 3 deletions nikola/plugin_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ class RestExtension(BasePlugin):

class MarkdownExtension(BasePlugin):
name = "dummy_markdown_extension"

def set_site(self, site):
self.site = site
m = site.plugin_manager.getPluginByName('markdown', 'PageCompiler')
m.plugin_object.extensions.append(self)
from nikola.plugins.compile.markdown import CompileMarkdown
CompileMarkdown.extensions.append(self)
return super(MarkdownExtension, self).set_site(site)


Expand Down
78 changes: 76 additions & 2 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@

import logbook

# Make logbook shutup
import nikola.utils

nikola.utils.LOGGER.handlers.append(logbook.TestHandler())

from yapsy.PluginManager import PluginManager
from nikola.plugin_categories import (
Command,
Task,
LateTask,
TemplateSystem,
PageCompiler,
TaskMultiplier,
RestExtension,
MarkdownExtension
)


if sys.version_info < (2, 7):

Expand Down Expand Up @@ -167,3 +177,67 @@ def initialize_locales_for_testing(cls, variant):
raise ValueError('Unknown locale variant')
nikola.utils.LocaleBorg.reset()
nikola.utils.LocaleBorg.initialize(locales, default_lang)


class FakePost(object):

def __init__(self, title, slug):
self._title = title
self._slug = slug
self._meta = {'slug': slug}

def title(self):
return self._title

def meta(self, key):
return self._meta[key]

def permalink(self):
return '/posts/' + self._slug


class FakeSite(object):
def __init__(self):
self.template_system = self
self.invariant = False
self.config = {
'DISABLED_PLUGINS': [],
'EXTRA_PLUGINS': [],
'DEFAULT_LANG': 'en',
'MARKDOWN_EXTENSIONS': ['fenced_code', 'codehilite'],
}
self.EXTRA_PLUGINS = self.config['EXTRA_PLUGINS']
self.plugin_manager = PluginManager(categories_filter={
"Command": Command,
"Task": Task,
"LateTask": LateTask,
"TemplateSystem": TemplateSystem,
"PageCompiler": PageCompiler,
"TaskMultiplier": TaskMultiplier,
"RestExtension": RestExtension,
"MarkdownExtension": MarkdownExtension,
})
self.loghandlers = [nikola.utils.STDERR_HANDLER]
self.plugin_manager.setPluginInfoExtension('plugin')
if sys.version_info[0] == 3:
places = [
os.path.join(os.path.dirname(nikola.utils.__file__), 'plugins'),
]
else:
places = [
os.path.join(os.path.dirname(nikola.utils.__file__), nikola.utils.sys_encode('plugins')),
]
self.plugin_manager.setPluginPlaces(places)
self.plugin_manager.collectPlugins()

self.timeline = [
FakePost(title='Fake post',
slug='fake-post')
]
self.debug = True
# This is to make plugin initialization happy
self.template_system = self
self.name = 'mako'

def render_template(self, name, _, context):
return('<img src="IMG.jpg">')
14 changes: 2 additions & 12 deletions tests/test_compile_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,10 @@
from os import path

from nikola.plugins.compile.markdown import CompileMarkdown
from .base import BaseTestCase, FakeSite


class FakeSite(object):
def __init__(self):
self.config = {
"MARKDOWN_EXTENSIONS": ['fenced_code', 'codehilite'],
"LOGGING_HANDLERS": {'stderr': {'loglevel': 'WARNING', 'bubble': True}}
}
# This is to make plugin initialization happy
self.template_system = self
self.name = 'mako'


class CompileMarkdownTests(unittest.TestCase):
class CompileMarkdownTests(BaseTestCase):
def setUp(self):
self.tmp_dir = tempfile.mkdtemp()
self.input_path = path.join(self.tmp_dir, 'input.markdown')
Expand Down
77 changes: 2 additions & 75 deletions tests/test_rst_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,87 +45,14 @@
from lxml import html
import pytest
import unittest
from yapsy.PluginManager import PluginManager

from nikola import utils
import nikola.plugins.compile.rest
from nikola.plugins.compile.rest import gist
from nikola.plugins.compile.rest import vimeo
import nikola.plugins.compile.rest.listing
from nikola.plugins.compile.rest.doc import Plugin as DocPlugin
from nikola.utils import _reload, STDERR_HANDLER
from nikola.plugin_categories import (
Command,
Task,
LateTask,
TemplateSystem,
PageCompiler,
TaskMultiplier,
RestExtension,
)
from .base import BaseTestCase


class FakePost(object):

def __init__(self, title, slug):
self._title = title
self._slug = slug
self._meta = {'slug': slug}

def title(self):
return self._title

def meta(self, key):
return self._meta[key]

def permalink(self):
return '/posts/' + self._slug


class FakeSite(object):
def __init__(self):
self.template_system = self
self.invariant = False
self.config = {
'DISABLED_PLUGINS': [],
'EXTRA_PLUGINS': [],
'DEFAULT_LANG': 'en',
}
self.EXTRA_PLUGINS = self.config['EXTRA_PLUGINS']
self.plugin_manager = PluginManager(categories_filter={
"Command": Command,
"Task": Task,
"LateTask": LateTask,
"TemplateSystem": TemplateSystem,
"PageCompiler": PageCompiler,
"TaskMultiplier": TaskMultiplier,
"RestExtension": RestExtension,
})
self.loghandlers = [STDERR_HANDLER]
self.plugin_manager.setPluginInfoExtension('plugin')
if sys.version_info[0] == 3:
places = [
os.path.join(os.path.dirname(utils.__file__), 'plugins'),
]
else:
places = [
os.path.join(os.path.dirname(utils.__file__), utils.sys_encode('plugins')),
]
self.plugin_manager.setPluginPlaces(places)
self.plugin_manager.collectPlugins()

self.timeline = [
FakePost(title='Fake post',
slug='fake-post')
]
self.debug = True
# This is to make plugin initialization happy
self.template_system = self
self.name = 'mako'

def render_template(self, name, _, context):
return('<img src="IMG.jpg">')
from nikola.utils import _reload
from .base import BaseTestCase, FakeSite


class ReSTExtensionTestCase(BaseTestCase):
Expand Down

0 comments on commit 29d90ab

Please sign in to comment.