From 08332c109b0faa05c2e06c39d020dcd56a9a6c10 Mon Sep 17 00:00:00 2001
From: chfw <wangc_2011@hotmail.com>
Date: Sun, 24 Feb 2019 21:48:35 +0000
Subject: [PATCH 1/2] :hammer: code refactoring

---
 moban/plugins/__init__.py                     |  4 +--
 moban/plugins/template.py                     |  8 ++---
 .../test_command_line_options.py              | 34 +++++++++----------
 tests/mobanfile/test_mobanfile.py             |  2 +-
 tests/test_engine.py                          |  6 ++--
 tests/test_jinja2_extensions.py               |  4 +--
 tests/test_template.py                        |  4 +--
 7 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/moban/plugins/__init__.py b/moban/plugins/__init__.py
index 0fcc020c..9458e5ed 100644
--- a/moban/plugins/__init__.py
+++ b/moban/plugins/__init__.py
@@ -1,5 +1,5 @@
 from lml.loader import scan_plugins_regex
-from moban.plugins.template import TemplateFactory
+from moban.plugins.template import MobanFactory
 from moban import constants
 
 
@@ -11,7 +11,7 @@
 ]
 
 
-ENGINES = TemplateFactory()
+ENGINES = MobanFactory()
 
 
 def make_sure_all_pkg_are_loaded():
diff --git a/moban/plugins/template.py b/moban/plugins/template.py
index 9595ea1d..a069d921 100644
--- a/moban/plugins/template.py
+++ b/moban/plugins/template.py
@@ -12,9 +12,9 @@
 log = logging.getLogger(__name__)
 
 
-class TemplateFactory(PluginManager):
+class MobanFactory(PluginManager):
     def __init__(self):
-        super(TemplateFactory, self).__init__(
+        super(MobanFactory, self).__init__(
             constants.TEMPLATE_ENGINE_EXTENSION
         )
         self.extensions = {}
@@ -25,7 +25,7 @@ def register_extensions(self, extensions):
     def get_engine(self, template_type, template_dirs, context_dirs):
         engine_cls = self.load_me_now(template_type)
         engine_extensions = self.extensions.get(template_type)
-        return TemplateEngine(
+        return MobanEngine(
             template_dirs, context_dirs, engine_cls, engine_extensions
         )
 
@@ -36,7 +36,7 @@ def raise_exception(self, key):
         raise exceptions.NoThirdPartyEngine(key)
 
 
-class TemplateEngine(object):
+class MobanEngine(object):
     def __init__(
         self, template_dirs, context_dirs, engine_cls, engine_extensions=None
     ):
diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py
index aea42b2e..6cbe3fe6 100644
--- a/tests/integration_tests/test_command_line_options.py
+++ b/tests/integration_tests/test_command_line_options.py
@@ -18,7 +18,7 @@ def setUp(self):
         )
         self.patcher1.start()
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_file")
+    @patch("moban.plugins.template.MobanEngine.render_to_file")
     def test_custom_options(self, fake_template_doer):
         test_args = [
             "moban",
@@ -39,7 +39,7 @@ def test_custom_options(self, fake_template_doer):
                 "a.jj2", "config.yaml", "moban.output"
             )
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_file")
+    @patch("moban.plugins.template.MobanEngine.render_to_file")
     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):
@@ -73,7 +73,7 @@ def setUp(self):
         )
         self.patcher1.start()
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_file")
+    @patch("moban.plugins.template.MobanEngine.render_to_file")
     def test_default_options(self, fake_template_doer):
         test_args = ["moban", "-t", "a.jj2"]
         with patch.object(sys, "argv", test_args):
@@ -84,7 +84,7 @@ def test_default_options(self, fake_template_doer):
                 "a.jj2", "data.yml", "moban.output"
             )
 
-    @patch("moban.plugins.template.TemplateEngine.render_string_to_file")
+    @patch("moban.plugins.template.MobanEngine.render_string_to_file")
     def test_string_template(self, fake_template_doer):
         string_template = "{{HELLO}}"
         test_args = ["moban", string_template]
@@ -133,7 +133,7 @@ def setUp(self):
         )
         self.patcher1.start()
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_files")
+    @patch("moban.plugins.template.MobanEngine.render_to_files")
     def test_single_command(self, fake_template_doer):
         test_args = ["moban"]
         with patch.object(sys, "argv", test_args):
@@ -152,7 +152,7 @@ def test_single_command(self, fake_template_doer):
             )
 
     @raises(Exception)
-    @patch("moban.plugins.template.TemplateEngine.render_to_files")
+    @patch("moban.plugins.template.MobanEngine.render_to_files")
     def test_single_command_with_missing_output(self, fake_template_doer):
         test_args = ["moban", "-t", "README.rst.jj2"]
         with patch.object(sys, "argv", test_args):
