Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor code refactoring #236

Merged
merged 2 commits into from
Feb 25, 2019
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
4 changes: 2 additions & 2 deletions moban/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -11,7 +11,7 @@
]


ENGINES = TemplateFactory()
ENGINES = MobanFactory()


def make_sure_all_pkg_are_loaded():
Expand Down
10 changes: 4 additions & 6 deletions moban/plugins/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
log = logging.getLogger(__name__)


class TemplateFactory(PluginManager):
class MobanFactory(PluginManager):
def __init__(self):
super(TemplateFactory, self).__init__(
constants.TEMPLATE_ENGINE_EXTENSION
)
super(MobanFactory, self).__init__(constants.TEMPLATE_ENGINE_EXTENSION)
self.extensions = {}

def register_extensions(self, extensions):
Expand All @@ -25,7 +23,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
)

Expand All @@ -36,7 +34,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
):
Expand Down
2 changes: 1 addition & 1 deletion moban/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 17 additions & 17 deletions tests/integration_tests/test_command_line_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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]
Expand Down Expand Up @@ -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):
Expand All @@ -152,15 +152,15 @@ 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):
from moban.main import main

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):
Expand All @@ -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",
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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("")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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])
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/mobanfile/test_mobanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions tests/mobanfile/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_jinja2_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down