Пример #1
0
	def test_errors_severe(self):
		markup = ReStructuredTextMarkup(settings_overrides={'warning_stream': False})
		text = "***************\nfaulty headline"
		# The following line should not raise SystemMessage exception
		body = markup.convert(text).get_document_body()
		self.assertIn("system-message", body)
		self.assertIn("Incomplete section title.", body)
Пример #2
0
	def test_mathjax_loading(self):
		markup = ReStructuredTextMarkup()
		self.assertEqual('', markup.get_javascript('Hello, world!'))
		js = markup.get_javascript('Hello, :math:`2+2`!')
		self.assertIn('<script', js)
		body = markup.get_document_body('Hello, :math:`2+2`!')
		self.assertIn('<span class="math">', body)
		self.assertIn(r'\(2+2\)</span>', body)
Пример #3
0
	def test_whole_html(self):
		markup = ReStructuredTextMarkup()
		text = basic_text + "\n\n.. math::\n   \\sin \\varphi"
		html = markup.convert(text).get_whole_html()
		self.assertIn("<title>Hello, world!</title>", html)
		self.assertIn('<style type="text/css">', html)
		self.assertIn('<script type="text/javascript"', html)
		self.assertIn('This is an example', html)
Пример #4
0
	def test_mathjax_loading(self):
		markup = ReStructuredTextMarkup()
		self.assertEqual('', markup.convert('Hello, world!').get_javascript())
		js = markup.convert('Hello, :math:`2+2`!').get_javascript()
		self.assertIn('<script', js)
		body = markup.convert('Hello, :math:`2+2`!').get_document_body()
		self.assertIn('<span class="math">', body)
		self.assertIn(r'\(2+2\)</span>', body)
Пример #5
0
	def test_toc_backrefs(self):
		markup = ReStructuredTextMarkup()
		text = (".. contents::\n"
		        "   :backlinks: entry\n"
		        "\n"
		        "Section title\n"
		        "-------------\n")
		body = markup.convert(text).get_document_body()
		self.assertIn('<a class="toc-backref"', body)
	def test_basic(self):
		markup = ReStructuredTextMarkup()
		converted = markup.convert(basic_text)
		text = converted.get_document_body()
		title = converted.get_document_title()
		stylesheet = converted.get_stylesheet()
		text_expected = ('<div class="document" id="hello-world">\n'
			'<h1 class="title">Hello, world!</h1>\n'
			'<p class="subtitle" id="some-subtitle">Some subtitle</p>\n'
			'<p>This is an example <strong>reStructuredText</strong> document.</p>\n'
			'</div>\n')
		title_expected = 'Hello, world!'
		self.assertEqual(text_expected, text)
		self.assertEqual(title_expected, title)
		self.assertIn('.code', stylesheet)
	def test_basic(self):
		markup = ReStructuredTextMarkup()
		converted = markup.convert(basic_text)
		text = converted.get_document_body()
		title = converted.get_document_title()
		stylesheet = converted.get_stylesheet()
		text_expected = ('<div class="document" id="hello-world">\n'
			'<h1 class="title">Hello, world!</h1>\n'
			'<h2 class="subtitle" id="some-subtitle">Some subtitle</h2>\n'
			'<p>This is an example <strong>reStructuredText</strong> document.</p>\n'
			'</div>\n')
		title_expected = 'Hello, world!'
		self.assertEqual(text_expected, text)
		self.assertEqual(title_expected, title)
		self.assertIn('.code', stylesheet)
Пример #8
0
	def test_basic(self):
		import docutils
		markup = ReStructuredTextMarkup()
		converted = markup.convert(basic_text)
		text = converted.get_document_body()
		title = converted.get_document_title()
		stylesheet = converted.get_stylesheet()
		text_expected = basic_html
		if docutils.__version_info__[:2] < (0, 17):
			# docutils uses <main> tag since revision 8474
			text_expected = text_expected.replace('<main', '<div class="document"')
			text_expected = text_expected.replace('</main>', '</div>')
		title_expected = 'Hello, world!'
		self.assertEqual(text_expected, text)
		self.assertEqual(title_expected, title)
		self.assertIn('.code', stylesheet)
Пример #9
0
	def test_basic(self):
		markup = ReStructuredTextMarkup()
		text = markup.get_document_body(basic_text)
		title = markup.get_document_title(basic_text)
		markup._enable_cache = True
		text_from_cache = markup.get_document_body(basic_text)
		title_from_cache = markup.get_document_title(basic_text)
		text_expected = \
		'<p>This is an example <strong>reStructuredText</strong> document.</p>\n'
		title_expected = 'Hello, world!'
		self.assertEqual(text_expected, text)
		self.assertEqual(text_expected, text_from_cache)
		self.assertEqual(title_expected, title)
		self.assertEqual(title_expected, title_from_cache)
Пример #10
0
	def test_errors_overridden(self):
		markup = ReStructuredTextMarkup('/dev/null',
			settings_overrides = {'report_level': 4})
		body = markup.get_document_body('`') # unclosed role
		self.assertNotIn('system-message', body)
Пример #11
0
	def test_errors(self):
		markup = ReStructuredTextMarkup('/dev/null',
			settings_overrides = {'warning_stream': False})
		body = markup.get_document_body('`') # unclosed role
		self.assertIn('system-message', body)
		self.assertIn('/dev/null', body)
Пример #12
0
# This file is part of python-markups test suite
# License: BSD
# Copyright: (C) Dmitry Shachnev, 2012-2014

import unittest
from markups import ReStructuredTextMarkup

basic_text = \
'''Hello, world!
=============

This is an example **reStructuredText** document.'''

@unittest.skipUnless(ReStructuredTextMarkup.available(), 'Docutils not available')
class ReStructuredTextTest(unittest.TestCase):
	def test_basic(self):
		markup = ReStructuredTextMarkup()
		text = markup.get_document_body(basic_text)
		title = markup.get_document_title(basic_text)
		markup._enable_cache = True
		text_from_cache = markup.get_document_body(basic_text)
		title_from_cache = markup.get_document_title(basic_text)
		text_expected = \
		'<p>This is an example <strong>reStructuredText</strong> document.</p>\n'
		title_expected = 'Hello, world!'
		self.assertEqual(text_expected, text)
		self.assertEqual(text_expected, text_from_cache)
		self.assertEqual(title_expected, title)
		self.assertEqual(title_expected, title_from_cache)

	def test_mathjax_loading(self):
Пример #13
0
	def test_errors_overridden(self):
		markup = ReStructuredTextMarkup('/dev/null',
		                                settings_overrides = {'report_level': 4})
		body = markup.convert('`').get_document_body() # unclosed role
		self.assertNotIn('System Message', body)
Пример #14
0
	def test_errors(self):
		markup = ReStructuredTextMarkup('/dev/null',
		                                settings_overrides = {'warning_stream': False})
		body = markup.convert('`').get_document_body() # unclosed role
		self.assertIn('<p class="system-message-title">System Message: WARNING/2', body)
		self.assertIn('/dev/null', body)
Пример #15
0
Some subtitle
~~~~~~~~~~~~~

This is an example **reStructuredText** document.
'''

basic_html = '''\
<main id="hello-world">
<h1 class="title" data-posmap="2">Hello, world!</h1>
<p class="subtitle" id="some-subtitle">Some subtitle</p>
<p data-posmap="7">This is an example <strong>reStructuredText</strong> document.</p>
</main>
'''

@unittest.skipUnless(ReStructuredTextMarkup.available(), 'Docutils not available')
class ReStructuredTextTest(unittest.TestCase):
	def test_basic(self):
		import docutils
		markup = ReStructuredTextMarkup()
		converted = markup.convert(basic_text)
		text = converted.get_document_body()
		title = converted.get_document_title()
		stylesheet = converted.get_stylesheet()
		text_expected = basic_html
		if docutils.__version_info__[:2] < (0, 17):
			# docutils uses <main> tag since revision 8474
			text_expected = text_expected.replace('<main', '<div class="document"')
			text_expected = text_expected.replace('</main>', '</div>')
		title_expected = 'Hello, world!'
		self.assertEqual(text_expected, text)