diff --git a/.gitignore b/.gitignore index 721af351..5bb92c09 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ docs/fr/_build build dist output +tags +.tox diff --git a/dev_requirements.txt b/dev_requirements.txt deleted file mode 100644 index acafebc0..00000000 --- a/dev_requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -Jinja2==2.5.5 -Pygments==1.4 -docutils==0.7 -feedgenerator==1.2.1 -unittest2 diff --git a/pelican/settings.py b/pelican/settings.py index 1b32395c..125d0bb0 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -55,6 +55,13 @@ def read_settings(filename): if key.isupper(): context[key] = tempdict[key] + # Make the paths relative to the settings file + for path in ['PATH', 'OUTPUT_PATH']: + if path in context: + if context[path] is not None and not os.path.isabs(context[path]): + # FIXME: + context[path] = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(filename), context[path]))) + # if locales is not a list, make it one locales = context['LOCALE'] @@ -74,11 +81,5 @@ def read_settings(filename): else: log.warn("LOCALE option doesn't contain a correct value") - # Make the paths relative to the settings file - for path in ['PATH', 'OUTPUT_PATH']: - if path in context: - if context[path] is not None and not os.path.isabs(context[path]): - context[path] = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(filename), context[path]))) - # set the locale return context diff --git a/pelican/tests/test_settings.py b/pelican/tests/test_settings.py deleted file mode 100644 index 39680a9f..00000000 --- a/pelican/tests/test_settings.py +++ /dev/null @@ -1,34 +0,0 @@ -from unittest2 import TestCase -import os - -from pelican.settings import read_settings, _DEFAULT_CONFIG - -SETTINGS = os.sep.join([os.path.dirname(os.path.abspath(__file__)), - "../../samples/pelican.conf.py"]) - -class SettingsTest(TestCase): - - - def test_read_settings(self): - # providing a file, it should read it, replace the default values and append - # new values to the settings, if any - settings = read_settings(SETTINGS) - - # overwrite existing settings - self.assertEqual(settings.get('SITENAME'), u"Alexis' log") - - # add new settings - self.assertEqual(settings.get('SITEURL'), 'http://blog.notmyidea.org') - - # keep default settings if not defined - self.assertEqual(settings.get('DEFAULT_CATEGORY'), - _DEFAULT_CONFIG['DEFAULT_CATEGORY']) - - # do not copy keys not in caps - self.assertNotIn('foobar', settings) - - - def test_empty_read_settings(self): - # providing no file should return the default values - settings = read_settings(None) - self.assertDictEqual(settings, _DEFAULT_CONFIG) diff --git a/pelican/tests/__init__.py b/tests/__init__.py similarity index 100% rename from pelican/tests/__init__.py rename to tests/__init__.py diff --git a/tests/content/article_with_metadata.rst b/tests/content/article_with_metadata.rst new file mode 100644 index 00000000..3410885e --- /dev/null +++ b/tests/content/article_with_metadata.rst @@ -0,0 +1,11 @@ + +This is a super article ! +######################### + +:tags: foo, bar, foobar +:date: 2010-12-02 10:14 +:category: yeah +:author: Alexis Métaireau +:summary: + Multi-line metadata should be supported + as well as **inline markup**. diff --git a/tests/default_conf.py b/tests/default_conf.py new file mode 100755 index 00000000..2796d561 --- /dev/null +++ b/tests/default_conf.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +AUTHOR = u'Alexis Métaireau' +SITENAME = u"Alexis' log" +SITEURL = 'http://blog.notmyidea.org' + +GITHUB_URL = 'http://github.com/ametaireau/' +DISQUS_SITENAME = "blog-notmyidea" +PDF_GENERATOR = False +REVERSE_CATEGORY_ORDER = True +LOCALE = "" +DEFAULT_PAGINATION = 2 + +FEED_RSS = 'feeds/all.rss.xml' +CATEGORY_FEED_RSS = 'feeds/%s.rss.xml' + +LINKS = (('Biologeek', 'http://biologeek.org'), + ('Filyb', "http://filyb.info/"), + ('Libert-fr', "http://www.libert-fr.com"), + ('N1k0', "http://prendreuncafe.com/blog/"), + (u'Tarek Ziadé', "http://ziade.org/blog"), + ('Zubin Mithra', "http://zubin71.wordpress.com/"),) + +SOCIAL = (('twitter', 'http://twitter.com/ametaireau'), + ('lastfm', 'http://lastfm.com/user/akounet'), + ('github', 'http://github.com/ametaireau'),) + +# global metadata to all the contents +DEFAULT_METADATA = (('yeah', 'it is'),) + +# static paths will be copied under the same name +STATIC_PATHS = ["pictures",] + +# A list of files to copy from the source to the destination +FILES_TO_COPY = (('extra/robots.txt', 'robots.txt'),) + +# foobar will not be used, because it's not in caps. All configuration keys +# have to be in caps +foobar = "barbaz" diff --git a/pelican/tests/test_contents.py b/tests/test_contents.py similarity index 98% rename from pelican/tests/test_contents.py rename to tests/test_contents.py index d013da2f..df2c00e6 100644 --- a/pelican/tests/test_contents.py +++ b/tests/test_contents.py @@ -1,3 +1,4 @@ +from __future__ import with_statement from unittest2 import TestCase from pelican.contents import Page diff --git a/pelican/tests/test_readers.py b/tests/test_readers.py similarity index 80% rename from pelican/tests/test_readers.py rename to tests/test_readers.py index 5a255209..bf7504fb 100644 --- a/pelican/tests/test_readers.py +++ b/tests/test_readers.py @@ -5,7 +5,7 @@ import datetime from pelican import readers CUR_DIR = os.path.dirname(__file__) -CONTENT_PATH = os.path.join(CUR_DIR, '..', '..', 'samples', 'content') +CONTENT_PATH = os.path.join(CUR_DIR, 'content') def _filename(*args): return os.path.join(CONTENT_PATH, *args) @@ -13,9 +13,9 @@ def _filename(*args): class RstReaderTest(unittest2.TestCase): - def test_metadata(self): + def test_article_with_metadata(self): reader = readers.RstReader() - content, metadata = reader.read(_filename('super_article.rst')) + content, metadata = reader.read(_filename('article_with_metadata.rst')) expected = { 'category': 'yeah', 'author': u'Alexis Métaireau', diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 00000000..e32fcef4 --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,33 @@ +import unittest2 +from os.path import dirname, abspath, join + +from pelican.settings import read_settings, _DEFAULT_CONFIG + + +class TestSettingsFromFile(unittest2.TestCase): + """Providing a file, it should read it, replace the default values and + append new values to the settings, if any + """ + def setUp(self): + self.PATH = abspath(dirname(__file__)) + default_conf = join(self.PATH, 'default_conf.py') + self.settings = read_settings(default_conf) + + def test_overwrite_existing_settings(self): + self.assertEqual(self.settings.get('SITENAME'), u"Alexis' log") + self.assertEqual(self.settings.get('SITEURL'), + 'http://blog.notmyidea.org') + + def test_keep_default_settings(self): + """keep default settings if not defined""" + self.assertEqual(self.settings.get('DEFAULT_CATEGORY'), + _DEFAULT_CONFIG['DEFAULT_CATEGORY']) + + def test_dont_copy_small_keys(self): + """do not copy keys not in caps.""" + self.assertNotIn('foobar', self.settings) + + def test_read_empty_settings(self): + """providing no file should return the default values.""" + settings = read_settings(None) + self.assertDictEqual(settings, _DEFAULT_CONFIG) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..462abf09 --- /dev/null +++ b/tox.ini @@ -0,0 +1,12 @@ +[tox] +envlist = py25,py26,py27 + +[testenv] +commands=py.test +deps = + Jinja2 + Pygments + docutils + feedgenerator + unittest2 + pytest