Skip to content

Commit

Permalink
Test content generation with git diff return value
Browse files Browse the repository at this point in the history
Assert equal dirs by diff return value, rather than diff output.
This prevents tests from failing when file contents are the same but the
file modes are different.

Fix #3042
  • Loading branch information
copperchin committed Sep 23, 2022
1 parent 2a7e691 commit d4a8aad
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions pelican/tests/test_pelican.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ def recursiveDiff(dcmp):
return diff


def assertDirsEqual(left_path, right_path):
"""
Raise AssertionError if files in paths differ (ignoring whitespace).
"""
proc = subprocess.Popen(
['git', '--no-pager', 'diff', '--no-ext-diff', '--exit-code',
'-w', left_path, right_path],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)

out = proc.communicate()
if proc.returncode:
assert not out, out


class TestPelican(LoggedTestCase):
# general functional testing for pelican. Basically, this test case tries
# to run pelican in different situations and see how it behaves
Expand All @@ -54,29 +70,6 @@ def tearDown(self):
locale.setlocale(locale.LC_ALL, self.old_locale)
super().tearDown()

def assertDirsEqual(self, left_path, right_path):
out, err = subprocess.Popen(
['git', '--no-pager', 'diff', '--no-ext-diff', '--exit-code',
'-w', left_path, right_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
).communicate()

def ignorable_git_crlf_errors(line):
# Work around for running tests on Windows
for msg in [
"LF will be replaced by CRLF",
"CRLF will be replaced by LF",
"The file will have its original line endings"]:
if msg in line:
return True
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):
# StaticGenerator must run last, so it can identify files that
# were skipped by the other generators, and so static files can
Expand All @@ -103,8 +96,7 @@ def test_basic_generation_works(self):
})
pelican = Pelican(settings=settings)
mute(True)(pelican.run)()
self.assertDirsEqual(
self.temp_path, os.path.join(OUTPUT_PATH, 'basic'))
assertDirsEqual(self.temp_path, os.path.join(OUTPUT_PATH, 'basic'))
self.assertLogCountEqual(
count=1,
msg="Unable to find.*skipping url replacement",
Expand All @@ -120,8 +112,7 @@ def test_custom_generation_works(self):
})
pelican = Pelican(settings=settings)
mute(True)(pelican.run)()
self.assertDirsEqual(
self.temp_path, os.path.join(OUTPUT_PATH, 'custom'))
assertDirsEqual(self.temp_path, os.path.join(OUTPUT_PATH, 'custom'))

@unittest.skipUnless(locale_available('fr_FR.UTF-8') or
locale_available('French'), 'French locale needed')
Expand All @@ -140,8 +131,8 @@ def test_custom_locale_generation_works(self):
})
pelican = Pelican(settings=settings)
mute(True)(pelican.run)()
self.assertDirsEqual(
self.temp_path, os.path.join(OUTPUT_PATH, 'custom_locale'))
assertDirsEqual(self.temp_path,
os.path.join(OUTPUT_PATH, 'custom_locale'))

def test_theme_static_paths_copy(self):
# the same thing with a specified set of settings should work
Expand Down

0 comments on commit d4a8aad

Please sign in to comment.