Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion markdown_it/cli/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def main(args=None):
convert(namespace.filenames)
else:
interactive()
return True
RET_OK = 0
return RET_OK


def convert(filenames):
Expand Down
10 changes: 9 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
import tempfile
from unittest.mock import patch

import pytest

from markdown_it.cli import parse


def test_parse():
with tempfile.TemporaryDirectory() as tempdir:
path = pathlib.Path(tempdir).joinpath("test.md")
path.write_text("a b c")
assert parse.main([str(path)])
assert parse.main([str(path)]) == 0


def test_parse_fail():
with pytest.raises(SystemExit) as exc_info:
parse.main(["/tmp/nonexistant_path/for_cli_test.md"])
assert exc_info.value.code == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to fix the test failure is:

Suggested change
assert exc_info.value.code == 1
assert isinstance(exc_info.value.code, str)

Another way, that I personally would prefer but don't know if @chrisjsewell would, is go to markdown_it.cli.parse.convert_file and replace

sys.exit('Cannot open file "{}".'.format(filename))

with

sys.stderr.write('Cannot open file "{}".\n'.format(filename)) sys.exit(1)


def test_print_heading():
Expand Down