def test_minimal_options(self, fake_template_doer): test_args = ["moban", "-c", self.config_file, "-t", "a.jj2"] with patch.object(sys, "argv", test_args): from moban.main import main main() fake_template_doer.assert_called_with("a.jj2", "config.yaml", "-")
def test_add_extension(): if sys.version_info[0] == 2: raise SkipTest("jinja2-python-version does not support python 2") test_commands = [ [ "moban", "-t", "{{ python_version }}", "-e", "jinja2=jinja2_python_version.PythonVersionExtension", "-o", "moban.output", ], [ "moban", "-t", "{{ python_version }}", "-e", "jj2=jinja2_python_version.PythonVersionExtension", "-o", "moban.output", ], ] for test_args in test_commands: with patch.object(sys, "argv", test_args): from moban.main import main main() with open("moban.output") as f: content = f.read() eq_( content, "{}.{}".format(sys.version_info[0], sys.version_info[1]), ) os.unlink("moban.output")
def test_default_options(self, fake_template_doer): test_args = ["moban", "-t", "a.jj2"] with patch.object(sys, "argv", test_args): from moban.main import main main() fake_template_doer.assert_called_with("a.jj2", "data.yml", "-")
def test_template_option_not_in_moban_file(self, fake_template_doer): test_args = ["moban", "-t", "foo.jj2"] with patch.object(sys, "argv", test_args): from moban.main import main main() fake_template_doer.assert_called_with("foo.jj2", "data.yml", "-")
def _raw_moban(self, args, folder, expected, output): base_dir = fs.path.join("tests", "regression_tests") os.chdir(fs.path.join(base_dir, folder)) with patch.object(sys, "argv", args): main() status = filecmp.cmp(output, expected) os.unlink(output) assert status
def test_stdout(): test_args = ["moban", "-d", "hello=world", "-t", "{{hello}}"] with patch.object(sys, "argv", test_args): with patch("sys.stdout", new_callable=StringIO) as fake_stdout: from moban.main import main main() eq_(fake_stdout.getvalue(), "world\n")
def run_moban_with_fs(args, folder, criterias): with patch.object(sys, "argv", args): main() for output, expected in criterias: verify_content_with_fs(output, expected) result = parse_fs_url(output) os.unlink(result.resource) # delete the zip file
def test_no_argments(self): test_args = ["moban"] 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()
def test_template_option_override_moban_file(self, fake_template_doer): test_args = ["moban", "-t", "setup.py.jj2"] with patch.object(sys, "argv", test_args): from moban.main import main main() fake_template_doer.assert_called_with("setup.py.jj2", "data.yml", "moban.output")
def test_no_targets(self, fake_template_doer): with open(self.config_file, "w") as f: f.write("configuration: test") test_args = ["moban"] with patch.object(sys, "argv", test_args): from moban.main import main main()
def test_mako_option(self, fake_template_doer): test_args = ["moban", "-t", "a.mako"] with patch.object(sys, "argv", test_args): from moban.main import main main() fake_template_doer.assert_called_with("a.mako", "data.yml", "moban.output")
def test_single_command_with_a_few_options(self, fake_template_doer): test_args = ["moban", "-t", "abc.jj2", "-o", "xyz.output"] with patch.object(sys, "argv", test_args): from moban.main import main main() call_args = list(fake_template_doer.call_args[0][0]) eq_(call_args, [("abc.jj2", "data.yaml", "xyz.output")])
def test_missing_template(self): test_args = ["moban", "-c", self.config_file] 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()
def test_stdout(): test_args = ["moban", "-t", "{{'tests' is directory}}"] with patch.object(sys, "argv", test_args): with patch("sys.stdout", new_callable=StringIO) as fake_stdout: from moban.main import main main() assert fake_stdout.getvalue() == "True\n"
def test_string_template(self, fake_template_doer): string_template = "{{HELLO}}" test_args = ["moban", string_template] with patch.object(sys, "argv", test_args): from moban.main import main main() fake_template_doer.assert_called_with(string_template, "data.yml", "moban.output")
def _raw_moban(self, args, folder, expected, output): os.chdir(os.path.join("docs", folder)) with patch.object(sys, "argv", args): try: main() except SystemExit as e: eq_("1", str(e)) _verify_content(output, expected) os.unlink(output)
def test_single_command(self, fake_template_doer): test_args = ["moban"] with patch.object(sys, "argv", test_args): main() call_args = list(fake_template_doer.call_args[0][0]) eq_( call_args, [ ("README.rst.jj2", "custom-data.yaml", "README.rst"), ("setup.py.jj2", "data.yml", "setup.py"), ], )
def test_single_command_with_a_few_options(self, fake_template_doer): test_args = ["moban", "-t", "abc.jj2", "-o", "xyz.output"] with patch.object(sys, "argv", test_args): main() call_args = list(fake_template_doer.call_args[0][0]) eq_( call_args, [ ("README.rst.jj2", "data.yaml", "README.rst"), ("setup.py.jj2", "data.yaml", "setup.py"), ("abc.jj2", "data.yaml", "xyz.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", "-o", "moban.output"] 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")
def test_debug_five_verbose_option(fake_config, *_): fake_config.side_effect = [IOError("stop test")] test_args = ["moban", "-vvvvv"] with patch.object(sys, "argv", test_args): from moban.main import main try: main() except IOError: fake_config.assert_called_with( format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=10, )
def test_single_command(self, fake_template_doer): test_args = ["moban", "-m", self.config_file] with patch.object(sys, "argv", test_args): from moban.main import main main() call_args = list(fake_template_doer.call_args[0][0]) eq_( call_args, [ ("README.rst.jj2", "data.yaml", "README.rst"), ("setup.py.jj2", "data.yaml", "setup.py"), ], )
def test_render_file_stdout(): config_file = "config.yaml" with open(config_file, "w") as f: f.write("hello: world") template_file = "t.jj2" with open(template_file, "w") as f: f.write("{{hello}}") test_args = ["moban", "-t", "t.jj2", "-c", "config.yaml"] with patch.object(sys, "argv", test_args): with patch("sys.stdout", new_callable=StringIO) as fake_stdout: from moban.main import main main() eq_(fake_stdout.getvalue(), "world\n")
def test_custom_options(self, fake_template_doer): test_args = [ "moban", "-c", self.config_file, "-cd", "/home/developer/configuration", "-td", "/home/developer/templates", "-t", "a.template", ] with patch.object(sys, "argv", test_args): main() fake_template_doer.assert_called_with("a.template", "config.yaml", "moban.output")
def test_single_command(self): test_args = ["moban"] with patch.object(sys, "argv", test_args): from moban.main import main with patch("moban.plugins.BaseEngine.render_to_files") as fake: main() call_args = list(fake.call_args[0][0]) eq_( call_args, [ ("README.rst.jj2", "custom-data.yaml", "README.rst"), ("setup.py.jj2", "data.yml", "setup.py"), ], )
def test_custom_options(self, fake_template_doer): test_args = [ "moban", "-c", self.config_file, "-cd", "/home/developer/configuration", "-td", "/home/developer/templates", "-t", "a.jj2", ] with patch.object(sys, "argv", test_args): main() fake_template_doer.assert_called_with("a.jj2", "config.yaml", "moban.output")
def test_single_command(self, _): test_args = ["moban"] with patch.object(sys, "argv", test_args): from moban.main import main with patch("moban.core.moban_factory.MobanEngine.render_to_files" ) as fake: main() call_args = list(fake.call_args[0][0]) eq_( call_args, [ TemplateTarget("README.rst.jj2", "custom-data.yaml", "README.rst"), TemplateTarget("setup.py.jj2", "data.yml", "setup.py"), ], )
def test_git_repo_example(_): test_args = [ "moban", "-t", "git://github.com/moremoban/pypi-mobans.git!/templates/_version.py.jj2", "-c", "git://github.com/moremoban/pypi-mobans.git!/config/data.yml", "-o", "test_git_repo_example.py", ] with patch.object(sys, "argv", test_args): from moban.main import main main() with open("test_git_repo_example.py") as f: content = f.read() eq_(content, '__version__ = "0.1.1rc3"\n__author__ = "C.W."\n') os.unlink("test_git_repo_example.py")
def test_pypi_pkg_example(_): test_args = [ "moban", "-t", "pypi://pypi-mobans-pkg/resources/templates/_version.py.jj2", "-c", "pypi://pypi-mobans-pkg/resources/config/data.yml", "-o", "test_pypi_pkg_example.py", ] with patch.object(sys, "argv", test_args): from moban.main import main main() with open("test_pypi_pkg_example.py") as f: content = f.read() eq_(content, '__version__ = "0.1.1rc3"\n__author__ = "C.W."\n') os.unlink("test_pypi_pkg_example.py")
def test_custom_options(self, fake_template_doer, fake_abspath): test_args = [ "moban", "-c", self.config_file, "-cd", ".", "-td", ".", "-t", "a.jj2", ] with patch.object(sys, "argv", test_args): from moban.main import main main() fake_template_doer.assert_called_with( "a.jj2", "config.yaml", "moban.output" )
def test_single_command_with_options(self, fake_template_doer): test_args = [ "moban", "-t", "README.rst.jj2", "-c", "new.yml", "-o", "xyz.output", ] with patch.object(sys, "argv", test_args): from moban.main import main main() call_args = list(fake_template_doer.call_args[0][0]) eq_( call_args, [TemplateTarget("README.rst.jj2", "new.yml", "xyz.output")], )
def test_custom_jinja2_filters_tests(): config_file = "config.yaml" with open(config_file, "w") as f: f.write("hello: world") template_file = "t.jj2" with open(template_file, "w") as f: f.write("{{hello}}") test_args = [ "moban", "-e", "jinja2=filter:moban.externals.file_system.url_join", "jinja2=test:moban.externals.file_system.exists", "jinja2=global:description=moban.constants.PROGRAM_DESCRIPTION", "-t", "{{'a'|url_join('b')}} {{'b' is exists}}{{ description }}", ] with patch.object(sys, "argv", test_args): with patch("sys.stdout", new_callable=StringIO) as fake_stdout: from moban.main import main expected_output = ("a/b False" + "Static text generator using " + "any template, any data and any location.\n") main() eq_(fake_stdout.getvalue(), expected_output)
def test_no_targets(self, fake_template_doer): with open(self.config_file, "w") as f: f.write("configuration: test") test_args = ["moban"] with patch.object(sys, "argv", test_args): main()
def test_mako_optoin(self, fake_template_doer): test_args = ["moban", "-t", "a.template", "--template_type", "mako"] with patch.object(sys, "argv", test_args): main() fake_template_doer.assert_called_with("a.template", "data.yml", "moban.output")
def test_minimal_options(self, fake_template_doer): test_args = ["moban", "-c", self.config_file, "-t", "a.template"] with patch.object(sys, "argv", test_args): main() fake_template_doer.assert_called_with("a.template", "config.yaml", "moban.output")
def _raw_moban(self, args, folder, expected, output): os.chdir(os.path.join("docs", folder)) with patch.object(sys, 'argv', args): main() _verify_content(output, expected) os.unlink(output)
def test_missing_template(self): test_args = ["moban", "-c", self.config_file] with patch.object(sys, "argv", test_args): main()
def test_default_options(self, fake_template_doer): test_args = ["moban", "-t", "a.template"] with patch.object(sys, "argv", test_args): main() fake_template_doer.assert_called_with("a.template", "data.yml", "moban.output")
def test_no_argments(self): test_args = ["moban"] with patch.object(sys, "argv", test_args): main()
def test_missing_configuration(): test_args = ["moban", "-t", "a.template"] with patch.object(sys, "argv", test_args): main()
def test_single_command(self, fake_template_doer): test_args = ["moban"] with patch.object(sys, "argv", test_args): main() call_args = list(fake_template_doer.call_args[0][0]) assert call_args == [("README.rst", "data.yaml", "README.rst"), ("setup.py", "data.yaml", "setup.py")]