From 8526135372f80105a6451ad5c939735e695c39a1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 11 Dec 2017 01:32:41 +0100 Subject: [PATCH] m.htmlsanity: initial test. --- .gitignore | 2 + doc/plugins/htmlsanity-test.rst | 42 ------- doxygen/.gitignore | 3 - pelican-plugins/m/test/.gitignore | 1 + pelican-plugins/m/test/__init__.py | 55 +++++++++ .../m/test/htmlsanity_content/page.html | 107 ++++++++++++++++++ .../m/test/htmlsanity_content/page.rst | 62 ++++++++++ .../htmlsanity_typography/article-lang.html | 69 +++++++++++ .../htmlsanity_typography/articles/lang.rst | 8 ++ .../test/htmlsanity_typography/page-lang.html | 51 +++++++++ .../test/htmlsanity_typography/page-lang.rst | 7 ++ .../m/test/htmlsanity_typography/page.html | 79 +++++++++++++ .../m/test/htmlsanity_typography/page.rst | 35 ++++++ .../page.html | 51 +++++++++ .../page.rst | 5 + pelican-plugins/m/test/test_htmlsanity.py | 65 +++++++++++ 16 files changed, 597 insertions(+), 45 deletions(-) delete mode 100644 doc/plugins/htmlsanity-test.rst create mode 100644 pelican-plugins/m/test/.gitignore create mode 100644 pelican-plugins/m/test/__init__.py create mode 100644 pelican-plugins/m/test/htmlsanity_content/page.html create mode 100644 pelican-plugins/m/test/htmlsanity_content/page.rst create mode 100644 pelican-plugins/m/test/htmlsanity_typography/article-lang.html create mode 100644 pelican-plugins/m/test/htmlsanity_typography/articles/lang.rst create mode 100644 pelican-plugins/m/test/htmlsanity_typography/page-lang.html create mode 100644 pelican-plugins/m/test/htmlsanity_typography/page-lang.rst create mode 100644 pelican-plugins/m/test/htmlsanity_typography/page.html create mode 100644 pelican-plugins/m/test/htmlsanity_typography/page.rst create mode 100644 pelican-plugins/m/test/htmlsanity_typography_global_lang/page.html create mode 100644 pelican-plugins/m/test/htmlsanity_typography_global_lang/page.rst create mode 100644 pelican-plugins/m/test/test_htmlsanity.py diff --git a/.gitignore b/.gitignore index 1e0752e8..c156db4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ __pycache__ +htmlcov +.coverage *.kdev4 diff --git a/doc/plugins/htmlsanity-test.rst b/doc/plugins/htmlsanity-test.rst deleted file mode 100644 index 9acb94e6..00000000 --- a/doc/plugins/htmlsanity-test.rst +++ /dev/null @@ -1,42 +0,0 @@ -.. - This file is part of m.css. - - Copyright © 2017 Vladimír Vondruš - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -.. - -Test -#### - -:save_as: plugins/htmlsanity/test/index.html -:breadcrumb: {filename}/plugins.rst Pelican plugins - {filename}/plugins/htmlsanity.rst HTML sanity - -Inline preformatted blocks should be escaped: ``
`` - -Inline preformatted blocks should have whitespace preserved: ``two spaces between words`` - -Preformatted blocks should have sane rendering:: - - helllo - - world - -Inline code shouldn't be hyphenated or with smart quotes applied: ``"hello" --- isn't this working?"``. diff --git a/doxygen/.gitignore b/doxygen/.gitignore index 02d74dea..68f19739 100644 --- a/doxygen/.gitignore +++ b/doxygen/.gitignore @@ -1,5 +1,2 @@ -__pycache__ -htmlcov test/*/html/ test/*/xml/ -.coverage diff --git a/pelican-plugins/m/test/.gitignore b/pelican-plugins/m/test/.gitignore new file mode 100644 index 00000000..beeea249 --- /dev/null +++ b/pelican-plugins/m/test/.gitignore @@ -0,0 +1 @@ +*/output/ diff --git a/pelican-plugins/m/test/__init__.py b/pelican-plugins/m/test/__init__.py new file mode 100644 index 00000000..3cfe1bd6 --- /dev/null +++ b/pelican-plugins/m/test/__init__.py @@ -0,0 +1,55 @@ +import os +import shutil +import unittest + +from pelican import read_settings, Pelican + +class PluginTestCase(unittest.TestCase): + def __init__(self, path, dir, *args, **kwargs): + unittest.TestCase.__init__(self, *args, **kwargs) + # Source files for test_something.py are in something_{dir}/ subdirectory + self.path = os.path.join(os.path.dirname(os.path.realpath(path)), os.path.splitext(os.path.basename(path))[0][5:] + ('_' + dir if dir else '')) + + # Display ALL THE DIFFS + self.maxDiff = None + + def setUp(self): + if os.path.exists(os.path.join(self.path, 'output')): shutil.rmtree(os.path.join(self.path, 'output')) + + def run_pelican(self, settings): + implicit_settings = { + # Contains just stuff that isn't required by the m.css theme itself, + # but is needed to have the test setup working correctly + 'RELATIVE_URLS': True, + 'TIMEZONE': 'UTC', + 'READERS': {'html': None}, + 'SITEURL': '.', + 'PATH': os.path.join(self.path), + 'OUTPUT_PATH': os.path.join(self.path, 'output'), + 'PAGE_PATHS': [''], + 'PAGE_SAVE_AS': '{slug}.html', + 'PAGE_URL': '{slug}.html', + 'PAGE_EXCLUDES': ['output'], + 'ARTICLE_PATHS': ['articles'], # does not exist + 'FEED_ALL_ATOM': None, # Don't render feeds, we're not testing them *ever* + 'THEME': '../pelican-theme', + 'PLUGIN_PATHS': ['.'], + 'THEME_STATIC_DIR': 'static', + 'M_CSS_FILES': ['https://fonts.googleapis.com/css?family=Source+Code+Pro:400,400i,600%7CSource+Sans+Pro:400,400i,600,600i', + 'static/m-dark.css'], + 'M_FINE_PRINT': None, + 'DIRECT_TEMPLATES': [], + 'SLUGIFY_SOURCE': 'basename' + } + settings = read_settings(path=None, override={**implicit_settings, **settings}) + pelican = Pelican(settings=settings) + pelican.run() + + def actual_expected_contents(self, actual, expected = None): + if not expected: expected = actual + + with open(os.path.join(self.path, expected)) as f: + expected_contents = f.read().strip() + with open(os.path.join(self.path, 'output', actual)) as f: + actual_contents = f.read().strip() + return actual_contents, expected_contents diff --git a/pelican-plugins/m/test/htmlsanity_content/page.html b/pelican-plugins/m/test/htmlsanity_content/page.html new file mode 100644 index 00000000..7ca916a1 --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_content/page.html @@ -0,0 +1,107 @@ + + + + + A page | A Pelican Blog + + + + + + + + + + + + + +
+
+
+
+
+
+

