Skip to content

Commit

Permalink
Give the composers collection access to the configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Sep 10, 2015
1 parent 91e5e14 commit e71a252
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
3 changes: 2 additions & 1 deletion handroll/composers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def output_extension(self):
class Composers(object):
"""A collection of available composers"""

def __init__(self):
def __init__(self, config):
self._config = config
self._available_composers = {}
self._composers = {}
self.default_composer = CopyComposer()
Expand Down
2 changes: 1 addition & 1 deletion handroll/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, config, site, extensions):
self.site = site
self.extensions = extensions
self.catalog = catalog.TemplateCatalog(site.path)
self.composers = Composers()
self.composers = Composers(config)
self.resolver = FileResolver(site.path, self.composers, config)

@property
Expand Down
31 changes: 20 additions & 11 deletions handroll/tests/test_composers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import stat
import tempfile
import unittest

import mock

Expand All @@ -18,9 +17,10 @@
from handroll.composers.sass import SassComposer
from handroll.composers.txt import TextileComposer
from handroll.exceptions import AbortError
from handroll.tests import TestCase


class TestComposer(unittest.TestCase):
class TestComposer(TestCase):

def test_compose_not_implemented(self):
composer = Composer()
Expand All @@ -33,15 +33,24 @@ def test_output_extension_not_implemented(self):
NotImplementedError, lambda: composer.output_extension)


class TestComposers(unittest.TestCase):
class TestComposers(TestCase):

def _make_one(self):
config = self.factory.make_configuration()
return Composers(config)

def test_selects_composer(self):
composers = Composers()
composers = self._make_one()
composer = composers.select_composer_for('sample.md')
self.assertTrue(isinstance(composer, MarkdownComposer))

def test_has_config(self):
config = self.factory.make_configuration()
composers = Composers(config)
self.assertEqual(config, composers._config)


class TestAtomComposer(unittest.TestCase):
class TestAtomComposer(TestCase):

def setUp(self):
site = tempfile.mkdtemp()
Expand Down Expand Up @@ -91,7 +100,7 @@ def test_output_extension(self):
self.assertEqual('.xml', composer.output_extension)


class TestCopyComposer(unittest.TestCase):
class TestCopyComposer(TestCase):

@mock.patch('handroll.composers.shutil')
def test_skips_same_files(self, shutil):
Expand Down Expand Up @@ -128,7 +137,7 @@ def test_output_extension(self):
self.assertRaises(AttributeError, lambda: composer.output_extension)


class TestGenericHTMLComposer(unittest.TestCase):
class TestGenericHTMLComposer(TestCase):

def test_composes_file(self):
catalog = mock.MagicMock()
Expand Down Expand Up @@ -212,7 +221,7 @@ def test_output_extension(self):
self.assertEqual('.html', composer.output_extension)


class TestMarkdownComposer(unittest.TestCase):
class TestMarkdownComposer(TestCase):

def test_generates_html(self):
source = '**bold**'
Expand Down Expand Up @@ -246,7 +255,7 @@ def test_uses_smartypants(self):
self.assertEqual('<p>&ldquo;quoted&rdquo;</p>', html)


class TestReStructuredTextComposer(unittest.TestCase):
class TestReStructuredTextComposer(TestCase):

def test_generates_html(self):
source = '**bold**'
Expand All @@ -258,7 +267,7 @@ def test_generates_html(self):
self.assertEqual(expected, html)


class TestSassComposer(unittest.TestCase):
class TestSassComposer(TestCase):

def _make_fake_sass_bin(self):
fake_bin = tempfile.mkdtemp()
Expand Down Expand Up @@ -308,7 +317,7 @@ def test_output_extension(self):
self.assertEqual('.css', composer.output_extension)


class TestTextileComposer(unittest.TestCase):
class TestTextileComposer(TestCase):

def test_generates_html(self):
source = '*bold*'
Expand Down
4 changes: 2 additions & 2 deletions handroll/tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ class TestFileResolver(TestCase):

def test_as_url(self):
site = self.factory.make_site()
composers = Composers()
config = self.factory.make_configuration()
composers = Composers(config)
resolver = FileResolver(site.path, composers, config)
md_file = os.path.join(site.path, 'a_dir', 'test.md')
url = resolver.as_url(md_file)
self.assertEqual('http://www.example.com/a_dir/test.html', url)

def test_as_route(self):
site = self.factory.make_site()
composers = Composers()
config = self.factory.make_configuration()
composers = Composers(config)
resolver = FileResolver(site.path, composers, config)
md_file = os.path.join(site.path, 'a_dir', 'test.md')
route = resolver.as_route(md_file)
Expand Down

0 comments on commit e71a252

Please sign in to comment.