From 8d01ffabd4e5143e8b67ecadf22bf166efb3af3c Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 4 Jun 2017 23:49:50 +0000 Subject: tests: Add TestMdlStyleGetArgs. * tests/test_mdl_style.py (TestMdlStyleGetArgs): Add test class. --- tests/test_mdl_style.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/tests/test_mdl_style.py b/tests/test_mdl_style.py index cb0b6cb..23372fd 100644 --- a/tests/test_mdl_style.py +++ b/tests/test_mdl_style.py @@ -20,13 +20,21 @@ import os import os.path +import sys + + +from io import StringIO from random import randint +from unittest import mock + + from mistune import Renderer, Markdown from nose.tools import * from pkg_resources import resource_string, resource_filename -from mdl_style import * +from markdown_link_style._version import __version__ +from mdl_style import * from mdl_style import _get_args, _mdl_stylize def _get_data(f): @@ -225,3 +233,67 @@ class TestMdlStyleMdlStylize(object): if os.path.isfile(self.out_file): os.remove(self.out_file) + +class TestMdlStyleGetArgs(object): + """Testing mdl_style._get_args. + + """ + + def setup(self): + self.out = None + + + @raises(SystemExit) + def test_get_args_version(self): + real_exit = sys.exit + def mock_exit(args): + assert_equal(sys.stdout.getvalue(), + __version__ + '\n') + real_exit(args) + + with mock.patch('sys.stdout', new_callable=StringIO) as out, \ + mock.patch('sys.exit', new=mock_exit): + raw_args = ['--version'] + _get_args(raw_args) + + + def test_get_args_inline_infile(self): + lstyle = 'inline' + md_file = 'autolink_00.md' + raw_args = [lstyle, _get_data_path(md_file)] + args = _get_args(raw_args) + assert_equal(args.link_style, lstyle) + assert_equal(args.in_file.read(), _get_data(md_file)) + + + def test_get_args_inline_infile_outfile(self): + lstyle = 'inline' + md_file = 'autolink_00.md' + raw_args = [lstyle, _get_data_path(md_file), 'outfile.md'] + args = _get_args(raw_args) + assert_equal(args.link_style, lstyle) + assert_equal(args.in_file.read(), _get_data(md_file)) + assert_equal(type(args.out_file), str) + + + def test_get_args_footnote_infile(self): + lstyle = 'footnote' + md_file = 'autolink_00.md' + raw_args = [lstyle, _get_data_path(md_file)] + args = _get_args(raw_args) + assert_equal(args.link_style, lstyle) + assert_equal(args.in_file.read(), _get_data(md_file)) + + + def test_get_args_footnote_infile_outfile(self): + lstyle = 'footnote' + md_file = 'autolink_00.md' + raw_args = [lstyle, _get_data_path(md_file), 'outfile.md'] + args = _get_args(raw_args) + assert_equal(args.link_style, lstyle) + assert_equal(args.in_file.read(), _get_data(md_file)) + assert_equal(type(args.out_file), str) + + + def teardown(self): + pass -- cgit v1.2.3