A page

+ + +

A paragraph.

+
+A block quote.
+

+Hand
+wrapped
+content
+

+
Code with <all> the & "things" escaped and
+                                       weird whitespace
+                                       preserved
+
    +
  • An unordered list
  • +
  • Another item
      +
    1. Sub-list, ordered
    2. +
    3. Another item
    4. +
    +
  • +
  • Third item of the top-level list
  • +
+ + + + + + + + + + + + + + +
Heading 1Heading 2
Cell 1Table cell 2
Row 2Row 2 cell 2
+
+
Term 1
+
Description
+
Term 2
+
Description of term 2
+
+
+

Section title

+

An emphasised text, strong text and a literal. Link to +Google, the heading below or just an +URL as-is: https://mcss.mosra.cz/. E-mail. A footnote +reference: 1

+
+
1
+
A footnote description
+
+ +
+ +
+
+
+
+
+ + diff --git a/pelican-plugins/m/test/htmlsanity_content/page.rst b/pelican-plugins/m/test/htmlsanity_content/page.rst new file mode 100644 index 00000000..e0fd5b2f --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_content/page.rst @@ -0,0 +1,62 @@ +A page +###### + +:summary: no. + +.. contents:: + :class: m-block m-default + +A paragraph. + + A block quote. + +| Hand +| wrapped +| content + +:: + + Code with the & "things" escaped and + weird whitespace + preserved + +- An unordered list +- Another item + + 1. Sub-list, ordered + 2. Another item + +- Third item of the top-level list + +.. class:: m-table + +========= ============ +Heading 1 Heading 2 +========= ============ +Cell 1 Table cell 2 +Row 2 Row 2 cell 2 +========= ============ + +Term 1 + Description +Term 2 + Description of term 2 + +Section title +============= + +An *emphasised text*, **strong text** and a ``literal``. Link to +`Google `_, `the heading below <#a-heading>`_ or just an +URL as-is: https://mcss.mosra.cz/. `E-mail `_. A footnote +reference: [1]_ + +.. [1] A footnote description + +`Section title with link`_ +-------------------------- + +A line: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +And a paragraph after. diff --git a/pelican-plugins/m/test/htmlsanity_typography/article-lang.html b/pelican-plugins/m/test/htmlsanity_typography/article-lang.html new file mode 100644 index 00000000..5d385fc3 --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_typography/article-lang.html @@ -0,0 +1,69 @@ + + + + + Article in different language | A Pelican Blog + + + + + + + + + + + + + + +
+
+
+
+
+
+

+ + Article in different language +

+

