mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #3044 from copperchin/fix-3042
This commit is contained in:
commit
a20bbb55d6
2 changed files with 48 additions and 26 deletions
|
|
@ -218,6 +218,24 @@ class LogCountHandler(BufferingHandler):
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def diff_subproc(first, second):
|
||||||
|
"""
|
||||||
|
Return a subprocess that runs a diff on the two paths.
|
||||||
|
|
||||||
|
Check results with::
|
||||||
|
|
||||||
|
>>> out_stream, err_stream = proc.communicate()
|
||||||
|
>>> didCheckFail = proc.returnCode != 0
|
||||||
|
"""
|
||||||
|
return subprocess.Popen(
|
||||||
|
['git', '--no-pager', 'diff', '--no-ext-diff', '--exit-code',
|
||||||
|
'-w', first, second],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LoggedTestCase(unittest.TestCase):
|
class LoggedTestCase(unittest.TestCase):
|
||||||
"""A test case that captures log messages."""
|
"""A test case that captures log messages."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import unittest
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
|
|
@ -10,8 +11,13 @@ from tempfile import mkdtemp
|
||||||
from pelican import Pelican
|
from pelican import Pelican
|
||||||
from pelican.generators import StaticGenerator
|
from pelican.generators import StaticGenerator
|
||||||
from pelican.settings import read_settings
|
from pelican.settings import read_settings
|
||||||
from pelican.tests.support import (LoggedTestCase, locale_available,
|
from pelican.tests.support import (
|
||||||
mute, unittest)
|
LoggedTestCase,
|
||||||
|
diff_subproc,
|
||||||
|
locale_available,
|
||||||
|
mute,
|
||||||
|
skipIfNoExecutable,
|
||||||
|
)
|
||||||
|
|
||||||
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
SAMPLES_PATH = os.path.abspath(os.path.join(
|
SAMPLES_PATH = os.path.abspath(os.path.join(
|
||||||
|
|
@ -54,28 +60,20 @@ class TestPelican(LoggedTestCase):
|
||||||
locale.setlocale(locale.LC_ALL, self.old_locale)
|
locale.setlocale(locale.LC_ALL, self.old_locale)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def assertDirsEqual(self, left_path, right_path):
|
def assertDirsEqual(self, left_path, right_path, msg=None):
|
||||||
out, err = subprocess.Popen(
|
"""
|
||||||
['git', '--no-pager', 'diff', '--no-ext-diff', '--exit-code',
|
Check if the files are the same (ignoring whitespace) below both paths.
|
||||||
'-w', left_path, right_path],
|
"""
|
||||||
stdout=subprocess.PIPE,
|
proc = diff_subproc(left_path, right_path)
|
||||||
stderr=subprocess.PIPE
|
|
||||||
).communicate()
|
|
||||||
|
|
||||||
def ignorable_git_crlf_errors(line):
|
out, err = proc.communicate()
|
||||||
# Work around for running tests on Windows
|
if proc.returncode != 0:
|
||||||
for msg in [
|
msg = self._formatMessage(
|
||||||
"LF will be replaced by CRLF",
|
msg,
|
||||||
"CRLF will be replaced by LF",
|
"%s and %s differ:\nstdout:\n%s\nstderr\n%s" %
|
||||||
"The file will have its original line endings"]:
|
(left_path, right_path, out, err)
|
||||||
if msg in line:
|
)
|
||||||
return True
|
raise self.failureException(msg)
|
||||||
return False
|
|
||||||
if err:
|
|
||||||
err = '\n'.join([line for line in err.decode('utf8').splitlines()
|
|
||||||
if not ignorable_git_crlf_errors(line)])
|
|
||||||
assert not out, out
|
|
||||||
assert not err, err
|
|
||||||
|
|
||||||
def test_order_of_generators(self):
|
def test_order_of_generators(self):
|
||||||
# StaticGenerator must run last, so it can identify files that
|
# StaticGenerator must run last, so it can identify files that
|
||||||
|
|
@ -92,6 +90,7 @@ class TestPelican(LoggedTestCase):
|
||||||
generator_classes, Sequence,
|
generator_classes, Sequence,
|
||||||
"_get_generator_classes() must return a Sequence to preserve order")
|
"_get_generator_classes() must return a Sequence to preserve order")
|
||||||
|
|
||||||
|
@skipIfNoExecutable(['git', '--version'])
|
||||||
def test_basic_generation_works(self):
|
def test_basic_generation_works(self):
|
||||||
# when running pelican without settings, it should pick up the default
|
# when running pelican without settings, it should pick up the default
|
||||||
# ones and generate correct output without raising any exception
|
# ones and generate correct output without raising any exception
|
||||||
|
|
@ -104,12 +103,14 @@ class TestPelican(LoggedTestCase):
|
||||||
pelican = Pelican(settings=settings)
|
pelican = Pelican(settings=settings)
|
||||||
mute(True)(pelican.run)()
|
mute(True)(pelican.run)()
|
||||||
self.assertDirsEqual(
|
self.assertDirsEqual(
|
||||||
self.temp_path, os.path.join(OUTPUT_PATH, 'basic'))
|
self.temp_path, os.path.join(OUTPUT_PATH, 'basic')
|
||||||
|
)
|
||||||
self.assertLogCountEqual(
|
self.assertLogCountEqual(
|
||||||
count=1,
|
count=1,
|
||||||
msg="Unable to find.*skipping url replacement",
|
msg="Unable to find.*skipping url replacement",
|
||||||
level=logging.WARNING)
|
level=logging.WARNING)
|
||||||
|
|
||||||
|
@skipIfNoExecutable(['git', '--version'])
|
||||||
def test_custom_generation_works(self):
|
def test_custom_generation_works(self):
|
||||||
# the same thing with a specified set of settings should work
|
# the same thing with a specified set of settings should work
|
||||||
settings = read_settings(path=SAMPLE_CONFIG, override={
|
settings = read_settings(path=SAMPLE_CONFIG, override={
|
||||||
|
|
@ -121,8 +122,10 @@ class TestPelican(LoggedTestCase):
|
||||||
pelican = Pelican(settings=settings)
|
pelican = Pelican(settings=settings)
|
||||||
mute(True)(pelican.run)()
|
mute(True)(pelican.run)()
|
||||||
self.assertDirsEqual(
|
self.assertDirsEqual(
|
||||||
self.temp_path, os.path.join(OUTPUT_PATH, 'custom'))
|
self.temp_path, os.path.join(OUTPUT_PATH, 'custom')
|
||||||
|
)
|
||||||
|
|
||||||
|
@skipIfNoExecutable(['git', '--version'])
|
||||||
@unittest.skipUnless(locale_available('fr_FR.UTF-8') or
|
@unittest.skipUnless(locale_available('fr_FR.UTF-8') or
|
||||||
locale_available('French'), 'French locale needed')
|
locale_available('French'), 'French locale needed')
|
||||||
def test_custom_locale_generation_works(self):
|
def test_custom_locale_generation_works(self):
|
||||||
|
|
@ -141,7 +144,8 @@ class TestPelican(LoggedTestCase):
|
||||||
pelican = Pelican(settings=settings)
|
pelican = Pelican(settings=settings)
|
||||||
mute(True)(pelican.run)()
|
mute(True)(pelican.run)()
|
||||||
self.assertDirsEqual(
|
self.assertDirsEqual(
|
||||||
self.temp_path, os.path.join(OUTPUT_PATH, 'custom_locale'))
|
self.temp_path, os.path.join(OUTPUT_PATH, 'custom_locale')
|
||||||
|
)
|
||||||
|
|
||||||
def test_theme_static_paths_copy(self):
|
def test_theme_static_paths_copy(self):
|
||||||
# the same thing with a specified set of settings should work
|
# the same thing with a specified set of settings should work
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue