Skip to content

Commit e879cfa

Browse files
authored
Tests fixes (#328)
* tests: fix invocation with sys.executable The formatting to substitute sys.executable was not effective because the formatted string was discarded. But even when when the substitution is made, pandoc ignores the shebang line in the file when the file is not executable and invokes it using 'python'. This second issue was hiding the first. We need to fix both to actually execute code using the desired sys.executable. Finally, the first .format() was interfering with the second .format(). * tests: fix indentation * tests: show diff if comparison fails
1 parent 5348c62 commit e879cfa

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ def test_conversion_with_data_files(self):
238238
if os.path.exists(test_docx_file):
239239
os.remove(test_docx_file)
240240
result = pypandoc.convert_file(
241-
os.path.join(test_data_dir, 'index.html'),
242-
to='docx',
243-
format='html',
244-
outputfile=test_docx_file,
245-
sandbox=True,
246-
)
241+
os.path.join(test_data_dir, 'index.html'),
242+
to='docx',
243+
format='html',
244+
outputfile=test_docx_file,
245+
sandbox=True,
246+
)
247247
print(result)
248248

249249
def test_convert_with_custom_writer(self):
@@ -347,9 +347,10 @@ def caps(key, value, format, meta):
347347
toJSONFilter(caps)
348348
'''
349349
python_source = textwrap.dedent(python_source)
350-
python_source.format(sys.executable)
350+
python_source = python_source.format(sys.executable)
351351

352352
with closed_tempfile(".py", python_source) as tempfile:
353+
os.chmod(tempfile, 0o755)
353354
output = pypandoc.convert_text(
354355
markdown_source, to='html', format='md', outputfile=None, filters=tempfile
355356
).strip()
@@ -389,28 +390,32 @@ def test_conversion_with_mixed_filters(self):
389390
390391
def func(key, value, format, meta):
391392
if key == "Para":
392-
return Para(value + [Str("{0}-")])
393+
return Para(value + [Str("{{0}}-")])
393394
394395
if __name__ == "__main__":
395396
toJSONFilter(func)
396397
397398
"""
398399
python = textwrap.dedent(python)
399-
python.format(sys.executable)
400+
python = python.format(sys.executable)
400401

401402
with closed_tempfile(".lua", lua.format(1)) as temp1, closed_tempfile(".py", python.format(2)) as temp2:
403+
os.chmod(temp2, 0o755)
404+
402405
with closed_tempfile(".lua", lua.format(3)) as temp3, closed_tempfile(".py", python.format(4)) as temp4:
406+
os.chmod(temp4, 0o755)
407+
403408
output = pypandoc.convert_text(
404409
markdown_source, to="html", format="md", outputfile=None, filters=[temp1, temp2, temp3, temp4]
405410
).strip()
406411
expected = "<p>-0-1-2-3-4-</p>"
407-
self.assertTrue(output == expected)
412+
self.assertEquals(output, expected)
408413

409414
output = pypandoc.convert_text(
410415
markdown_source, to="html", format="md", outputfile=None, filters=[temp3, temp1, temp4, temp2]
411416
).strip()
412417
expected = "<p>-0-3-1-4-2-</p>"
413-
self.assertTrue(output == expected)
418+
self.assertEquals(output, expected)
414419

415420
def test_classify_pandoc_logging(self):
416421

0 commit comments

Comments
 (0)