Skip to content

Commit

Permalink
raise traceback if creole2rest self test failed
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed May 9, 2012
1 parent c11c5d3 commit f3e8093
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
19 changes: 14 additions & 5 deletions creole/rest2html/clean_writer.py
Expand Up @@ -165,7 +165,7 @@ def depart_docinfo(self, node):
self.body.append('</table>\n')


def rest2html(content):
def rest2html(content, enable_exit_status=None, **kwargs):
"""
Convert reStructuredText markup to clean html code: No extra div, class or ids.
Expand All @@ -174,19 +174,28 @@ def rest2html(content):
>>> rest2html("A ReSt link to `PyLucid CMS <http://www.pylucid.org>`_ :)")
'<p>A ReSt link to <a href="http://www.pylucid.org">PyLucid CMS</a> :)</p>\\n'
>>> rest2html("========", enable_exit_status=1, traceback=False, exit_status_level=2)
Traceback (most recent call last):
...
SystemExit: 13
"""
if not PY3:
content = unicode(content)

assert isinstance(content, TEXT_TYPE), "rest2html content must be %s, but it's %s" % (TEXT_TYPE, type(content))

settings_overrides = {
"input_encoding": "unicode",
"doctitle_xform": False,
}
settings_overrides.update(kwargs)

parts = publish_parts(
source=content,
writer=CleanHTMLWriter(),
settings_overrides={
"input_encoding": "unicode",
"doctitle_xform": False,
},
settings_overrides=settings_overrides,
enable_exit_status=enable_exit_status,
)
# import pprint
# pprint.pprint(parts)
Expand Down
7 changes: 6 additions & 1 deletion creole/setup_utils.py
Expand Up @@ -117,7 +117,11 @@ def get_long_description(package_root, filename="README.creole", raise_errors=No
if raise_errors:
# Test created ReSt code
from creole.rest2html.clean_writer import rest2html
rest2html(long_description_rest_unicode)
try:
rest2html(long_description_rest_unicode, traceback=True, enable_exit_status=1, exit_status_level=2)
except SystemExit, e:
print("Error creole2rest self test failed: rest2html() exist with status code: %s" % e)
raise

return long_description_rest

Expand All @@ -136,3 +140,4 @@ def _get_long_description(*args, **kwargs):
package_root = os.path.abspath("../")
long_description = get_long_description(package_root)
print(long_description)

18 changes: 18 additions & 0 deletions creole/tests/test_setup_utils.py
Expand Up @@ -20,6 +20,7 @@
from creole.setup_utils import get_long_description
from creole.tests.utils.base_unittest import BaseCreoleTest
from creole.py3compat import BINARY_TYPE, PY3, TEXT_TYPE
import tempfile


CREOLE_PACKAGE_ROOT = os.path.abspath(os.path.join(os.path.dirname(creole.__file__), ".."))
Expand Down Expand Up @@ -51,6 +52,23 @@ def test_get_long_description_with_raise_errors(self):
long_description = get_long_description(CREOLE_PACKAGE_ROOT, raise_errors=True)
self.assertIn("=====\nabout\n=====\n\n", long_description)

def test_with_string(self):
fd = tempfile.NamedTemporaryFile()
path, filename = os.path.split(fd.name)

fd.write("== noerror ==")
fd.seek(0)
long_description = get_long_description(path, filename, raise_errors=True)
self.assertEqual(long_description, "-------\nnoerror\n-------")

fd.truncate()
fd.write("----")
fd.seek(0)

self.assertRaises(SystemExit, get_long_description, path, filename, raise_errors=True)

fd.close()

def test_wrong_path_without_raise_errors(self):
self.assertEqual(
get_long_description("wrong/path", raise_errors=False).replace("u'", "'"),
Expand Down

0 comments on commit f3e8093

Please sign in to comment.