コード例 #1
0
ファイル: test_readers.py プロジェクト: bnice5000/pelican
    def test_typogrify_ignore_tags(self):
        try:
            # typogrify should be able to ignore user specified tags,
            # but tries to be clever with widont extension
            page = self.read_file(path="article.rst", TYPOGRIFY=True, TYPOGRIFY_IGNORE_TAGS=["p"])
            expected = (
                "<p>THIS is some content. With some stuff to&nbsp;"
                "&quot;typogrify&quot;...</p>\n<p>Now with added "
                'support for <abbr title="three letter acronym">'
                "TLA</abbr>.</p>\n"
            )

            self.assertEqual(page.content, expected)

            # typogrify should ignore code blocks by default because
            # code blocks are composed inside the pre tag
            page = self.read_file(path="article_with_code_block.rst", TYPOGRIFY=True)

            expected = (
                "<p>An article with some&nbsp;code</p>\n"
                '<div class="highlight"><pre><span></span>'
                '<span class="n">x</span>'
                ' <span class="o">&amp;</span>'
                ' <span class="n">y</span>\n</pre></div>\n'
                "<p>A block&nbsp;quote:</p>\n<blockquote>\nx "
                '<span class="amp">&amp;</span> y</blockquote>\n'
                "<p>Normal:\nx"
                ' <span class="amp">&amp;</span>'
                "&nbsp;y"
                "</p>\n"
            )

            self.assertEqual(page.content, expected)

            # instruct typogrify to also ignore blockquotes
            page = self.read_file(
                path="article_with_code_block.rst", TYPOGRIFY=True, TYPOGRIFY_IGNORE_TAGS=["blockquote"]
            )

            expected = (
                "<p>An article with some&nbsp;code</p>\n"
                '<div class="highlight"><pre><span>'
                '</span><span class="n">x</span>'
                ' <span class="o">&amp;</span>'
                ' <span class="n">y</span>\n</pre></div>\n'
                "<p>A block&nbsp;quote:</p>\n<blockquote>\nx "
                "&amp; y</blockquote>\n"
                "<p>Normal:\nx"
                ' <span class="amp">&amp;</span>'
                "&nbsp;y"
                "</p>\n"
            )

            self.assertEqual(page.content, expected)
        except ImportError:
            return unittest.skip("need the typogrify distribution")
        except TypeError:
            return unittest.skip("need typogrify version 2.0.4 or later")
コード例 #2
0
    def test_typogrify_ignore_tags(self):
        try:
            # typogrify should be able to ignore user specified tags,
            # but tries to be clever with widont extension
            page = self.read_file(path='article.rst',
                                  TYPOGRIFY=True,
                                  TYPOGRIFY_IGNORE_TAGS=['p'])
            expected = ('<p>THIS is some content. With some stuff to&nbsp;'
                        '&quot;typogrify&quot;...</p>\n<p>Now with added '
                        'support for <abbr title="three letter acronym">'
                        'TLA</abbr>.</p>\n')

            self.assertEqual(page.content, expected)

            # typogrify should ignore code blocks by default because
            # code blocks are composed inside the pre tag
            page = self.read_file(path='article_with_code_block.rst',
                                  TYPOGRIFY=True)

            expected = ('<p>An article with some&nbsp;code</p>\n'
                        '<div class="highlight"><pre><span></span>'
                        '<span class="n">x</span>'
                        ' <span class="o">&amp;</span>'
                        ' <span class="n">y</span>\n</pre></div>\n'
                        '<p>A block&nbsp;quote:</p>\n<blockquote>\nx '
                        '<span class="amp">&amp;</span> y</blockquote>\n'
                        '<p>Normal:\nx'
                        ' <span class="amp">&amp;</span>'
                        '&nbsp;y'
                        '</p>\n')

            self.assertEqual(page.content, expected)

            # instruct typogrify to also ignore blockquotes
            page = self.read_file(path='article_with_code_block.rst',
                                  TYPOGRIFY=True,
                                  TYPOGRIFY_IGNORE_TAGS=['blockquote'])

            expected = ('<p>An article with some&nbsp;code</p>\n'
                        '<div class="highlight"><pre><span>'
                        '</span><span class="n">x</span>'
                        ' <span class="o">&amp;</span>'
                        ' <span class="n">y</span>\n</pre></div>\n'
                        '<p>A block&nbsp;quote:</p>\n<blockquote>\nx '
                        '&amp; y</blockquote>\n'
                        '<p>Normal:\nx'
                        ' <span class="amp">&amp;</span>'
                        '&nbsp;y'
                        '</p>\n')

            self.assertEqual(page.content, expected)
        except ImportError:
            return unittest.skip('need the typogrify distribution')
        except TypeError:
            return unittest.skip('need typogrify version 2.0.4 or later')