Text to­ho­to člán­ku je čes­ky (při­Äemž DEFAULT_LANG je 'en') a měl by + te­dy mít čes­ké dě­le­ní slov. „A ta­ké čes­ké uvo­zov­ky.“

+
+
+ +

Text to­ho­to člán­ku je čes­ky (při­Äemž DEFAULT_LANG je 'en') a měl by +te­dy mít čes­ké dě­le­ní slov. „A ta­ké čes­ké uvo­zov­ky.“

+ +
+

Posted on in articles.

+
+
+ +
+
+
+
+ + diff --git a/pelican-plugins/m/test/htmlsanity_typography/articles/lang.rst b/pelican-plugins/m/test/htmlsanity_typography/articles/lang.rst new file mode 100644 index 00000000..4e22a812 --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_typography/articles/lang.rst @@ -0,0 +1,8 @@ +Article in different language +############################# + +:date: 2017-12-10 +:lang: cs + +Text tohoto článku je česky (přičemž ``DEFAULT_LANG`` je ``'en'``) a měl by +tedy mít české dělení slov. "A také české uvozovky." diff --git a/pelican-plugins/m/test/htmlsanity_typography/page-lang.html b/pelican-plugins/m/test/htmlsanity_typography/page-lang.html new file mode 100644 index 00000000..9b576d19 --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_typography/page-lang.html @@ -0,0 +1,51 @@ + + + + + Page in different language | A Pelican Blog + + + + + + + + + + + + + +
+
+
+
+
+
+

Page in different language

+ +

Text té­to strán­ky je čes­ky (při­Äemž DEFAULT_LANG je 'en') a měl by te­dy +mít čes­ké dě­le­ní slov. „A ta­ké čes­ké uvo­zov­ky.“

+ +
+
+
+
+
+
+ + diff --git a/pelican-plugins/m/test/htmlsanity_typography/page-lang.rst b/pelican-plugins/m/test/htmlsanity_typography/page-lang.rst new file mode 100644 index 00000000..2610d11c --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_typography/page-lang.rst @@ -0,0 +1,7 @@ +Page in different language +########################## + +:lang: cs + +Text této stránky je česky (přičemž ``DEFAULT_LANG`` je ``'en'``) a měl by tedy +mít české dělení slov. "A také české uvozovky." diff --git a/pelican-plugins/m/test/htmlsanity_typography/page.html b/pelican-plugins/m/test/htmlsanity_typography/page.html new file mode 100644 index 00000000..1dbcf191 --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_typography/page.html @@ -0,0 +1,79 @@ + + + + + Page title should not be hyphenated. “But quotes yes.” | A Pelican Blog + + + + + + + + + + + + + + + +
+
+
+
+
+ +

A head­er that should be hy­phen­at­ed. “Quotes.”

+ +
+
+
+
+
+
+
+

Page title should not be hyphenated. “But quotes yes.”

+ +

Page con­tent should be hy­phen­at­ed. But "code" should not be hyphenated.

+
Neither preformatted text. "No quotes for you."
+
+Nest­ed con­tent should be hy­phen­at­ed al­so! And al­so bold sec­tions or +ital­ics text. Oh and “quotes should be smart” — with prop­er em-dash, +8–22 (en-dash) and el­lip­sis…
+

Link ti­tles can be hy­phen­at­ed as well. But in­line +ver­ba­tim stuff shouldn’t: hello "this" is not hyphenated. Nei­ther +ver­ba­tim blocks:

+"quote" hyphenation

Od­sta­vec v čeÅ¡­ti­ně. „Uvo­zov­ky“ fun­gu­jí ji­nak a dě­le­ní slov jakbys­met.

+ +
+
+
+
+
+
+
+ +

The foot­er should be hy­phen­at­ed as well. “Quotes.”

+ +
+
+
+
+
+ + diff --git a/pelican-plugins/m/test/htmlsanity_typography/page.rst b/pelican-plugins/m/test/htmlsanity_typography/page.rst new file mode 100644 index 00000000..f4291818 --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_typography/page.rst @@ -0,0 +1,35 @@ +Page title should not be hyphenated. "But quotes yes." +###################################################### + +:header: A header that *should be* hyphenated. "Quotes." +:footer: The footer *should be* hyphenated as well. "Quotes." +:summary: Page summary in the meta tag should not be hyphenated. "But quotes yes." +:description: Neither the description. "But quotes yes." +:css: and-definitely-not-css-links.css + +.. role:: raw-html(raw) + :format: html + +Page content should be hyphenated. ``But "code" should not be hyphenated.`` + +:: + + Neither preformatted text. "No quotes for you." + +.. container:: m-note m-info + + Nested content should be hyphenated also! And also **bold sections** or + *italics text*. Oh and "quotes should be smart" --- with proper em-dash, + 8--22 (en-dash) and ellipsis... + +`Link titles can be hyphenated as well. `_ But inline +verbatim stuff shouldn't: :raw-html:`hello "this" is not hyphenated`. Neither +verbatim blocks: + +.. raw:: html + + "quote" hyphenation + +.. class:: language-cs + + Odstavec v češtině. "Uvozovky" fungují jinak a dělení slov jakbysmet. diff --git a/pelican-plugins/m/test/htmlsanity_typography_global_lang/page.html b/pelican-plugins/m/test/htmlsanity_typography_global_lang/page.html new file mode 100644 index 00000000..49cdfba7 --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_typography_global_lang/page.html @@ -0,0 +1,51 @@ + + + + + Hyphenation in other languages | A Pelican Blog + + + + + + + + + + + + + +
+
+
+
+
+
+

