From fbf89687cc05c0656e7efc69befde6c790ec66b4 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Sun, 11 Mar 2012 01:59:58 +0100 Subject: [PATCH] start functional testing --- tests/support.py | 18 ++++++++++++++++++ tests/test_pelican.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/support.py create mode 100644 tests/test_pelican.py diff --git a/tests/support.py b/tests/support.py new file mode 100644 index 00000000..0cd757a6 --- /dev/null +++ b/tests/support.py @@ -0,0 +1,18 @@ +from contextlib import contextmanager + +from tempfile import mkdtemp +from shutil import rmtree + + +@contextmanager +def temporary_folder(): + """creates a temporary folder, return it and delete it afterwards. + + This allows to do something like this in tests: + + >>> with temporary_folder() as d: + # do whatever you want + """ + tempdir = mkdtemp() + yield tempdir + rmtree(tempdir) diff --git a/tests/test_pelican.py b/tests/test_pelican.py new file mode 100644 index 00000000..dce4fadc --- /dev/null +++ b/tests/test_pelican.py @@ -0,0 +1,31 @@ +import unittest +import os + +from support import temporary_folder + +from pelican import Pelican +from pelican.settings import read_settings + +SAMPLES_PATH = os.path.abspath(os.sep.join( + (os.path.dirname(os.path.abspath(__file__)), "..", "samples"))) + +INPUT_PATH = os.path.join(SAMPLES_PATH, "content") +SAMPLE_CONFIG = os.path.join(SAMPLES_PATH, "pelican.conf.py") + + +class TestPelican(unittest.TestCase): + # general functional testing for pelican. Basically, this test case tries + # to run pelican in different situations and see how it behaves + + def test_basic_generation_works(self): + # when running pelican without settings, it should pick up the default + # ones and generate the output without raising any exception / issuing + # any warning. + with temporary_folder() as temp_path: + pelican = Pelican(path=INPUT_PATH, output_path=temp_path) + pelican.run() + + # the same thing with a specified set of settins should work + with temporary_folder() as temp_path: + pelican = Pelican(path=INPUT_PATH, output_path=temp_path, + settings=read_settings(SAMPLE_CONFIG))