Skip to content

Commit

Permalink
Merge 6856cbb into a801697
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex L. Urban committed Apr 6, 2019
2 parents a801697 + 6856cbb commit ae4532a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 8 additions & 3 deletions gwdetchar/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,15 @@ def get_command_line(language='bash'):
Parameters
----------
language : `str`, optional
language the code is written in, default: `'bash'`
type of environment the code is run in, default: `'bash'`
"""
commandline = ' '.join(sys.argv)
return render_code(commandline, language)
if sys.argv[0].endswith('__main__.py'):
package = sys.argv[0].rsplit(os.path.sep, 2)[1]
commandline = '$ python -m {0} {1}'.format(
package, ' '.join(sys.argv[1:]))
else:
commandline = '$ ' + ' '.join(sys.argv)
return render_code(commandline.replace(' --html-only', ''), language)


def html_link(href, txt, target="_blank", **params):
Expand Down
19 changes: 19 additions & 0 deletions gwdetchar/io/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,25 @@ def test_write_param():
'<p>\n<strong>test: </strong>\ntest\n</p>')


def test_get_command_line():
testargs = ['gwdetchar-conlog', '-i', 'X1']
with mock.patch.object(sys, 'argv', testargs):
cmdline = html.get_command_line()
assert parse_html(cmdline) == parse_html(
'<div class="highlight" style="background: #f8f8f8">'
'<pre style="line-height: 125%"><span></span>'
'$ gwdetchar-conlog -i X1\n</pre></div>\n')

def test_get_command_line_module():
testargs = ['gwdetchar/omega/__main__.py', '--html-only']
with mock.patch.object(sys, 'argv', testargs):
cmdline = html.get_command_line()
assert parse_html(cmdline) == parse_html(
'<div class="highlight" style="background: #f8f8f8">'
'<pre style="line-height: 125%"><span></span>'
'$ python -m omega\n</pre></div>\n')


@pytest.mark.parametrize('args, kwargs, result', [
(('test.html', 'Test link'), {},
'<a href="test.html" target="_blank">Test link</a>'),
Expand Down

0 comments on commit ae4532a

Please sign in to comment.