From 123ef043dc7214c9818985aeea565a82c2680c0e Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 10 Dec 2016 11:36:32 +0100 Subject: add new xml/html pretty-printer :tada: --- test/mitmproxy/contentviews/test_html_outline.py | 2 +- test/mitmproxy/contentviews/test_xml_html.py | 29 ++++++++++++++++++++++ .../test_xml_html_data/cdata-formatted.xml | 10 ++++++++ .../contentviews/test_xml_html_data/cdata.xml | 10 ++++++++ .../test_xml_html_data/comment-formatted.xml | 10 ++++++++ .../contentviews/test_xml_html_data/comment.xml | 10 ++++++++ .../test_xml_html_data/inline-formatted.html | 14 +++++++++++ .../contentviews/test_xml_html_data/inline.html | 7 ++++++ .../test_xml_html_data/simple-formatted.html | 10 ++++++++ .../contentviews/test_xml_html_data/simple.html | 1 + 10 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 test/mitmproxy/contentviews/test_xml_html.py create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/cdata-formatted.xml create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/cdata.xml create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/comment-formatted.xml create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/comment.xml create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/inline-formatted.html create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/inline.html create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/simple-formatted.html create mode 100644 test/mitmproxy/contentviews/test_xml_html_data/simple.html (limited to 'test') diff --git a/test/mitmproxy/contentviews/test_html_outline.py b/test/mitmproxy/contentviews/test_html_outline.py index d9ccc406..9e664e52 100644 --- a/test/mitmproxy/contentviews/test_html_outline.py +++ b/test/mitmproxy/contentviews/test_html_outline.py @@ -6,4 +6,4 @@ def test_view_html_outline(): v = full_eval(html_outline.ViewHTMLOutline()) s = b"


one

" assert v(s) - assert v(b'\xfe') \ No newline at end of file + assert v(b'\xfe') diff --git a/test/mitmproxy/contentviews/test_xml_html.py b/test/mitmproxy/contentviews/test_xml_html.py new file mode 100644 index 00000000..899ecfde --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html.py @@ -0,0 +1,29 @@ +import pytest + +from mitmproxy.contentviews import xml_html +from mitmproxy.test import tutils +from . import full_eval + +data = tutils.test_data.push("mitmproxy/contentviews/test_xml_html_data/") + + +def test_simple(): + v = full_eval(xml_html.ViewXmlHtml()) + assert v(b"foo") == ('XML', [[('text', 'foo')]]) + assert v(b"") == ('HTML', [[('text', '')]]) + + +@pytest.mark.parametrize("filename", [ + "simple.html", + "cdata.xml", + "comment.xml", + "inline.html", +]) +def test_format_xml(filename): + path = data.path(filename) + with open(path) as f: + input = f.read() + with open(path.replace(".", "-formatted.")) as f: + expected = f.read() + tokens = xml_html.tokenize(input) + assert xml_html.format_xml(tokens) == expected diff --git a/test/mitmproxy/contentviews/test_xml_html_data/cdata-formatted.xml b/test/mitmproxy/contentviews/test_xml_html_data/cdata-formatted.xml new file mode 100644 index 00000000..44a81a83 --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/cdata-formatted.xml @@ -0,0 +1,10 @@ + + < " and & + or write things like + + but my document is still well formed! + ]]> + diff --git a/test/mitmproxy/contentviews/test_xml_html_data/cdata.xml b/test/mitmproxy/contentviews/test_xml_html_data/cdata.xml new file mode 100644 index 00000000..b4c5dfca --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/cdata.xml @@ -0,0 +1,10 @@ + + < " and & +or write things like + + but my document is still well formed! +]]> + \ No newline at end of file diff --git a/test/mitmproxy/contentviews/test_xml_html_data/comment-formatted.xml b/test/mitmproxy/contentviews/test_xml_html_data/comment-formatted.xml new file mode 100644 index 00000000..d0da6665 --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/comment-formatted.xml @@ -0,0 +1,10 @@ + + + diff --git a/test/mitmproxy/contentviews/test_xml_html_data/comment.xml b/test/mitmproxy/contentviews/test_xml_html_data/comment.xml new file mode 100644 index 00000000..3f54ddba --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/comment.xml @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/test/mitmproxy/contentviews/test_xml_html_data/inline-formatted.html b/test/mitmproxy/contentviews/test_xml_html_data/inline-formatted.html new file mode 100644 index 00000000..5253bf4f --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/inline-formatted.html @@ -0,0 +1,14 @@ + + + Test Page + + +

+ + Some things should be + inline + , some things shouldn't! +

+ + + diff --git a/test/mitmproxy/contentviews/test_xml_html_data/inline.html b/test/mitmproxy/contentviews/test_xml_html_data/inline.html new file mode 100644 index 00000000..3e4b16b9 --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/inline.html @@ -0,0 +1,7 @@ + +Test Page + +

Some things should be inline, some things shouldn't!

+ + + \ No newline at end of file diff --git a/test/mitmproxy/contentviews/test_xml_html_data/simple-formatted.html b/test/mitmproxy/contentviews/test_xml_html_data/simple-formatted.html new file mode 100644 index 00000000..23438428 --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/simple-formatted.html @@ -0,0 +1,10 @@ + + + + title + + +

Hello World

+ + + diff --git a/test/mitmproxy/contentviews/test_xml_html_data/simple.html b/test/mitmproxy/contentviews/test_xml_html_data/simple.html new file mode 100644 index 00000000..73e81a5e --- /dev/null +++ b/test/mitmproxy/contentviews/test_xml_html_data/simple.html @@ -0,0 +1 @@ +title

Hello World

-- cgit v1.2.3