Merge pull request #144 from marsam/master

Improving tests
This commit is contained in:
Alexis Metaireau 2011-07-15 14:39:05 -07:00
commit 34c41b43e5
14 changed files with 183 additions and 124 deletions

2
.gitignore vendored
View file

@ -7,3 +7,5 @@ docs/fr/_build
build
dist
output
tags
.tox

View file

@ -1,5 +0,0 @@
Jinja2==2.5.5
Pygments==1.4
docutils==0.7
feedgenerator==1.2.1
unittest2

View file

@ -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

View file

@ -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)

View file

@ -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**.

38
tests/default_conf.py Executable file
View file

@ -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"

View file

@ -1,3 +1,4 @@
from __future__ import with_statement
from unittest2 import TestCase
from pelican.contents import Page

View file

@ -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',

33
tests/test_settings.py Normal file
View file

@ -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)

12
tox.ini Normal file
View file

@ -0,0 +1,12 @@
[tox]
envlist = py25,py26,py27
[testenv]
commands=py.test
deps =
Jinja2
Pygments
docutils
feedgenerator
unittest2
pytest