Hyphenation in other languages

+ +

Text vÅ¡ech strá­nek je čes­ky (DEFAULT_LANG je 'cs') a měl by mít te­dy +čes­ké dě­le­ní slov. „A ta­ké čes­ké uvo­zov­ky.“

+ +
+
+
+
+
+ + + diff --git a/pelican-plugins/m/test/htmlsanity_typography_global_lang/page.rst b/pelican-plugins/m/test/htmlsanity_typography_global_lang/page.rst new file mode 100644 index 00000000..fd9814e1 --- /dev/null +++ b/pelican-plugins/m/test/htmlsanity_typography_global_lang/page.rst @@ -0,0 +1,5 @@ +Hyphenation in other languages +############################## + +Text vÅ¡ech stránek je česky (``DEFAULT_LANG`` je ``'cs'``) a měl by mít tedy +české dělení slov. "A také české uvozovky." diff --git a/pelican-plugins/m/test/test_htmlsanity.py b/pelican-plugins/m/test/test_htmlsanity.py new file mode 100644 index 00000000..b9fff16a --- /dev/null +++ b/pelican-plugins/m/test/test_htmlsanity.py @@ -0,0 +1,65 @@ +from m.test import PluginTestCase + +class Content(PluginTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'content', *args, **kwargs) + + def test(self): + self.run_pelican({ + 'PLUGINS': ['m.htmlsanity'] + }) + + # Verify there's no superfluous markup or useless classes + self.assertEqual(*self.actual_expected_contents('page.html')) + +class Typography(PluginTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'typography', *args, **kwargs) + + def test(self): + self.run_pelican({ + # Need extended Latin characters for Czech text + 'M_CSS_FILES': ['https://fonts.googleapis.com/css?family=Source+Code+Pro:400,400i,600%7CSource+Sans+Pro:400,400i,600,600i&subset=latin-ext', + 'static/m-dark.css'], + 'PLUGINS': ['m.htmlsanity'], + 'M_HTMLSANITY_HYPHENATION': True, + 'M_HTMLSANITY_SMART_QUOTES': True, + 'M_FINE_PRINT': "The footer should be hyphenated as well. \"And with smart quotes.\"", + 'DATE_FORMATS': {'cs': ('en_US.UTF-8', '%b %d, %Y')}, + 'PAGE_LANG_SAVE_AS': '{slug}.html', + 'ARTICLE_SAVE_AS': 'article-{slug}.html', + 'ARTICLE_LANG_SAVE_AS': 'article-{slug}.html', + 'FORMATTED_FIELDS': ['summary', 'description', 'header', 'footer'], + + # Disable unneeded stuff + 'TRANSLATION_FEED_ATOM': None, + 'CATEGORY_FEED_ATOM': None, + 'CATEGORY_SAVE_AS': '', + }) + + # The ­ should be at proper places and not where it shouldn't be. + self.assertEqual(*self.actual_expected_contents('page.html')) + + # The lang element should be set correctly as well. + self.assertEqual(*self.actual_expected_contents('page-lang.html')) + self.assertEqual(*self.actual_expected_contents('article-lang.html')) + +class TypographyGlobalLang(PluginTestCase): + def __init__(self, *args, **kwargs): + super().__init__(__file__, 'typography_global_lang', *args, **kwargs) + + def test(self): + self.run_pelican({ + # Need extended Latin characters for Czech text + 'M_CSS_FILES': ['https://fonts.googleapis.com/css?family=Source+Code+Pro:400,400i,600%7CSource+Sans+Pro:400,400i,600,600i&subset=latin-ext', + 'static/m-dark.css'], + 'PLUGINS': ['m.htmlsanity'], + 'DEFAULT_LANG': 'cs', + 'M_HTMLSANITY_HYPHENATION': True, + 'M_HTMLSANITY_SMART_QUOTES': True, + 'M_FINE_PRINT': "Patička má dělení slov také. \"A chytré uvozovky.\"" + }) + + # The lang element should be set correctly and the ­ should + # be at proper places and not where it shouldn't be. + self.assertEqual(*self.actual_expected_contents('page.html')) -- 2.30.2