summaryrefslogtreecommitdiff
path: root/creole
diff options
context:
space:
mode:
authorJensDiemer <git@jensdiemer.de>2015-06-02 18:02:29 +0200
committerJensDiemer <git@jensdiemer.de>2015-06-02 18:02:29 +0200
commit0bd2955957227ba611954d180cc7c0a6c3e62cf7 (patch)
tree27d8e27f334df26263ca78b4681f4b14ec80a5c5 /creole
parentaa309e7c4eee478386a7a38cdbbc3adb2fc8e1c7 (diff)
downloadcreole-0bd2955957227ba611954d180cc7c0a6c3e62cf7.tar.gz
Squashed commit of the following:
commit 04b2b00e51e3a60369de4a2ecde07c4cd5f67c57 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 17:58:34 2015 +0200 --verbose not needed commit 1206d8fd18f368e0cacb54f76788c5eb855f72c5 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 17:49:13 2015 +0200 Strange: argparse use stderr in Py2 and stdout in Py3 for --version ;) commit 82140fcec5c1994081d31b288a28f924a7723ed8 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 17:47:39 2015 +0200 Bugfix: get rid of the u'' with Py2 commit cdbb3ff08848698ad9e0f7df5bfa7486e60cb7da Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 17:41:03 2015 +0200 fixup! WIP: refactor CLI tests commit 6d959e3a9d793eed76cbe606f4cf43843ddfc281 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 17:29:28 2015 +0200 WIP: refactor CLI tests commit 4ff6eb4f3454e92b50408541d3ed72215cfc4682 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 16:39:44 2015 +0200 bixfix travis config? commit ecc22075a5433e91075700e1e928a63b96090de7 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 16:38:57 2015 +0200 new v1.3.0 commit 16f4244224856defa711d90b02b0e9498c55b220 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 16:38:46 2015 +0200 update README commit ba59454aae040486d77843c9c41f1873fabf7f87 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 16:38:40 2015 +0200 +"pip install ." makes the CLI available on Travis?!? commit 75a782dcd679f8c9aea6a5ef43f22245559f32c2 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 16:27:08 2015 +0200 run nosetests on travis with doctests commit d3de2ebb979c1d08cc4bda1db439aeac98117500 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 15:49:22 2015 +0200 use 'json.dumps()' instead of own repr2() commit 1ec9d9eacbaa1ec475ea2573f0a8744c713073da Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 14:13:50 2015 +0200 search in sys.path, too. commit 1a101ec988b3c365d592e5e471f16d2a00700e04 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 14:07:10 2015 +0200 -"2.6" commit 514d7b8f28708ad2c81e163e444cdd1901f9a992 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 14:07:00 2015 +0200 more info commit 30c67fe9ef1af41a87fa676e6c345ec358a1928d Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 13:52:44 2015 +0200 sys.exit() if not importable commit 5bf5c0829ea550609ff160d5240609d6948035d9 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 13:48:46 2015 +0200 run cli tests via subprocess commit f9eac72fa1b9f7cfd60f1242887caa86c3d23422 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 13:48:19 2015 +0200 rename test macros, so that nose will not interpret them as a test ;) commit 8e7f236490a7374e79d3a342b6446c79b645a484 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 13:47:39 2015 +0200 use "with" commit a7376c023f0ef8886bdc8aff05e2eb4db82cb84b Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 13:47:29 2015 +0200 use nose and add a simple test, if nose is installed commit 932aacb70ca387302fd6242aa9094df3d80322db Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 13:45:26 2015 +0200 Bugfix: --version commit d884abc68a06961dcc0ae99f5642dcfdb560bd90 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 11:00:46 2015 +0200 use @unittest.expectedFailure commit 75b21bd449e969bd05d5dcd41c74e2909172fb3f Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 10:54:09 2015 +0200 WIP: refactor commit 17041df8d8cf1de91295da50b06de1c7f3bf7c62 Merge: 4285bbf e82d365 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 10:51:55 2015 +0200 Merge branch 'nose' into refactor commit 4285bbf7707542772a70b3718d03394cd3537a43 Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 10:51:15 2015 +0200 WIP: refactor commit e82d365885bd5f23c3ad144d464a11ccb007fdae Author: JensDiemer <git@jensdiemer.de> Date: Tue Jun 2 10:38:24 2015 +0200 WIP: use nose
Diffstat (limited to 'creole')
-rw-r--r--creole/__init__.py14
-rw-r--r--creole/cmdline.py5
-rw-r--r--creole/emitter/__init__.py (renamed from creole/creole2html/__init__.py)0
-rw-r--r--creole/emitter/creol2html_emitter.py (renamed from creole/creole2html/emitter.py)10
-rw-r--r--creole/emitter/html2creole_emitter.py (renamed from creole/html2creole/emitter.py)4
-rw-r--r--creole/emitter/html2rest_emitter.py (renamed from creole/html2rest/emitter.py)3
-rw-r--r--creole/emitter/html2textile_emitter.py (renamed from creole/html2textile/emitter.py)2
-rw-r--r--creole/html2textile/__init__.py0
-rw-r--r--creole/html_parser/__init__.py0
-rw-r--r--creole/html_tools/strip_html.py2
-rw-r--r--creole/parser/__init__.py (renamed from creole/html2creole/__init__.py)0
-rw-r--r--creole/parser/creol2html_parser.py (renamed from creole/creole2html/parser.py)6
-rw-r--r--creole/parser/creol2html_rules.py (renamed from creole/creole2html/rules.py)0
-rw-r--r--creole/parser/html_parser.py (renamed from creole/html_parser/parser.py)8
-rw-r--r--creole/parser/html_parser_config.py (renamed from creole/html_parser/config.py)0
-rw-r--r--creole/py3compat.py10
-rw-r--r--creole/rest2html/__init__.py0
-rw-r--r--creole/rest_tools/__init__.py (renamed from creole/html2rest/__init__.py)0
-rw-r--r--creole/rest_tools/clean_writer.py (renamed from creole/rest2html/clean_writer.py)0
-rw-r--r--creole/rest_tools/pypi_rest2html.py (renamed from creole/rest2html/pypi_rest2html.py)2
-rw-r--r--creole/setup_utils.py2
-rw-r--r--creole/shared/base_emitter.py3
-rw-r--r--creole/shared/document_tree.py4
-rw-r--r--creole/shared/utils.py9
-rw-r--r--creole/tests/__init__.py38
-rw-r--r--creole/tests/all_tests.py140
-rw-r--r--creole/tests/test_TODOs.py18
-rw-r--r--creole/tests/test_cli.py142
-rw-r--r--creole/tests/test_creole2html.py26
-rw-r--r--creole/tests/test_cross_compare_creole.py4
-rw-r--r--creole/tests/test_html2creole.py6
-rw-r--r--creole/tests/test_html2rest.py3
-rw-r--r--creole/tests/test_html2textile.py8
-rw-r--r--creole/tests/test_macros.py24
-rw-r--r--creole/tests/test_setup_utils.py2
-rw-r--r--creole/tests/utils/base_unittest.py2
-rw-r--r--creole/tests/utils/utils.py2
37 files changed, 206 insertions, 293 deletions
diff --git a/creole/__init__.py b/creole/__init__.py
index 75db1d4..37487c9 100644
--- a/creole/__init__.py
+++ b/creole/__init__.py
@@ -20,18 +20,18 @@
from __future__ import division, absolute_import, print_function, unicode_literals
-__version__ = (1, 2, 2)
+__version__ = (1, 3, 0)
__api__ = (1, 0) # Creole 1.0 spec - http://wikicreole.org/
import warnings
-from creole.creole2html.emitter import HtmlEmitter
-from creole.creole2html.parser import BlockRules, CreoleParser
-from creole.html2creole.emitter import CreoleEmitter
-from creole.html2rest.emitter import ReStructuredTextEmitter
-from creole.html2textile.emitter import TextileEmitter
-from creole.html_parser.parser import HtmlParser
+from creole.emitter.creol2html_emitter import HtmlEmitter
+from creole.parser.creol2html_parser import CreoleParser
+from creole.emitter.html2creole_emitter import CreoleEmitter
+from creole.emitter.html2rest_emitter import ReStructuredTextEmitter
+from creole.emitter.html2textile_emitter import TextileEmitter
+from creole.parser.html_parser import HtmlParser
from creole.py3compat import TEXT_TYPE
diff --git a/creole/cmdline.py b/creole/cmdline.py
index 0245078..a8420a2 100644
--- a/creole/cmdline.py
+++ b/creole/cmdline.py
@@ -26,9 +26,10 @@ class CreoleCLI(object):
" in pure Python for:"
" creole2html, html2creole, html2ReSt, html2textile"
),
- version=VERSION_STRING,
)
-
+ self.parser.add_argument('--version', action='version',
+ version='%%(prog)s from python-creole v%s' % VERSION_STRING
+ )
self.parser.add_argument("sourcefile", help="source file to convert")
self.parser.add_argument("destination", help="Output filename")
self.parser.add_argument("--encoding",
diff --git a/creole/creole2html/__init__.py b/creole/emitter/__init__.py
index e69de29..e69de29 100644
--- a/creole/creole2html/__init__.py
+++ b/creole/emitter/__init__.py
diff --git a/creole/creole2html/emitter.py b/creole/emitter/creol2html_emitter.py
index 71fc314..6a688dc 100644
--- a/creole/creole2html/emitter.py
+++ b/creole/emitter/creol2html_emitter.py
@@ -4,23 +4,23 @@
"""
WikiCreole to HTML converter
- :copyleft: 2008-2014 by python-creole team, see AUTHORS for more details.
+ :copyleft: 2008-2015 by python-creole team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
from __future__ import division, absolute_import, print_function, unicode_literals
+import json
from xml.sax.saxutils import escape
import sys
import traceback
-from creole.creole2html.parser import CreoleParser
-from creole.py3compat import TEXT_TYPE, repr2
+from creole.parser.creol2html_parser import CreoleParser
+from creole.py3compat import TEXT_TYPE
from creole.shared.utils import string2dict
-
class TableOfContent(object):
def __init__(self):
self.max_depth = None
@@ -288,7 +288,7 @@ class HtmlEmitter(object):
exc_info = sys.exc_info()
return self.error(
"Wrong macro arguments: %s for macro '%s' (maybe wrong macro tag syntax?)" % (
- repr2(args), macro_name
+ json.dumps(args), macro_name
),
exc_info
)
diff --git a/creole/html2creole/emitter.py b/creole/emitter/html2creole_emitter.py
index 08d0ad3..6504dc2 100644
--- a/creole/html2creole/emitter.py
+++ b/creole/emitter/html2creole_emitter.py
@@ -148,9 +148,9 @@ if __name__ == '__main__':
print(doctest.testmod())
# import sys;sys.exit()
- from creole.html_parser.parser import HtmlParser
+ from creole.parser.html_parser import HtmlParser
- data = """A <<test_macro1 args="foo1">>bar1<</test_macro1>> in a line..."""
+ data = """A <<unittest_macro1 args="foo1">>bar1<</unittest_macro1>> in a line..."""
# print(data.strip())
h2c = HtmlParser(
diff --git a/creole/html2rest/emitter.py b/creole/emitter/html2rest_emitter.py
index e1849fc..7a32872 100644
--- a/creole/html2rest/emitter.py
+++ b/creole/emitter/html2rest_emitter.py
@@ -16,7 +16,6 @@
from __future__ import division, absolute_import, print_function, unicode_literals
import posixpath
-from creole.html_parser.config import BLOCK_TAGS
from creole.shared.base_emitter import BaseEmitter
from creole.shared.markup_table import MarkupTable
@@ -298,7 +297,7 @@ if __name__ == '__main__':
print(doctest.testmod())
# import sys;sys.exit()
- from creole.html_parser.parser import HtmlParser
+ from creole.parser.html_parser import HtmlParser
data = """<p>A nested bullet lists:</p>
<ul>
diff --git a/creole/html2textile/emitter.py b/creole/emitter/html2textile_emitter.py
index 44a3a2f..2263c12 100644
--- a/creole/html2textile/emitter.py
+++ b/creole/emitter/html2textile_emitter.py
@@ -136,7 +136,7 @@ if __name__ == '__main__':
print(doctest.testmod())
# import sys;sys.exit()
- from creole.html_parser.parser import HtmlParser
+ from creole.parser.html_parser import HtmlParser
data = """
<h1>Textile</h1>
diff --git a/creole/html2textile/__init__.py b/creole/html2textile/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/creole/html2textile/__init__.py
+++ /dev/null
diff --git a/creole/html_parser/__init__.py b/creole/html_parser/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/creole/html_parser/__init__.py
+++ /dev/null
diff --git a/creole/html_tools/strip_html.py b/creole/html_tools/strip_html.py
index 60216f9..20b6788 100644
--- a/creole/html_tools/strip_html.py
+++ b/creole/html_tools/strip_html.py
@@ -15,7 +15,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import re
-from creole.html_parser.config import BLOCK_TAGS
+from creole.parser.html_parser_config import BLOCK_TAGS
strip_html_regex = re.compile(
diff --git a/creole/html2creole/__init__.py b/creole/parser/__init__.py
index e69de29..e69de29 100644
--- a/creole/html2creole/__init__.py
+++ b/creole/parser/__init__.py
diff --git a/creole/creole2html/parser.py b/creole/parser/creol2html_parser.py
index 9ec06c0..ab09a35 100644
--- a/creole/creole2html/parser.py
+++ b/creole/parser/creol2html_parser.py
@@ -26,10 +26,10 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import re
-from creole.creole2html.rules import BlockRules, INLINE_FLAGS, INLINE_RULES, \
+from creole.parser.creol2html_rules import BlockRules, INLINE_FLAGS, INLINE_RULES, \
SpecialRules, InlineRules
from creole.py3compat import TEXT_TYPE
-from creole.shared.document_tree import DocNode, DebugList
+from creole.shared.document_tree import DocNode
class CreoleParser(object):
@@ -493,7 +493,7 @@ if __name__ == "__main__":
print("-" * 80)
- txt = """A <<test_macro1 args="foo1">>bar1<</test_macro1>> in a line..."""
+ txt = """A <<unittest_macro1 args="foo1">>bar1<</unittest_macro1>> in a line..."""
print(txt)
print("-" * 80)
diff --git a/creole/creole2html/rules.py b/creole/parser/creol2html_rules.py
index 01bb08e..01bb08e 100644
--- a/creole/creole2html/rules.py
+++ b/creole/parser/creol2html_rules.py
diff --git a/creole/html_parser/parser.py b/creole/parser/html_parser.py
index 2fadd60..fa60091 100644
--- a/creole/html_parser/parser.py
+++ b/creole/parser/html_parser.py
@@ -13,15 +13,15 @@
from __future__ import division, absolute_import, print_function, unicode_literals
import re
-import sys
import warnings
-from creole.html_parser.config import BLOCK_TAGS, IGNORE_TAGS
+from creole.parser.html_parser_config import BLOCK_TAGS, IGNORE_TAGS
from creole.html_tools.strip_html import strip_html
from creole.py3compat import TEXT_TYPE, BINARY_TYPE
from creole.shared.document_tree import DocNode, DebugList
from creole.shared.html_parser import HTMLParser
+
#------------------------------------------------------------------------------
block_re = re.compile(r'''
@@ -74,9 +74,7 @@ class HtmlParser(HTMLParser):
p
data: 'html1 '
script
- data: "var foo='<em>BAR"
- data: '</em>'
- data: "';"
+ data: "var foo='<em>BAR</em>';"
data: ' html2'
********************************************************************************
"""
diff --git a/creole/html_parser/config.py b/creole/parser/html_parser_config.py
index 9790833..9790833 100644
--- a/creole/html_parser/config.py
+++ b/creole/parser/html_parser_config.py
diff --git a/creole/py3compat.py b/creole/py3compat.py
index c06c383..f48da75 100644
--- a/creole/py3compat.py
+++ b/creole/py3compat.py
@@ -41,13 +41,3 @@ else:
doctest.OutputChecker = OutputChecker2
-def repr2(obj):
- """
- Don't mark unicode strings with u in Python 2
- """
- if not PY3:
- return repr(obj).lstrip("u")
- else:
- return repr(obj)
-
-
diff --git a/creole/rest2html/__init__.py b/creole/rest2html/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/creole/rest2html/__init__.py
+++ /dev/null
diff --git a/creole/html2rest/__init__.py b/creole/rest_tools/__init__.py
index e69de29..e69de29 100644
--- a/creole/html2rest/__init__.py
+++ b/creole/rest_tools/__init__.py
diff --git a/creole/rest2html/clean_writer.py b/creole/rest_tools/clean_writer.py
index 5378bd7..5378bd7 100644
--- a/creole/rest2html/clean_writer.py
+++ b/creole/rest_tools/clean_writer.py
diff --git a/creole/rest2html/pypi_rest2html.py b/creole/rest_tools/pypi_rest2html.py
index 15b425c..fd7d16d 100644
--- a/creole/rest2html/pypi_rest2html.py
+++ b/creole/rest_tools/pypi_rest2html.py
@@ -44,7 +44,7 @@ wais irc'''.split()
def pypi_rest2html(source, output_encoding='unicode'):
"""
>>> pypi_rest2html("test!")
- u'<p>test!</p>\n'
+ '<p>test!</p>\\n'
"""
settings_overrides = {
'raw_enabled': 0, # no raw HTML code
diff --git a/creole/setup_utils.py b/creole/setup_utils.py
index 97ae94d..977cb73 100644
--- a/creole/setup_utils.py
+++ b/creole/setup_utils.py
@@ -118,7 +118,7 @@ def get_long_description(package_root, filename="README.creole", raise_errors=No
else:
if raise_errors:
# Test created ReSt code like PyPi does it.
- from creole.rest2html.pypi_rest2html import pypi_rest2html
+ from creole.rest_tools.pypi_rest2html import pypi_rest2html
try:
pypi_rest2html(long_description_rest_unicode)
except SystemExit as e:
diff --git a/creole/shared/base_emitter.py b/creole/shared/base_emitter.py
index fe1b334..1561083 100644
--- a/creole/shared/base_emitter.py
+++ b/creole/shared/base_emitter.py
@@ -11,9 +11,8 @@
"""
from __future__ import division, absolute_import, print_function, unicode_literals
-import posixpath
-from creole.html_parser.config import BLOCK_TAGS
+from creole.parser.html_parser_config import BLOCK_TAGS
from creole.html_tools.deentity import Deentity
from creole.py3compat import TEXT_TYPE
from creole.shared.markup_table import MarkupTable
diff --git a/creole/shared/document_tree.py b/creole/shared/document_tree.py
index 6282afc..eb33aca 100644
--- a/creole/shared/document_tree.py
+++ b/creole/shared/document_tree.py
@@ -48,11 +48,11 @@ class DocNode:
>>> node = DocNode(attrs={'foo':"bar", "no":123})
>>> node.get_attrs_as_string()
- "foo='bar' no=123"
+ 'foo="bar" no=123'
>>> node = DocNode(attrs={"foo":'bar', "no":"ABC"})
>>> node.get_attrs_as_string()
- "foo='bar' no='ABC'"
+ 'foo="bar" no="ABC"'
"""
return dict2string(self.attrs)
diff --git a/creole/shared/utils.py b/creole/shared/utils.py
index 4043f0d..e150c5f 100644
--- a/creole/shared/utils.py
+++ b/creole/shared/utils.py
@@ -12,8 +12,9 @@
from __future__ import division, absolute_import, print_function, unicode_literals
import shlex
+import json
-from creole.py3compat import TEXT_TYPE, PY3, repr2
+from creole.py3compat import TEXT_TYPE, PY3
try:
from pygments import lexers
@@ -72,16 +73,16 @@ def dict2string(d):
FIXME: Find a better was to do this.
>>> dict2string({'foo':"bar", "no":123})
- "foo='bar' no=123"
+ 'foo="bar" no=123'
>>> dict2string({"foo":'bar', "no":"ABC"})
- "foo='bar' no='ABC'"
+ 'foo="bar" no="ABC"'
See test_creole2html.TestDict2String()
"""
attr_list = []
for key, value in sorted(d.items()):
- value_string = repr2(value)
+ value_string = json.dumps(value)
attr_list.append("%s=%s" % (key, value_string))
return " ".join(attr_list)
diff --git a/creole/tests/__init__.py b/creole/tests/__init__.py
index 1fac4d3..e69de29 100644
--- a/creole/tests/__init__.py
+++ b/creole/tests/__init__.py
@@ -1,38 +0,0 @@
-#!/usr/bin/env python
-# coding: utf-8
-
-"""
- python-creole unittests
- ~~~~~~~~~~~~~~~~~~~~~~~
-
- :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details.
- :license: GNU GPL v3 or above, see LICENSE for more details.
-"""
-
-from __future__ import division, absolute_import, print_function, unicode_literals
-
-import unittest
-
-from creole.tests import all_tests
-
-
-def get_test_suite():
- """
- return the unittest.TestSuite with all python-creole unittests for setup.py
- """
- suite = unittest.findTestCases(all_tests)
- return suite
-
-
-def run_unittests():
- """
- run all python-creole unittests with TextTestRunner
- """
- suite = get_test_suite()
- runner = unittest.TextTestRunner()
- runner.run(suite)
-
-
-if __name__ == '__main__':
- run_unittests()
-
diff --git a/creole/tests/all_tests.py b/creole/tests/all_tests.py
deleted file mode 100644
index c24cd74..0000000
--- a/creole/tests/all_tests.py
+++ /dev/null
@@ -1,140 +0,0 @@
-#!/usr/bin/env python
-# coding: utf-8
-
-"""
- collects all existing unittests
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- :copyleft: 2008-2012 by python-creole team, see AUTHORS for more details.
- :license: GNU GPL v3 or above, see LICENSE for more details.
-"""
-
-from __future__ import division, absolute_import, print_function, unicode_literals
-
-from doctest import testmod
-import os
-import sys
-import time
-import unittest
-
-try:
- import creole
-except ImportError as err:
- # running tests, but creole is not in sys.path
- raise ImportError("Seems that pyhton-creole is not installed, correctly: %s" % err)
-
-from creole.tests.test_creole2html import TestCreole2html, TestCreole2htmlMarkup, TestStr2Dict, TestDict2String
-from creole.tests.test_cross_compare_all import CrossCompareTests
-from creole.tests.test_cross_compare_creole import CrossCompareCreoleTests
-from creole.tests.test_cross_compare_rest import CrossCompareReStTests
-from creole.tests.test_cross_compare_textile import CrossCompareTextileTests
-from creole.tests.test_html2creole import TestHtml2Creole, TestHtml2CreoleMarkup
-from creole.tests.test_rest2html import ReSt2HtmlTests
-from creole.tests.test_setup_utils import SetupUtilsTests
-from creole.tests.test_utils import UtilsTests
-from creole.tests.utils.utils import MarkupTest
-
-import creole.tests
-
-
-SKIP_DIRS = (".settings", ".git", "dist", "python_creole.egg-info")
-SKIP_FILES = ("setup.py", "test.py")
-
-
-if "-v" in sys.argv or "--verbosity" in sys.argv:
- VERBOSE = 2
-elif "-q" in sys.argv or "--quite" in sys.argv:
- VERBOSE = 0
-else:
- VERBOSE = 1
-
-
-def run_all_doctests(verbosity=None):
- """
- run all python-creole DocTests
- """
- start_time = time.time()
- if verbosity is None:
- verbosity = VERBOSE
-
- path = os.path.abspath(os.path.dirname(creole.__file__))
- if verbosity >= 2:
- print("")
- print("_" * 79)
- print("Running %r DocTests:\n" % path)
-
- total_files = 0
- total_doctests = 0
- total_attempted = 0
- total_failed = 0
- for root, dirs, filelist in os.walk(path, followlinks=True):
- for skip_dir in SKIP_DIRS:
- if skip_dir in dirs:
- dirs.remove(skip_dir) # don't visit this directories
-
- for filename in filelist:
- if not filename.endswith(".py"):
- continue
- if filename in SKIP_FILES:
- continue
-
- total_files += 1
-
- sys.path.insert(0, root)
- try:
- m = __import__(filename[:-3])
- except ImportError as err:
- if verbosity >= 2:
- print("***DocTest import %s error*** %s" % (filename, err))
- except Exception as err:
- if verbosity >= 2:
- print("***DocTest %s error*** %s" % (filename, err))
- else:
- failed, attempted = testmod(m)
- total_attempted += attempted
- total_failed += failed
- if attempted or failed:
- total_doctests += 1
-
- if attempted and not failed:
- filepath = os.path.join(root, filename)
- if verbosity <= 1:
- sys.stdout.write(".")
- elif verbosity >= 2:
- print("DocTest in %s OK (failed=%i, attempted=%i)" % (
- filepath, failed, attempted
- ))
- finally:
- del sys.path[0]
-
- duration = time.time() - start_time
- print("")
- print("-"*70)
- print("Ran %i DocTests from %i files in %.3fs: failed=%i, attempted=%i\n\n" % (
- total_doctests, total_files, duration, total_failed, total_attempted
- ))
-
-
-def run_unittests(verbosity=None):
- """
- run all python-creole unittests with unittest CLI TestProgram()
- """
- if verbosity is None:
- verbosity = VERBOSE
-
- if verbosity >= 2:
- print("")
- print("_" * 79)
- print("Running Unittests:\n")
-
- if sys.version_info >= (2, 7):
- unittest.main(verbosity=verbosity)
- else:
- unittest.main()
-
-
-if __name__ == '__main__':
- # for e.g.:
- # coverage run creole/tests/all_tests.py
- run_all_doctests()
- run_unittests()
diff --git a/creole/tests/test_TODOs.py b/creole/tests/test_TODOs.py
index c2fb041..b396c86 100644
--- a/creole/tests/test_TODOs.py
+++ b/creole/tests/test_TODOs.py
@@ -11,17 +11,19 @@ from creole.html_tools.strip_html import strip_html
class StripHtml(unittest.TestCase):
+ @unittest.expectedFailure
def test_not_closed_image_tag(self):
output = strip_html('<p>a <img src="/image.jpg"> image.</p>')
self.assertEqual(output, '<p>a <img src="/image.jpg"> image.</p>')
+ @unittest.expectedFailure
def test_remove_linebreak(self):
output = strip_html('<strong>foo</strong>\n<ul><li>one</li></ul>')
self.assertEqual(output, '<strong>foo</strong><ul><li>one</li></ul>')
-
class CrossCompareCreoleTests(BaseCreoleTest):
+ @unittest.expectedFailure
def test_cross_lines_creole2html(self):
""" TODO: bold/italics cross lines in creole2html
see: http://code.google.com/p/python-creole/issues/detail?id=13
@@ -40,6 +42,7 @@ class CrossCompareCreoleTests(BaseCreoleTest):
"""
)
+ @unittest.expectedFailure
def test_cross_paragraphs(self):
""" TODO: bold/italics cross paragraphs in creole2html
see: http://code.google.com/p/python-creole/issues/detail?id=13
@@ -53,7 +56,7 @@ class CrossCompareCreoleTests(BaseCreoleTest):
<p>...able<em> to cross paragraphs.</em></p>
""")
-
+ @unittest.expectedFailure
def test_escape_inline(self):
""" TODO: different pre/code syntax?
"""
@@ -75,6 +78,7 @@ class CrossCompareCreoleTests(BaseCreoleTest):
class TestHtml2CreoleMarkup(BaseCreoleTest):
+ @unittest.expectedFailure
def test_format_in_a_text(self):
""" TODO: http://code.google.com/p/python-creole/issues/detail?id=4 """
self.assert_html2creole(r"""
@@ -83,7 +87,7 @@ class TestHtml2CreoleMarkup(BaseCreoleTest):
<a href="/url/"><strong>title</strong></a>
""")
-
+ @unittest.expectedFailure
def test_newline_before_headline(self):
""" TODO: http://code.google.com/p/python-creole/issues/detail?id=16#c5 """
self.assert_html2creole(r"""
@@ -95,6 +99,7 @@ class TestHtml2CreoleMarkup(BaseCreoleTest):
<h1>one</h1>
""")#, debug=True)
+ @unittest.expectedFailure
def test_no_space_before_blocktag(self):
""" TODO: Bug in html2creole.strip_html(): Don't add a space before/after block tags """
self.assert_html2creole(r"""
@@ -107,6 +112,7 @@ class TestHtml2CreoleMarkup(BaseCreoleTest):
"""#, debug=True
)
+ @unittest.expectedFailure
def test_escape_char(self):
self.assert_html2creole(r"""
~#1
@@ -122,6 +128,7 @@ class TestHtml2CreoleMarkup(BaseCreoleTest):
[[Link]]</p>
""")
+ @unittest.expectedFailure
def test_images(self):
self.assert_html2creole(r"""
a {{/image.jpg|JPG pictures}} and
@@ -140,7 +147,4 @@ class TestHtml2CreoleMarkup(BaseCreoleTest):
"""#, debug=True
)
-if __name__ == '__main__':
- unittest.main(
- verbosity=2
- )
+
diff --git a/creole/tests/test_cli.py b/creole/tests/test_cli.py
index 6febeff..52014bf 100644
--- a/creole/tests/test_cli.py
+++ b/creole/tests/test_cli.py
@@ -5,30 +5,96 @@
unittest for CLI
~~~~~~~~~~~~~~~~
- :copyleft: 2013 by python-creole team, see AUTHORS for more details.
+ :copyleft: 2013-2015 by python-creole team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
from __future__ import division, absolute_import, print_function, unicode_literals
+import subprocess
import unittest
import sys
+import os
import tempfile
+from creole.py3compat import PY3
from creole.tests.utils.base_unittest import BaseCreoleTest
-from creole.cmdline import cli_creole2html, cli_html2creole, cli_html2rest, \
- cli_html2textile
+from creole import VERSION_STRING
+
+
+CMDS = ("creole2html", "html2creole", "html2rest", "html2textile")
class CreoleCLITests(BaseCreoleTest):
- def setUp(self):
- super(CreoleCLITests, self).setUp()
- self._old_argv = sys.argv[:]
- def tearDown(self):
- super(CreoleCLITests, self).tearDown()
- sys.argv = self._old_argv
-
- def _test_convert(self, source_content, dest_content, cli_func):
+ CMD_PATH = None
+
+ @classmethod
+ def setUpClass(cls):
+ # FIXME: How can this be easier?!?
+ prog = CMDS[0]
+ cls.CMD_PATH = os.path.abspath(os.path.dirname(sys.executable))
+ if not os.path.isfile(os.path.join(cls.CMD_PATH, prog)):
+ for path in sys.path:
+ if os.path.isfile(os.path.join(path, prog)):
+ cls.CMD_PATH = path
+ break
+
+ def _subprocess(self, popen_args, verbose=True):
+ assert isinstance(popen_args, list)
+
+ # set absolute path to called cli program
+ prog = popen_args[0]
+ prog = os.path.join(self.CMD_PATH, prog)
+ self.assertTrue(os.path.isfile(prog), "File not found: %r" % prog)
+ self.assertTrue(os.access(prog, os.X_OK), "File %r is not executeable?!?" % prog)
+ popen_args[0] = prog
+
+ if verbose:
+ print("Call:", popen_args)
+
+ process = subprocess.Popen(popen_args,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ universal_newlines=True,
+ )
+ stdout, stderr = process.communicate()
+ retcode = process.poll()
+
+ if verbose:
+ print("return code: %r" % retcode)
+ print("stdout: %r" % stdout)
+ print("stderr: %r" % stderr)
+
+ stdout = stdout.strip()
+ stderr = stderr.strip()
+ return popen_args, retcode, stdout, stderr
+
+ def assertSubprocess(self, popen_args, retcode, stdout, stderr, verbose=True):
+ popen_args2, retcode2, stdout2, stderr2 = self._subprocess(popen_args, verbose)
+ try:
+ self.assertEqual(stdout, stdout2, "stdout wrong:")
+ self.assertEqual(stderr, stderr2, "stderr wrong:")
+ self.assertEqual(retcode, retcode2, "return code wrong:")
+ except AssertionError as err:
+ msg = (
+ "Error: %s"
+ "call via subprocess: %s\n"
+ "return code........: %r\n"
+ " ---------- [stdout] ---------- \n"
+ "%s\n"
+ " ---------- [stderr] ---------- \n"
+ "%s\n"
+ "-------------------------------"
+ ) % (
+ err,
+ repr(popen_args2), retcode2,
+ stdout2, stderr2,
+ )
+ self.fail(msg)
+
+ def _test_convert(self, source_content, dest_content, cli_str, verbose=True):
+ assert isinstance(source_content, bytes), type(source_content)
+ assert isinstance(dest_content, bytes), type(dest_content)
+
source_file = tempfile.NamedTemporaryFile()
sourcefilepath = source_file.name
source_file.write(source_content)
@@ -37,45 +103,81 @@ class CreoleCLITests(BaseCreoleTest):
dest_file = tempfile.NamedTemporaryFile()
destfilepath = dest_file.name
- sys.argv += [sourcefilepath, destfilepath]
- cli_func()
+ stdout=(
+ "Convert '%(src)s' to '%(dst)s' with %(prog)s (codec: utf-8)\n"
+ "done. '%(dst)s' created."
+ ) % {
+ "prog": cli_str,
+ "src": sourcefilepath,
+ "dst": destfilepath,
+ }
+
+ self.assertSubprocess(
+ popen_args=[cli_str, sourcefilepath, destfilepath],
+ retcode=0, stdout=stdout, stderr="",
+ verbose=False,
+ )
dest_file.seek(0)
result_content = dest_file.read()
-# print(dest_content)
+ result_content = result_content.decode("utf-8")
+ dest_content = dest_content.decode("utf-8")
self.assertEqual(result_content, dest_content)
+ def test_version(self):
+ for cmd in CMDS:
+ version_info = "%s from python-creole v%s" % (
+ cmd, VERSION_STRING
+ )
+ if PY3:
+ self.assertSubprocess(
+ popen_args=[cmd, "--version"],
+ retcode=0,
+ stdout=version_info,
+ stderr="",
+ verbose=False,
+ )
+ else:
+ self.assertSubprocess(
+ popen_args=[cmd, "--version"],
+ retcode=0,
+ stdout="",
+ stderr=version_info,
+ verbose=False,
+ )
+
def test_creole2html(self):
self._test_convert(
source_content=b"= test creole2html =",
dest_content=b"<h1>test creole2html</h1>",
- cli_func=cli_creole2html
+ cli_str="creole2html",
)
def test_html2creole(self):
self._test_convert(
source_content=b"<h1>test html2creole</h1>",
dest_content=b"= test html2creole",
- cli_func=cli_html2creole
+ cli_str="html2creole",
)
def test_html2rest(self):
self._test_convert(
source_content=b"<h1>test html2rest</h1>",
dest_content=(b"==============\n"
- "test html2rest\n"
- "=============="
+ b"test html2rest\n"
+ b"=============="
),
- cli_func=cli_html2rest
+ cli_str="html2rest",
)
def test_html2textile(self):
self._test_convert(
source_content=b"<h1>test html2textile</h1>",
dest_content=b"h1. test html2textile",
- cli_func=cli_html2textile
+ cli_str="html2textile",
)
+
if __name__ == '__main__':
unittest.main()
diff --git a/creole/tests/test_creole2html.py b/creole/tests/test_creole2html.py
index ef1d454..ec77fb8 100644
--- a/creole/tests/test_creole2html.py
+++ b/creole/tests/test_creole2html.py
@@ -369,25 +369,25 @@ class TestCreole2htmlMarkup(BaseCreoleTest):
def test_macro_basic(self):
"""
- Test the three diferent macro types with a "unittest macro"
+ Test the three different macro types with a "unittest macro"
"""
self.assert_creole2html(r"""
There exist three different macro types:
- A <<test_macro1 args="foo1">>bar1<</test_macro1>> in a line...
- ...a single <<test_macro1 foo="bar">> tag,
- or: <<test_macro1 a=1 b=2 />> closed...
+ A <<unittest_macro1 args="foo1">>bar1<</unittest_macro1>> in a line...
+ ...a single <<unittest_macro1 foo="bar">> tag,
+ or: <<unittest_macro1 a=1 b=2 />> closed...
a macro block:
- <<test_macro2 char="|">>
+ <<unittest_macro2 char="|">>
the
text
- <</test_macro2>>
+ <</unittest_macro2>>
the end
""", r"""
<p>There exist three different macro types:<br />
- A [test macro1 - kwargs: args='foo1',text='bar1'] in a line...<br />
- ...a single [test macro1 - kwargs: foo='bar',text=None] tag,<br />
- or: [test macro1 - kwargs: a=1,b=2,text=None] closed...</p>
+ A [test macro1 - kwargs: args="foo1",text="bar1"] in a line...<br />
+ ...a single [test macro1 - kwargs: foo="bar",text=null] tag,<br />
+ or: [test macro1 - kwargs: a=1,b=2,text=null] closed...</p>
<p>a macro block:</p>
the|text
@@ -450,7 +450,7 @@ class TestCreole2htmlMarkup(BaseCreoleTest):
<<summary>Some funky page summary.<</summary>>
""", r"""
<p>wrong macro line:<br />
- [Error: Wrong macro arguments: '>Some funky page summary.<</summary' for macro 'summary' (maybe wrong macro tag syntax?)]
+ [Error: Wrong macro arguments: ">Some funky page summary.<</summary" for macro 'summary' (maybe wrong macro tag syntax?)]
</p>
""", # verbose=True
)
@@ -935,18 +935,18 @@ class TestDict2String(unittest.TestCase):
def test_basic(self):
self.assertEqual(
dict2string({'key':'value'}),
- "key='value'"
+ 'key="value"'
)
def test_basic2(self):
self.assertEqual(
dict2string({'foo':"bar", "no":123}),
- "foo='bar' no=123"
+ 'foo="bar" no=123'
)
def test_basic3(self):
self.assertEqual(
dict2string({"foo":'bar', "no":"ABC"}),
- "foo='bar' no='ABC'"
+ 'foo="bar" no="ABC"'
)
if __name__ == '__main__':
diff --git a/creole/tests/test_cross_compare_creole.py b/creole/tests/test_cross_compare_creole.py
index 9127b66..6431fc0 100644
--- a/creole/tests/test_cross_compare_creole.py
+++ b/creole/tests/test_cross_compare_creole.py
@@ -419,12 +419,12 @@ class CrossCompareCreoleTests(BaseCreoleTest):
"""
self.cross_compare_creole("""
111 <<html>><x><</html>>foo<<html>></x><</html>> 222
- 333<<html>><x foo1='bar1'><</html>>foobar<<html>></x><</html>>444
+ 333<<html>><x foo1="bar1"><</html>>foobar<<html>></x><</html>>444
555<<html>><x /><</html>>666
""", """
<p>111 <x>foo</x> 222<br />
- 333<x foo1='bar1'>foobar</x>444</p>
+ 333<x foo1="bar1">foobar</x>444</p>
<p>555<x />666</p>
""",
diff --git a/creole/tests/test_html2creole.py b/creole/tests/test_html2creole.py
index 8eff25d..0fca58e 100644
--- a/creole/tests/test_html2creole.py
+++ b/creole/tests/test_html2creole.py
@@ -76,7 +76,7 @@ class TestHtml2CreoleMarkup(BaseCreoleTest):
"""
self.assert_html2creole(r"""
111 <<html>><unknown><</html>>foo<<html>></unknown><</html>> 222
- 333<<html>><unknown foo1='bar1' foo2='bar2'><</html>>foobar<<html>></unknown><</html>>444
+ 333<<html>><unknown foo1="bar1" foo2="bar2"><</html>>foobar<<html>></unknown><</html>>444
555<<html>><unknown /><</html>>666
""", """
@@ -95,12 +95,12 @@ class TestHtml2CreoleMarkup(BaseCreoleTest):
"""
self.assert_html2creole(r"""
111 &lt;unknown&gt;foo&lt;/unknown&gt; 222
- 333&lt;unknown foo1='bar1' foo2='bar2'&gt;foobar&lt;/unknown&gt;444
+ 333&lt;unknown foo1="bar1" foo2="bar2"&gt;foobar&lt;/unknown&gt;444
555&lt;unknown /&gt;666
""", """
<p>111 <unknown>foo</unknown> 222<br />
- 333<unknown foo1="bar1" foo2='bar2'>foobar</unknown>444</p>
+ 333<unknown foo1="bar1" foo2="bar2">foobar</unknown>444</p>
<p>555<unknown />666</p>
""",
diff --git a/creole/tests/test_html2rest.py b/creole/tests/test_html2rest.py
index ba957a4..9056d54 100644
--- a/creole/tests/test_html2rest.py
+++ b/creole/tests/test_html2rest.py
@@ -17,8 +17,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import unittest
-from creole.html2rest.emitter import Html2restException
-from creole.shared.unknown_tags import preformat_unknown_nodes
+from creole.emitter.html2rest_emitter import Html2restException
from creole.tests.utils.base_unittest import BaseCreoleTest
diff --git a/creole/tests/test_html2textile.py b/creole/tests/test_html2textile.py
index c27dcef..f02fced 100644
--- a/creole/tests/test_html2textile.py
+++ b/creole/tests/test_html2textile.py
@@ -67,10 +67,10 @@ class TextileTests(BaseCreoleTest):
"""
self.assert_html2textile(
textile_string="""
- 111 <<pre>><x><</pre>>foo<<pre>></x><</pre>> 222
- 333<<pre>><x foo1="bar1"><</pre>>foobar<<pre>></x><</pre>>444
-
- 555<<pre>><x /><</pre>>666
+ 111 foo 222
+ 333foobar444
+
+ 555666
""",
html_string="""
<p>111 <x>foo</x> 222<br />
diff --git a/creole/tests/test_macros.py b/creole/tests/test_macros.py
index 0bb4ce2..a5194f9 100644
--- a/creole/tests/test_macros.py
+++ b/creole/tests/test_macros.py
@@ -14,32 +14,30 @@
from __future__ import division, absolute_import, print_function, unicode_literals
-from creole.py3compat import repr2
+import json
-
-def test_macro1(**kwargs):
+def unittest_macro1(**kwargs):
"""
- >>> test_macro1(foo="bar")
- "[test macro1 - kwargs: foo='bar']"
+ >>> unittest_macro1(foo="bar")
+ '[test macro1 - kwargs: foo="bar"]'
- >>> test_macro1()
+ >>> unittest_macro1()
'[test macro1 - kwargs: ]'
- >>> test_macro1(a=1,b=2)
+ >>> unittest_macro1(a=1,b=2)
'[test macro1 - kwargs: a=1,b=2]'
"""
- kwargs = ','.join(['%s=%s' % (k, repr2(v)) for k, v in sorted(kwargs.items())])
+ kwargs = ','.join(['%s=%s' % (k, json.dumps(v)) for k, v in sorted(kwargs.items())])
return "[test macro1 - kwargs: %s]" % kwargs
-def test_macro2(char, text):
+def unittest_macro2(char, text):
"""
- >>> test_macro2(char="|", text="a\\nb")
+ >>> unittest_macro2(char="|", text="a\\nb")
'a|b'
"""
return char.join(text.split())
-
-if __name__ == "__main__":
+if __name__ == '__main__':
import doctest
- print(doctest.testmod())
+ print(doctest.testmod()) \ No newline at end of file
diff --git a/creole/tests/test_setup_utils.py b/creole/tests/test_setup_utils.py
index 52d897d..f7b2975 100644
--- a/creole/tests/test_setup_utils.py
+++ b/creole/tests/test_setup_utils.py
@@ -60,7 +60,7 @@ class SetupUtilsTests(BaseCreoleTest):
long_description = get_long_description(CREOLE_PACKAGE_ROOT, raise_errors=False)
self.assertIn("=====\nabout\n=====\n\n", long_description)
# Test created ReSt code
- from creole.rest2html.clean_writer import rest2html
+ from creole.rest_tools.clean_writer import rest2html
html = rest2html(long_description)
self.assertIn("<h1>about</h1>\n", html)
diff --git a/creole/tests/utils/base_unittest.py b/creole/tests/utils/base_unittest.py
index 92e906c..ee9343f 100644
--- a/creole/tests/utils/base_unittest.py
+++ b/creole/tests/utils/base_unittest.py
@@ -36,7 +36,7 @@ from creole.exceptions import DocutilsImportError
from creole import creole2html, html2creole, html2textile, html2rest
try:
- from creole.rest2html.clean_writer import rest2html
+ from creole.rest_tools.clean_writer import rest2html
except DocutilsImportError as err:
REST_INSTALLED = False
warnings.warn("Can't run all ReSt unittests: %s" % err)
diff --git a/creole/tests/utils/utils.py b/creole/tests/utils/utils.py
index ef202e0..5e2b24a 100644
--- a/creole/tests/utils/utils.py
+++ b/creole/tests/utils/utils.py
@@ -14,6 +14,7 @@
from __future__ import division, absolute_import, print_function, unicode_literals
import difflib
+import textwrap
import unittest
@@ -78,7 +79,6 @@ class MarkupTest(unittest.TestCase):
"""
prepare the multiline, indentation text.
"""
- #txt = unicode(txt)
txt = txt.splitlines()
assert txt[0] == "", "First assertion line must be empty! Is: %s" % repr(txt[0])
txt = txt[1:] # Skip the first line