Skip to content

Instantly share code, notes, and snippets.

@ojii
Created January 12, 2011 09:50
Show Gist options
  • Save ojii/775952 to your computer and use it in GitHub Desktop.
Save ojii/775952 to your computer and use it in GitHub Desktop.
from __future__ import with_statement
from unittest import TestCase
from tempfile import template, mkdtemp, _exists
from sphinx.application import Sphinx
import os
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
DOCS_DIR = '/path/to/your/docs/'
class TemporaryDirectory:
"""Create and return a temporary directory. This has the same
behavior as mkdtemp but can be used as a context manager. For
example:
with TemporaryDirectory() as tmpdir:
...
Upon exiting the context, the directory and everthing contained
in it are removed.
"""
def __init__(self, suffix="", prefix=template, dir=None):
self.name = mkdtemp(suffix, prefix, dir)
def __enter__(self):
return self.name
def cleanup(self):
if _exists(self.name):
_rmtree(self.name)
def __exit__(self, exc, value, tb):
self.cleanup()
class DocsTestCase(TestCase):
"""
Test docs building correctly for HTML
"""
def test_documentation(self):
nullout = StringIO()
with TemporaryDirectory() as OUT_DIR:
app = Sphinx(
DOCS_DIR,
DOCS_DIR,
OUT_DIR,
OUT_DIR,
"html",
warningiserror=True,
status=nullout,
)
try:
app.build()
except:
print nullout.getvalue()
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment