From 83382bcefb246f1169b0d01375fcd86cd05b031e Mon Sep 17 00:00:00 2001 From: Tiago Serafim Date: Sun, 2 Sep 2012 20:12:53 -0300 Subject: Initial version with insufficient tests and no docs. --- tests/extensions/admonition.html | 19 ++++++++++++++ tests/extensions/admonition.txt | 17 ++++++++++++ tests/extensions/test.cfg | 3 +++ tests/test_extensions.py | 56 +++++++++++++++++++++++++++++++++------- 4 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 tests/extensions/admonition.html create mode 100644 tests/extensions/admonition.txt (limited to 'tests') diff --git a/tests/extensions/admonition.html b/tests/extensions/admonition.html new file mode 100644 index 0000000..f28bcfd --- /dev/null +++ b/tests/extensions/admonition.html @@ -0,0 +1,19 @@ +

Some text

+
+

Note

+

A normal paragraph here

+
    +
  1. first
  2. +
  3. second
  4. +
+
+

More text and stuff.

+
+

Did you know?

+

You can customize the title of the admonition

+
+
+

And now...

+

For something completely different.

+

You can also use a custom CSS class name.

+
\ No newline at end of file diff --git a/tests/extensions/admonition.txt b/tests/extensions/admonition.txt new file mode 100644 index 0000000..e8db239 --- /dev/null +++ b/tests/extensions/admonition.txt @@ -0,0 +1,17 @@ +Some text + +!!! note + A normal paragraph here + + 1. first + 2. second + +More text and stuff. + +!!! note "Did you know?" + You can customize the title of the admonition + +!!! mycustomcssclass "And now..." + For something completely different. + + You can also use a custom CSS class name. diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index ac8a747..e83aa62 100644 --- a/tests/extensions/test.cfg +++ b/tests/extensions/test.cfg @@ -29,3 +29,6 @@ extensions=fenced_code [sane_lists] extensions=sane_lists + +[admonition] +extensions=admonition diff --git a/tests/test_extensions.py b/tests/test_extensions.py index 15feb6b..ca1520e 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -2,7 +2,7 @@ Python-Markdown Extension Regression Tests ========================================== -A collection of regression tests to confirm that the included extensions +A collection of regression tests to confirm that the included extensions continue to work as advertised. This used to be accomplished by doctests. """ @@ -59,7 +59,7 @@ class TestFencedCode(unittest.TestCase): def testBasicFence(self): """ Test Fenced Code Blocks. """ - text = ''' + text = ''' A paragraph before a fenced code block: ~~~ @@ -123,7 +123,7 @@ class TestHeaderId(unittest.TestCase): def testBasicHeaderId(self): """ Test Basic HeaderID """ - + text = "# Some Header #" self.assertEqual(self.md.convert(text), '

Some Header

') @@ -189,8 +189,8 @@ The body. This is paragraph one.''' self.assertEqual(self.md.convert(text), '

The body. This is paragraph one.

') self.assertEqual(self.md.Meta, - {'author': ['Waylan Limberg', 'John Doe'], - 'blank_data': [''], + {'author': ['Waylan Limberg', 'John Doe'], + 'blank_data': [''], 'title': ['A Test Doc.']}) def testMissingMetaData(self): @@ -226,18 +226,18 @@ class TestWikiLinks(unittest.TestCase): def testSimpleSettings(self): """ Test Simple Settings. """ - self.assertEqual(markdown.markdown(self.text, + self.assertEqual(markdown.markdown(self.text, ['wikilinks(base_url=/wiki/,end_url=.html,html_class=foo)']), '

Some text with a ' 'WikiLink.

') - + def testComplexSettings(self): """ Test Complex Settings. """ md = markdown.Markdown( - extensions = ['wikilinks'], + extensions = ['wikilinks'], extension_configs = {'wikilinks': [ - ('base_url', 'http://example.com/'), + ('base_url', 'http://example.com/'), ('end_url', '.html'), ('html_class', '') ]}, safe_mode = True) @@ -268,8 +268,44 @@ Some text with a [[WikiLink]].""" def my_url_builder(label, base, end): return '/bar/' - md = markdown.Markdown(extensions=['wikilinks'], + md = markdown.Markdown(extensions=['wikilinks'], extension_configs={'wikilinks' : [('build_url', my_url_builder)]}) self.assertEqual(md.convert('[[foo]]'), '

foo

') +class TestAdmonition(unittest.TestCase): + """ Test Admonition Extension. """ + + def setUp(self): + self.md = markdown.Markdown(extensions=['admonition']) + self.text = \ +'''!!! note + First line + +!!! didyouknow "Did you know?" + Another text''' + + def testComplexSettings(self): + """ Test Complex Settings. """ + + # config = { + # 'styles': { + # 'note': ('note', 'Please Note'), + # 'didyouknow': ('note', 'Did you know?'), + # } + # } + + md = markdown.Markdown( + extensions=['admonition'], + extension_configs={ + 'admonition': [] + }, + safe_mode=True) + self.assertEqual(md.convert(self.text), + '
\n' + '

Note

\n' + '

First line

\n' + '
\n' + '
\n' + '

Did you know?

\n' + '

Another text

\n
') -- cgit v1.2.3 From bcfe4257299034eed6aae8351d115c7691db3a3e Mon Sep 17 00:00:00 2001 From: Tiago Serafim Date: Sat, 8 Sep 2012 09:00:57 -0300 Subject: Removed the configs. --- tests/test_extensions.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/test_extensions.py b/tests/test_extensions.py index ca1520e..78c6d9d 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -288,18 +288,9 @@ class TestAdmonition(unittest.TestCase): def testComplexSettings(self): """ Test Complex Settings. """ - # config = { - # 'styles': { - # 'note': ('note', 'Please Note'), - # 'didyouknow': ('note', 'Did you know?'), - # } - # } - md = markdown.Markdown( extensions=['admonition'], - extension_configs={ - 'admonition': [] - }, + extension_configs={}, safe_mode=True) self.assertEqual(md.convert(self.text), '
\n' -- cgit v1.2.3 From 9756cb9f6014347179a9acf54a739aad5dda0c6d Mon Sep 17 00:00:00 2001 From: Tiago Serafim Date: Wed, 19 Sep 2012 18:37:02 -0300 Subject: More tests for the extension and new tests for the RE. It's now possible to use an explicit blank title to not have the

tag with the title rendered. --- tests/extensions/admonition.html | 11 +++++++++++ tests/extensions/admonition.txt | 11 +++++++++++ tests/test_extensions.py | 30 +++++++++--------------------- 3 files changed, 31 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/extensions/admonition.html b/tests/extensions/admonition.html index f28bcfd..437cac6 100644 --- a/tests/extensions/admonition.html +++ b/tests/extensions/admonition.html @@ -6,6 +6,14 @@

  • first
  • second
  • +
    +

    Some important quote

    +

    another paragraph in the quote

    +
    +
    int main() {
    +    // insert some code
    +}
    +

    More text and stuff.

    @@ -16,4 +24,7 @@

    And now...

    For something completely different.

    You can also use a custom CSS class name.

    +
    +
    +

    An explicitly empty string prevents the title from being rendered.

    \ No newline at end of file diff --git a/tests/extensions/admonition.txt b/tests/extensions/admonition.txt index e8db239..fd18bd6 100644 --- a/tests/extensions/admonition.txt +++ b/tests/extensions/admonition.txt @@ -6,6 +6,14 @@ Some text 1. first 2. second + > Some important quote + + > another paragraph in the quote + + int main() { + // insert some code + } + More text and stuff. !!! note "Did you know?" @@ -15,3 +23,6 @@ More text and stuff. For something completely different. You can also use a custom CSS class name. + +!!! tip "" + An explicitly empty string prevents the title from being rendered. diff --git a/tests/test_extensions.py b/tests/test_extensions.py index 78c6d9d..7661347 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -278,25 +278,13 @@ class TestAdmonition(unittest.TestCase): def setUp(self): self.md = markdown.Markdown(extensions=['admonition']) - self.text = \ -'''!!! note - First line -!!! didyouknow "Did you know?" - Another text''' - - def testComplexSettings(self): - """ Test Complex Settings. """ - - md = markdown.Markdown( - extensions=['admonition'], - extension_configs={}, - safe_mode=True) - self.assertEqual(md.convert(self.text), - '
    \n' - '

    Note

    \n' - '

    First line

    \n' - '
    \n' - '
    \n' - '

    Did you know?

    \n' - '

    Another text

    \n
    ') + def testRE(self): + RE = self.md.parser.blockprocessors['admonition'].RE + tests = [ + ('!!! note', ('note', None)), + ('!!! note "Please Note"', ('note', 'Please Note')), + ('!!! note ""', ('note', '')), + ] + for test, expected in tests: + self.assertEqual(RE.match(test).groups(), expected) -- cgit v1.2.3