-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest is clearly the preferred tool for testing in Python.
- Loading branch information
1 parent
d53b00c
commit 70e072f
Showing
10 changed files
with
249 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
|
||
from unittest import TestCase | ||
|
||
from mjml.helpers import borderParser | ||
|
||
|
||
class BorderParserTest(TestCase): | ||
def test_can_parse_css_none(self): | ||
self.assertEqual(0, borderParser('none')) | ||
def test_can_parse_css_none(): | ||
assert borderParser('none') == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
|
||
from io import StringIO | ||
from unittest import TestCase | ||
|
||
import pytest | ||
from schwarz.fakefs_helpers import FakeFS | ||
|
||
from mjml import mjml_to_html | ||
|
||
|
||
class IncludesWithUmlautsTest(TestCase): | ||
def test_can_properly_handle_include_umlauts(self): | ||
fs = FakeFS.set_up(test=self) | ||
included_mjml = ( | ||
'<mj-section>' | ||
' <mj-column>' | ||
' <mj-text>äöüß</mj-text>' | ||
' </mj-column>' | ||
'</mj-section>' | ||
) | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <mj-text>foo bar</mj-text>' | ||
' <mj-include path="./footer.mjml" />' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
fs.create_file('footer.mjml', contents=included_mjml.encode('utf8')) | ||
|
||
result = mjml_to_html(StringIO(mjml)) | ||
html = result.html | ||
|
||
assert ('äöüß' in html) | ||
@pytest.fixture | ||
def fs(): | ||
_fs = FakeFS.set_up() | ||
yield _fs | ||
_fs.tear_down() | ||
|
||
|
||
def test_can_properly_handle_include_umlauts(fs): | ||
included_mjml = ( | ||
'<mj-section>' | ||
' <mj-column>' | ||
' <mj-text>äöüß</mj-text>' | ||
' </mj-column>' | ||
'</mj-section>' | ||
) | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <mj-text>foo bar</mj-text>' | ||
' <mj-include path="./footer.mjml" />' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
fs.create_file('footer.mjml', contents=included_mjml.encode('utf8')) | ||
|
||
result = mjml_to_html(StringIO(mjml)) | ||
html = result.html | ||
|
||
assert ('äöüß' in html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,26 @@ | ||
|
||
from pathlib import Path | ||
from unittest import TestCase, expectedFailure | ||
|
||
from ddt import data as ddt_data, ddt as DataDrivenTestCase | ||
import pytest | ||
from htmlcompare import assert_same_html | ||
|
||
from mjml import mjml_to_html | ||
|
||
|
||
TESTDATA_DIR = Path(__file__).parent / 'missing_functionality' | ||
|
||
def patch_nose1(func): | ||
def _wrapper(test, *args, **kwargs): | ||
_patch_nose1_result(test) | ||
return func(test, *args, **kwargs) | ||
return _wrapper | ||
|
||
|
||
@DataDrivenTestCase | ||
class MissingFeaturesTest(TestCase): | ||
@ddt_data( | ||
) | ||
@expectedFailure | ||
@patch_nose1 | ||
def test_ensure_same_html(self, test_id): | ||
mjml_filename = f'{test_id}.mjml' | ||
html_filename = f'{test_id}-expected.html' | ||
with (TESTDATA_DIR / html_filename).open('rb') as html_fp: | ||
expected_html = html_fp.read() | ||
|
||
with (TESTDATA_DIR / mjml_filename).open('rb') as mjml_fp: | ||
result = mjml_to_html(mjml_fp) | ||
|
||
assert not result.errors | ||
actual_html = result.html | ||
assert_same_html(expected_html, actual_html, verbose=True) | ||
|
||
|
||
def _patch_nose1_result(test): | ||
# nose's TextTestResult does not support "expected failures" but I still | ||
# like that test runner. Just treat an expected failure like a skipped test. | ||
result = test._outcome.result | ||
if not hasattr(result, 'addExpectedFailure'): | ||
result.addExpectedFailure = result.addSkip | ||
if not hasattr(result, 'addUnexpectedSuccess'): | ||
def _addUnexpectedSuccess(test): | ||
error = (AssertionError, AssertionError('unexpected success'), None) | ||
return result.addFailure(test, error) | ||
result.addUnexpectedSuccess = _addUnexpectedSuccess | ||
# currently there are no tests which are expected to fail | ||
@pytest.mark.parametrize('test_id', []) | ||
@pytest.mark.xfail | ||
def test_missing_functionality(test_id): | ||
mjml_filename = f'{test_id}.mjml' | ||
html_filename = f'{test_id}-expected.html' | ||
with (TESTDATA_DIR / html_filename).open('rb') as html_fp: | ||
expected_html = html_fp.read() | ||
|
||
with (TESTDATA_DIR / mjml_filename).open('rb') as mjml_fp: | ||
result = mjml_to_html(mjml_fp) | ||
|
||
assert not result.errors | ||
actual_html = result.html | ||
assert_same_html(expected_html, actual_html, verbose=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,33 @@ | ||
|
||
import re | ||
from io import StringIO | ||
from unittest import TestCase | ||
|
||
import lxml.html | ||
|
||
from mjml import mjml_to_html | ||
|
||
|
||
class MjButtonMailtoLinkTest(TestCase): | ||
def test_no_target_for_mailto_links(self): | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <mj-button href="mailto:foo@site.example">Click me</mj-button>' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
def test_no_target_for_mailto_links(): | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <mj-button href="mailto:foo@site.example">Click me</mj-button>' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
|
||
result = mjml_to_html(StringIO(mjml)) | ||
html = result.html | ||
mailto_match = re.search('<a href="([^"]+?)"[^>]*>', html) | ||
start, end = mailto_match.span() | ||
match_str = html[start:end] | ||
result = mjml_to_html(StringIO(mjml)) | ||
html = result.html | ||
mailto_match = re.search('<a href="([^"]+?)"[^>]*>', html) | ||
start, end = mailto_match.span() | ||
match_str = html[start:end] | ||
|
||
a_el = lxml.html.fragment_fromstring(match_str) | ||
self.assertEqual('mailto:foo@site.example', a_el.attrib['href']) | ||
target = a_el.attrib.get('target') | ||
# Thunderbird opens a blank page instead of the new message window if | ||
# the <a> contains 'target="_blank"'. | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1677248 | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1589968 | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=421310 | ||
assert not target, f'target="{target}"' | ||
a_el = lxml.html.fragment_fromstring(match_str) | ||
assert a_el.attrib['href'] == 'mailto:foo@site.example' | ||
target = a_el.attrib.get('target') | ||
# Thunderbird opens a blank page instead of the new message window if | ||
# the <a> contains 'target="_blank"'. | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1677248 | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1589968 | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=421310 | ||
assert not target, f'target="{target}"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
|
||
from io import StringIO | ||
from unittest import TestCase | ||
|
||
from mjml import mjml_to_html | ||
|
||
|
||
class MJML2HTMLTest(TestCase): | ||
def test_can_handle_comments_in_mjml(self): | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <!-- empty -->' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
mjml_to_html(StringIO(mjml)) | ||
def test_can_handle_comments_in_mjml(): | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <!-- empty -->' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
mjml_to_html(StringIO(mjml)) |
Oops, something went wrong.