コード例 #3
0
ファイル: test_readers.py プロジェクト: bnice5000/pelican
    def test_typogrify_summary(self):
        # if nothing is specified in the settings, the summary should be
        # unmodified
        page = self.read_file(path="article_with_metadata.rst")
        expected = (
            '<p class="first last">Multi-line metadata should be'
            " supported\nas well as <strong>inline"
            " markup</strong> and stuff to &quot;typogrify"
            "&quot;...</p>\n"
        )

        self.assertEqual(page.metadata["summary"], expected)

        try:
            # otherwise, typogrify should be applied
            page = self.read_file(path="article_with_metadata.rst", TYPOGRIFY=True)
            expected = (
                '<p class="first last">Multi-line metadata should be'
                " supported\nas well as <strong>inline"
                " markup</strong> and stuff to&nbsp;&#8220;typogrify"
                "&#8221;&#8230;</p>\n"
            )

            self.assertEqual(page.metadata["summary"], expected)
        except ImportError:
            return unittest.skip("need the typogrify distribution")
コード例 #4
0
ファイル: test_readers.py プロジェクト: bnice5000/pelican
    def test_typogrify(self):
        # if nothing is specified in the settings, the content should be
        # unmodified
        page = self.read_file(path="article.rst")
        expected = (
            "<p>THIS is some content. With some stuff to "
            "&quot;typogrify&quot;...</p>\n<p>Now with added "
            'support for <abbr title="three letter acronym">'
            "TLA</abbr>.</p>\n"
        )

        self.assertEqual(page.content, expected)

        try:
            # otherwise, typogrify should be applied
            page = self.read_file(path="article.rst", TYPOGRIFY=True)
            expected = (
                '<p><span class="caps">THIS</span> is some content. '
                "With some stuff to&nbsp;&#8220;typogrify&#8221;&#8230;</p>\n"
                '<p>Now with added support for <abbr title="three letter '
                'acronym"><span class="caps">TLA</span></abbr>.</p>\n'
            )

            self.assertEqual(page.content, expected)
        except ImportError:
            return unittest.skip("need the typogrify distribution")
コード例 #5
0
    def test_datetime(self):
        # If DATETIME is set to a tuple, it should be used to override LOCALE
        dt = SafeDatetime(2015, 9, 13)

        page_kwargs = self._copy_page_kwargs()

        # set its date to dt
        page_kwargs['metadata']['date'] = dt
        page = Page(**page_kwargs)

        # page.locale_date is a unicode string in both python2 and python3
        dt_date = dt.strftime(DEFAULT_CONFIG['DEFAULT_DATE_FORMAT'])
        # dt_date is a byte string in python2, and a unicode string in python3
        # Let's make sure it is a unicode string (relies on python 3.3 supporting the u prefix)
        if type(dt_date) != type(u''):
            # python2:
            dt_date = unicode(dt_date, 'utf8')

        self.assertEqual(page.locale_date, dt_date)
        page_kwargs['settings'] = get_settings()

        # I doubt this can work on all platforms ...
        if platform == "win32":
            locale = 'jpn'
        else:
            locale = 'ja_JP.utf8'
        page_kwargs['settings']['DATE_FORMATS'] = {
            'jp': (locale, '%Y-%m-%d(%a)')
        }
        page_kwargs['metadata']['lang'] = 'jp'

        import locale as locale_module
        try:
            page = Page(**page_kwargs)
            self.assertEqual(page.locale_date, '2015-09-13(\u65e5)')
        except locale_module.Error:
            # The constructor of ``Page`` will try to set the locale to
            # ``ja_JP.utf8``. But this attempt will failed when there is no
            # such locale in the system. You can see which locales there are
            # in your system with ``locale -a`` command.
            #
            # Until we find some other method to test this functionality, we
            # will simply skip this test.
            unittest.skip("There is no locale %s in this system." % locale)
コード例 #6
0
ファイル: test_contents.py プロジェクト: Windeal/pelican
    def test_datetime(self):
        # If DATETIME is set to a tuple, it should be used to override LOCALE
        dt = SafeDatetime(2015, 9, 13)

        page_kwargs = self._copy_page_kwargs()

        # set its date to dt
        page_kwargs['metadata']['date'] = dt
        page = Page(**page_kwargs)

        # page.locale_date is a unicode string in both python2 and python3
        dt_date = dt.strftime(DEFAULT_CONFIG['DEFAULT_DATE_FORMAT']) 
        # dt_date is a byte string in python2, and a unicode string in python3
        # Let's make sure it is a unicode string (relies on python 3.3 supporting the u prefix)
        if type(dt_date) != type(u''):
            # python2:
            dt_date = unicode(dt_date, 'utf8')

        self.assertEqual(page.locale_date, dt_date )
        page_kwargs['settings'] = get_settings()

        # I doubt this can work on all platforms ...
        if platform == "win32":
            locale = 'jpn'
        else:
            locale = 'ja_JP.utf8'
        page_kwargs['settings']['DATE_FORMATS'] = {'jp': (locale,
                                                          '%Y-%m-%d(%a)')}
        page_kwargs['metadata']['lang'] = 'jp'

        import locale as locale_module
        try:
            page = Page(**page_kwargs)
            self.assertEqual(page.locale_date, '2015-09-13(\u65e5)')
        except locale_module.Error:
            # The constructor of ``Page`` will try to set the locale to
            # ``ja_JP.utf8``. But this attempt will failed when there is no
            # such locale in the system. You can see which locales there are
            # in your system with ``locale -a`` command.
            #
            # Until we find some other method to test this functionality, we
            # will simply skip this test.
            unittest.skip("There is no locale %s in this system." % locale)