@@ -160,7 +160,7 @@ def test_single_command_with_missing_output(self, fake_template_doer):
 
             main()
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_files")
+    @patch("moban.plugins.template.MobanEngine.render_to_files")
     def test_single_command_with_a_few_options(self, fake_template_doer):
         test_args = ["moban", "-t", "README.rst.jj2", "-o", "xyz.output"]
         with patch.object(sys, "argv", test_args):
@@ -173,7 +173,7 @@ def test_single_command_with_a_few_options(self, fake_template_doer):
                 [TemplateTarget("README.rst.jj2", "data.yaml", "xyz.output")],
             )
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_files")
+    @patch("moban.plugins.template.MobanEngine.render_to_files")
     def test_single_command_with_options(self, fake_template_doer):
         test_args = [
             "moban",
@@ -223,7 +223,7 @@ def setUp(self):
         )
         self.patcher1.start()
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_files")
+    @patch("moban.plugins.template.MobanEngine.render_to_files")
     def test_single_command(self, fake_template_doer):
         test_args = ["moban"]
         with patch.object(sys, "argv", test_args):
@@ -261,7 +261,7 @@ def setUp(self):
         )
         self.patcher1.start()
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_files")
+    @patch("moban.plugins.template.MobanEngine.render_to_files")
     def test_single_command(self, fake_template_doer):
         test_args = ["moban", "-m", self.config_file]
         with patch.object(sys, "argv", test_args):
@@ -296,7 +296,7 @@ def setUp(self):
         )
         self.patcher1.start()
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_file")
+    @patch("moban.plugins.template.MobanEngine.render_to_file")
     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):
@@ -307,7 +307,7 @@ def test_template_option_override_moban_file(self, fake_template_doer):
                 "setup.py.jj2", "data.yml", "moban.output"
             )
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_file")
+    @patch("moban.plugins.template.MobanEngine.render_to_file")
     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):
@@ -340,7 +340,7 @@ def setUp(self):
         self.config_file = ".moban.yml"
 
     @raises(SystemExit)
-    @patch("moban.plugins.template.TemplateEngine.render_to_files")
+    @patch("moban.plugins.template.MobanEngine.render_to_files")
     def test_no_configuration(self, fake_template_doer):
         with open(self.config_file, "w") as f:
             f.write("")
@@ -351,7 +351,7 @@ def test_no_configuration(self, fake_template_doer):
             main()
 
     @raises(SystemExit)
-    @patch("moban.plugins.template.TemplateEngine.render_to_files")
+    @patch("moban.plugins.template.MobanEngine.render_to_files")
     def test_no_configuration_2(self, fake_template_doer):
         with open(self.config_file, "w") as f:
             f.write("not: related")
@@ -362,7 +362,7 @@ def test_no_configuration_2(self, fake_template_doer):
             main()
 
     @raises(SystemExit)
-    @patch("moban.plugins.template.TemplateEngine.render_to_files")
+    @patch("moban.plugins.template.MobanEngine.render_to_files")
     def test_no_targets(self, fake_template_doer):
         with open(self.config_file, "w") as f:
             f.write("configuration: test")
@@ -395,7 +395,7 @@ def test_single_command(self, _):
             from moban.main import main
 
             with patch(
-                "moban.plugins.template.TemplateEngine.render_to_files"
+                "moban.plugins.template.MobanEngine.render_to_files"
             ) as fake:
                 main()
                 call_args = list(fake.call_args[0][0])
@@ -420,7 +420,7 @@ def setUp(self):
         with open(self.config_file, "w") as f:
             f.write("hello: world")
 
-    @patch("moban.plugins.template.TemplateEngine.render_to_file")
+    @patch("moban.plugins.template.MobanEngine.render_to_file")
     def test_mako_option(self, fake_template_doer):
         test_args = ["moban", "-t", "a.mako"]
         with patch.object(sys, "argv", test_args):
diff --git a/tests/mobanfile/test_mobanfile.py b/tests/mobanfile/test_mobanfile.py
index 2cffe17c..0786108d 100644
--- a/tests/mobanfile/test_mobanfile.py
+++ b/tests/mobanfile/test_mobanfile.py
@@ -112,7 +112,7 @@ def test_is_repo():
     eq_(expected, actual)
 
 
-@patch("moban.plugins.template.TemplateEngine.render_to_files")
+@patch("moban.plugins.template.MobanEngine.render_to_files")
 def test_handle_targets(fake_renderer):
     from moban.mobanfile import handle_targets
 
diff --git a/tests/test_engine.py b/tests/test_engine.py
index 5b45e6a3..086851a1 100644
--- a/tests/test_engine.py
+++ b/tests/test_engine.py
@@ -13,7 +13,7 @@
     import_module_of_extension,
 )
 from moban.plugins.context import Context
-from moban.plugins.template import TemplateEngine, expand_template_directories
+from moban.plugins.template import MobanEngine, expand_template_directories
 
 USER_HOME = os.path.join("user", "home", ".moban", "repos")
 
