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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: moban
organisation: moremoban
releases:
- changes:
- action: Added
details:
- "`#260`: jinja-cli parity: support command line pipe stream."
date: 25.09.2019
version: 0.6.3
- changes:
- action: Added
details:
Expand Down
6 changes: 3 additions & 3 deletions .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ organisation: moremoban
author: C. W.
contact: wangc_2011@hotmail.com
license: MIT
version: 0.6.2
current_version: 0.6.2
release: 0.6.2
version: 0.6.3
current_version: 0.6.3
release: 0.6.3
branch: master
master: index
command_line_interface: "moban"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Change log
================================================================================

0.6.3 - 25.09.2019
--------------------------------------------------------------------------------

Added
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#. `#260 <https://github.com/moremoban/moban/issues/260>`_: jinja-cli parity:
support command line pipe stream.

0.6.2 - 15.09.2019
--------------------------------------------------------------------------------

Expand Down
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ Quick start
$ cat moban.output
world

Or

.. code-block:: bash

$ export HELLO="world"
$ echo "{{HELLO}}" | moban

Or simply

.. code-block:: bash
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
copyright = '2017-2019 Onni Software Ltd.'
author = 'C. W.'
# The short X.Y version
version = '0.6.2'
version = '0.6.3'
# The full version, including alpha/beta/rc tags
release = '0.6.2'
release = '0.6.3'

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion moban/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.6.2"
__version__ = "0.6.3"
__author__ = "C. W."
18 changes: 11 additions & 7 deletions moban/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,18 @@ def handle_command_line(options):
options[constants.LABEL_CONFIG_DIR],
)
if options[constants.LABEL_TEMPLATE] is None:
if options[constants.POSITIONAL_LABEL_TEMPLATE] is None:
content = options[constants.POSITIONAL_LABEL_TEMPLATE]
if content is None:
if not sys.stdin.isatty() and sys.platform != "win32":
content = sys.stdin.read().strip()
if content is None:
raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE)
else:
engine.render_string_to_file(
options[constants.POSITIONAL_LABEL_TEMPLATE],
options[constants.LABEL_CONFIG],
options[constants.LABEL_OUTPUT],
)

engine.render_string_to_file(
content,
options[constants.LABEL_CONFIG],
options[constants.LABEL_OUTPUT],
)
else:
engine.render_to_file(
options[constants.LABEL_TEMPLATE],
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

NAME = "moban"
AUTHOR = "C. W."
VERSION = "0.6.2"
VERSION = "0.6.3"
EMAIL = "wangc_2011@hotmail.com"
LICENSE = "MIT"
ENTRY_POINTS = {
Expand All @@ -50,7 +50,7 @@
"Yet another jinja2 cli command for static text generation"
)
URL = "https://github.com/moremoban/moban"
DOWNLOAD_URL = "%s/archive/0.6.2.tar.gz" % URL
DOWNLOAD_URL = "%s/archive/0.6.3.tar.gz" % URL
FILES = ["README.rst", "CONTRIBUTORS.rst", "CHANGELOG.rst"]
KEYWORDS = [
"python",
Expand Down Expand Up @@ -97,8 +97,8 @@
}
# You do not need to read beyond this line
PUBLISH_COMMAND = "{0} setup.py sdist bdist_wheel upload -r pypi".format(sys.executable)
GS_COMMAND = ("gs moban v0.6.2 " +
"Find 0.6.2 in changelog for more details")
GS_COMMAND = ("gs moban v0.6.3 " +
"Find 0.6.3 in changelog for more details")
NO_GS_MESSAGE = ("Automatic github release is disabled. " +
"Please install gease to enable it.")
UPLOAD_FAILED_MSG = (
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pip freeze

nosetests --with-cov --with-doctest --doctest-extension=.rst --cover-package moban --cover-package tests
nosetests --verbosity=3 --with-cov --with-doctest --doctest-extension=.rst --cover-package moban --cover-package tests
38 changes: 31 additions & 7 deletions tests/integration_tests/test_command_line_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
import sys
from shutil import copyfile

from mock import patch
from mock import MagicMock, patch
from nose import SkipTest
from nose.tools import eq_, raises, assert_raises
from moban.definitions import TemplateTarget

try:
from StringIO import StringIO
except ImportError:
from io import StringIO


class TestCustomOptions:
def setUp(self):
Expand Down Expand Up @@ -54,10 +59,12 @@ def test_minimal_options(self, fake_template_doer):
@raises(SystemExit)
def test_missing_template(self):
test_args = ["moban", "-c", self.config_file]
with patch.object(sys, "argv", test_args):
from moban.main import main
fake_stdin = MagicMock(isatty=MagicMock(return_value=True))
with patch.object(sys, "stdin", fake_stdin):
with patch.object(sys, "argv", test_args):
from moban.main import main

main()
main()

def tearDown(self):
self.patcher1.stop()
Expand Down Expand Up @@ -100,10 +107,12 @@ def test_string_template(self, fake_template_doer):
@raises(SystemExit)
def test_no_argments(self):
test_args = ["moban"]
with patch.object(sys, "argv", test_args):
from moban.main import main
fake_stdin = MagicMock(isatty=MagicMock(return_value=True))
with patch.object(sys, "stdin", fake_stdin):
with patch.object(sys, "argv", test_args):
from moban.main import main

main()
main()

def tearDown(self):
self.patcher1.stop()
Expand Down Expand Up @@ -524,3 +533,18 @@ def test_add_extension():
"{}.{}".format(sys.version_info[0], sys.version_info[1]),
)
os.unlink("moban.output")


def test_stdin_input():
if sys.platform == "win32":
raise SkipTest("windows test fails with this pipe test 2")
test_args = ["moban", "-d", "hello=world"]
with patch.object(sys, "stdin", StringIO("{{hello}}")):
with patch.object(sys, "argv", test_args):
from moban.main import main

main()
with open("moban.output") as f:
content = f.read()
eq_(content, "world")
os.unlink("moban.output")
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ arrow;python_version!="3.4"
jinja2_time
pypifs
gitfs2
jinja2-python-version
jinja2-python-version>=1.1.2
26 changes: 16 additions & 10 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from shutil import copyfile

import moban.exceptions as exceptions
from mock import patch
from mock import MagicMock, patch
from nose.tools import eq_, raises, assert_raises


Expand Down Expand Up @@ -86,10 +86,12 @@ def test_directory_not_found(
):
fake_file.return_value = True
fake_moban_file.side_effect = exceptions.DirectoryNotFound
from moban.main import main
fake_stdin = MagicMock(isatty=MagicMock(return_value=True))
with patch.object(sys, "stdin", fake_stdin):
with patch.object(sys, "argv", ["moban"]):
from moban.main import main

with patch.object(sys, "argv", ["moban"]):
main()
main()

@raises(SystemExit)
@patch("os.path.exists")
Expand All @@ -100,10 +102,12 @@ def test_no_third_party_engine(
):
fake_file.return_value = True
fake_moban_file.side_effect = exceptions.NoThirdPartyEngine
from moban.main import main
fake_stdin = MagicMock(isatty=MagicMock(return_value=True))
with patch.object(sys, "stdin", fake_stdin):
from moban.main import main

with patch.object(sys, "argv", ["moban"]):
main()
with patch.object(sys, "argv", ["moban"]):
main()

@raises(SystemExit)
@patch("os.path.exists")
Expand All @@ -114,10 +118,12 @@ def test_double_underscore_main(
):
fake_file.return_value = True
fake_moban_file.side_effect = exceptions.DirectoryNotFound
from moban.__main__ import main
fake_stdin = MagicMock(isatty=MagicMock(return_value=True))
with patch.object(sys, "stdin", fake_stdin):
from moban.__main__ import main

with patch.object(sys, "argv", ["moban"]):
main()
with patch.object(sys, "argv", ["moban"]):
main()


class TestExitCodes:
Expand Down