コード例 #7
0
ファイル: test_contents.py プロジェクト: dmpeters/pelican
    def test_datetime(self):
        # If DATETIME is set to a tuple, it should be used to override LOCALE
        dt = datetime(2015, 9, 13)

        page_kwargs = self._copy_page_kwargs()

        # set its date to dt
        page_kwargs["metadata"]["date"] = dt
        page = Page(**page_kwargs)

        self.assertEqual(page.locale_date, dt.strftime(DEFAULT_CONFIG["DEFAULT_DATE_FORMAT"]))

        page_kwargs["settings"] = get_settings()

        # I doubt this can work on all platforms ...
        if platform == "win32":
            locale = "jpn"
        else:
            locale = "ja_JP.utf8"
        page_kwargs["settings"]["DATE_FORMATS"] = {"jp": (locale, "%Y-%m-%d(%a)")}
        page_kwargs["metadata"]["lang"] = "jp"

        import locale as locale_module

        try:
            page = Page(**page_kwargs)
            self.assertEqual(page.locale_date, "2015-09-13(\u65e5)")
        except locale_module.Error:
            # The constructor of ``Page`` will try to set the locale to
            # ``ja_JP.utf8``. But this attempt will failed when there is no
            # such locale in the system. You can see which locales there are
            # in your system with ``locale -a`` command.
            #
            # Until we find some other method to test this functionality, we
            # will simply skip this test.
            unittest.skip("There is no locale %s in this system." % locale)
コード例 #8
0
    def test_typogrify(self):
        # if nothing is specified in the settings, the content should be
        # unmodified
        page = self.read_file(path='article.rst')
        expected = ('<p>This is some content. With some stuff to '
                    '&quot;typogrify&quot;.</p>\n<p>Now with added '
                    'support for <abbr title="three letter acronym">'
                    'TLA</abbr>.</p>\n')

        self.assertEqual(page.content, expected)

        try:
            # otherwise, typogrify should be applied
            page = self.read_file(path='article.rst', TYPOGRIFY=True)
            expected = ('<p>This is some content. With some stuff to&nbsp;'
                        '&#8220;typogrify&#8221;.</p>\n<p>Now with added '
                        'support for <abbr title="three letter acronym">'
                        '<span class="caps">TLA</span></abbr>.</p>\n')

            self.assertEqual(page.content, expected)
        except ImportError:
            return unittest.skip('need the typogrify distribution')
コード例 #9
0
ファイル: test_readers.py プロジェクト: KearneyLiu/pelican
    def test_typogrify(self):
        # if nothing is specified in the settings, the content should be
        # unmodified
        page = self.read_file(path='article.rst')
        expected = ('<p>This is some content. With some stuff to '
                    '&quot;typogrify&quot;.</p>\n<p>Now with added '
                    'support for <abbr title="three letter acronym">'
                    'TLA</abbr>.</p>\n')

        self.assertEqual(page.content, expected)

        try:
            # otherwise, typogrify should be applied
            page = self.read_file(path='article.rst', TYPOGRIFY=True)
            expected = ('<p>This is some content. With some stuff to&nbsp;'
                        '&#8220;typogrify&#8221;.</p>\n<p>Now with added '
                        'support for <abbr title="three letter acronym">'
                        '<span class="caps">TLA</span></abbr>.</p>\n')

            self.assertEqual(page.content, expected)
        except ImportError:
            return unittest.skip('need the typogrify distribution')
コード例 #10
0
    def test_typogrify_summary(self):
        # if nothing is specified in the settings, the summary should be
        # unmodified
        page = self.read_file(path='article_with_metadata.rst')
        expected = ('<p class="first last">Multi-line metadata should be'
                    ' supported\nas well as <strong>inline'
                    ' markup</strong> and stuff to &quot;typogrify'
                    '&quot;...</p>\n')

        self.assertEqual(page.metadata['summary'], expected)

        try:
            # otherwise, typogrify should be applied
            page = self.read_file(path='article_with_metadata.rst',
                                  TYPOGRIFY=True)
            expected = ('<p class="first last">Multi-line metadata should be'
                        ' supported\nas well as <strong>inline'
                        ' markup</strong> and stuff to&nbsp;&#8220;typogrify'
                        '&#8221;&#8230;</p>\n')

            self.assertEqual(page.metadata['summary'], expected)
        except ImportError:
            return unittest.skip('need the typogrify distribution')