@@ -63,12 +63,12 @@ def test_unknown_template_type():
 
 @raises(exceptions.DirectoryNotFound)
 def test_non_existent_tmpl_directries():
-    TemplateEngine("abc", "tests", Engine)
+    MobanEngine("abc", "tests", Engine)
 
 
 @raises(exceptions.DirectoryNotFound)
 def test_non_existent_config_directries():
-    TemplateEngine("tests", "abc", Engine)
+    MobanEngine("tests", "abc", Engine)
 
 
 @raises(exceptions.DirectoryNotFound)
diff --git a/tests/test_jinja2_extensions.py b/tests/test_jinja2_extensions.py
index e2eba845..05e4a2eb 100644
--- a/tests/test_jinja2_extensions.py
+++ b/tests/test_jinja2_extensions.py
@@ -3,7 +3,7 @@
 from nose.tools import eq_
 
 from moban.jinja2.engine import Engine
-from moban.plugins.template import TemplateEngine
+from moban.plugins.template import MobanEngine
 from moban.jinja2.extensions import jinja_global
 
 
@@ -12,7 +12,7 @@ def test_globals():
     test_dict = dict(hello="world")
     jinja_global("test", test_dict)
     path = os.path.join("tests", "fixtures", "globals")
-    engine = TemplateEngine([path], path, Engine)
+    engine = MobanEngine([path], path, Engine)
     engine.render_to_file("basic.template", "basic.yml", output)
     with open(output, "r") as output_file:
         content = output_file.read()
diff --git a/tests/test_template.py b/tests/test_template.py
index f00940f9..360c37a8 100644
--- a/tests/test_template.py
+++ b/tests/test_template.py
@@ -8,7 +8,7 @@
 MODULE = "moban.plugins.template"
 
 
-@patch(MODULE + ".TemplateEngine._render_with_finding_data_first")
+@patch(MODULE + ".MobanEngine._render_with_finding_data_first")
 def test_do_templates_1(_do_templates_with_more_shared_data):
     jobs = [
         TemplateTarget("1.template", "data.yml", "1.output"),
@@ -31,7 +31,7 @@ def test_do_templates_1(_do_templates_with_more_shared_data):
     _do_templates_with_more_shared_data.assert_called_with(expected)
 
 
-@patch(MODULE + ".TemplateEngine._render_with_finding_template_first")
+@patch(MODULE + ".MobanEngine._render_with_finding_template_first")
 def test_do_templates_2(_do_templates_with_more_shared_templates):
     jobs = [
         TemplateTarget("1.template", "data1.yml", "1.output"),

From 78e4467612a11d51a959afafdd662c2d7c1472e5 Mon Sep 17 00:00:00 2001
From: chfw <wangc_2011@hotmail.com>
Date: Sun, 24 Feb 2019 21:50:02 +0000
Subject: [PATCH 2/2] :lipstick: reformat code

---
 moban/plugins/template.py         | 4 +---
 moban/repo.py                     | 2 +-
 tests/mobanfile/test_templates.py | 6 ++++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/moban/plugins/template.py b/moban/plugins/template.py
index a069d921..3224ae59 100644
--- a/moban/plugins/template.py
+++ b/moban/plugins/template.py
@@ -14,9 +14,7 @@
 
 class MobanFactory(PluginManager):
     def __init__(self):
-        super(MobanFactory, self).__init__(
-            constants.TEMPLATE_ENGINE_EXTENSION
-        )
+        super(MobanFactory, self).__init__(constants.TEMPLATE_ENGINE_EXTENSION)
         self.extensions = {}
 
     def register_extensions(self, extensions):
diff --git a/moban/repo.py b/moban/repo.py
index 8e04ce5e..36da0582 100644
--- a/moban/repo.py
+++ b/moban/repo.py
@@ -36,7 +36,7 @@ def get_repo_name(repo_url):
     try:
         repo = giturlparse.parse(repo_url)
         name = repo.repo
-        if name.endswith('/'):
+        if name.endswith("/"):
             name = name[:-1]
         return name
     except AttributeError:
diff --git a/tests/mobanfile/test_templates.py b/tests/mobanfile/test_templates.py
index 1379f88e..02479212 100644
--- a/tests/mobanfile/test_templates.py
+++ b/tests/mobanfile/test_templates.py
@@ -59,8 +59,10 @@ def test_listing_dir_recusively(self):
                 None,
             ),
         ]
-        eq_(sorted(expected, key=lambda x: x[0]),
-            sorted(results, key=lambda x: x[0]))
+        eq_(
+            sorted(expected, key=lambda x: x[0]),
+            sorted(results, key=lambda x: x[0]),
+        )
 
     @patch("moban.reporter.report_error_message")
     def test_listing_dir_recusively_with_error(self, reporter):