Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bopen/mariobros
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamici committed Jan 19, 2016
2 parents bc0ac5c + 3563eb6 commit 3b93338
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 32 deletions.
2 changes: 1 addition & 1 deletion mariobros/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def mariobros(
"""Main mariobros entry point. Parse the configuration file and launch the build of targets.
:param sequence targets: List of targets.
:param str mariofile: Mariofile name.
:param unicode mariofile: Mariofile name.
:param bool print_ns: Flag to print namespace.
:param bool dry_run: Dry run flag.
:param int workers: Number of workers.
Expand Down
7 changes: 4 additions & 3 deletions mariobros/mario.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def factory(
:param int worker_timeout: Worker timeout Luigi task metadata.
:param dict resources: Resources Luigi task metadata.
:param bool disabled: Disabled Luigi task metadata.
:param unicode dry_run_suffix: Suffix to be added to file created during dry run.
:rtype: subclass_of_ReRuleTask
"""
# FIXME: move class init code to init method?
Expand Down Expand Up @@ -158,7 +159,7 @@ def remove_dry_run_file(self):
def render_template(template, local_namespace, default_namespace={}):
"""Return the rendered template merging local and default namespaces.
:param str template: Template.
:param unicode template: Template.
:param dict local_namespace: Local namespace.
:param dict default_namespace: Default namespace.
:rtype: str
Expand Down Expand Up @@ -198,7 +199,7 @@ def register_tasks(namespaces, default_namespace={}, dry_run_suffix=''):
:param dict namespaces: Task namespaces.
:param dict default_namespace: Default namespaces.
:param bool dry_run_suffix: Suffix to be added to file created during dry run.
:param unicode dry_run_suffix: Suffix to be added to file created during dry run.
:rtype: iterable
"""

Expand Down Expand Up @@ -238,7 +239,7 @@ def print_namespaces(default_namespace, section_namespaces):
def render_config(section_namespaces):
"""Parse and render a Mariofile.
:param str mariofile: Mariofile path.
:param dict section_namespaces: Section namespaces dictionary.
:return: (dict, dict, dict)
"""
default_namespace = render_namespace(section_namespaces['DEFAULT'])
Expand Down
6 changes: 3 additions & 3 deletions mariobros/mariofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def parse_sections(stream):


def parse_include(raw_lines):
"""Parse the intestation of the raw_lines and return a list of filepaths to be included.
"""Parse the heading of the raw_lines and return a list of filepaths to be included.
:param iterable raw_lines: Mariofile raw_lines.
:rtype: (list, iterable)
Expand All @@ -118,7 +118,7 @@ def parse_config(raw_lines, cwd='.'):
"""Parse the input Mariofile and the included Mariofiles recursively and return a dictionary
with the section name as the key and the section namespace as the value.
:param str raw_lines: Mariofile per lines.
:param iterable raw_lines: Mariofile per lines.
:param str cwd: Current working directory.
:rtype: dict
"""
Expand All @@ -137,7 +137,7 @@ def parse_config(raw_lines, cwd='.'):
def parse_mariofile(file_path, cwd='.'):
"""Parse input mariofile.
:param str file_path: File path.
:param unicode file_path: File path.
:param str cwd: Current working directory.
:return: dict
"""
Expand Down
1 change: 0 additions & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pytest
mock
pytest-cov
pytest-pep8
pytest-flakes
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
extras_require={
'dev': [
'check-manifest',
'pytest',
'pytest-cov',
'pytest-flakes',
'pytest-pep8',
Expand Down
28 changes: 24 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import glob
import os
import shlex

import click.testing

from mariobros import cli

TOUCH_FILE = r"""touched-([^-.]+)-([^-.]+).file: touched-\1.file touched-\2.file
TOUCH_FILE = r"""touched-11-22.file: touched-11.file touched-22.file
touch ${TARGET}
[touch_single]
Expand All @@ -16,15 +20,31 @@ def test_mariobros(tmpdir):
f = mario_folder.join('touch_file.ini')
f.write(TOUCH_FILE)
cli.mariobros(
targets=['touched-11-22.file', ], mariofile='touch_file.ini', local_scheduler=True
targets=['touched-11-22.file', ], mariofile=u'touch_file.ini', local_scheduler=True
)
created_files = sorted(glob.glob('touched*'))
assert created_files == ['touched-11-22.file', 'touched-11.file', 'touched-22.file']
cli.mariobros(
targets=['touched-11-22.file', ], mariofile='touch_file.ini', local_scheduler=True,
targets=['touched-11-22.file', ], mariofile=u'touch_file.ini', local_scheduler=True,
dry_run=True, workers=2
)
cli.mariobros(
targets=['touched-11-22.file', ], mariofile='touch_file.ini', local_scheduler=True,
targets=['touched-11-22.file', ], mariofile=u'touch_file.ini', local_scheduler=True,
print_ns=True
)


def test_cli(tmpdir):
mario_folder = tmpdir.mkdir('tmpdir')
mario_folder.chdir()
f = mario_folder.join('touch_file.ini')
f.write(TOUCH_FILE)

runner = click.testing.CliRunner()
mariofile = os.path.join(mario_folder.dirname, 'tmpdir/touch_file.ini')
args = shlex.split('-f {} --local-scheduler touched-11-22.file'.format(mariofile))
result = runner.invoke(cli.main, args=args)
assert not result.exception
args = shlex.split('-f {} --local-scheduler'.format(mariofile))
result = runner.invoke(cli.main, args=args)
assert not result.exception
39 changes: 19 additions & 20 deletions tests/test_mariofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@


def test_parse_sections():
SIMPLE_MARIOFILE_sections = dict(mariofile.parse_sections(SIMPLE_MARIOFILE.splitlines(True)))
assert len(SIMPLE_MARIOFILE_sections) == 3
complex_MARIOFILE_sections = dict(mariofile.parse_sections(COMPLEX_MARIOFILE.splitlines(True)))
assert len(complex_MARIOFILE_sections) == 2
assert sorted(complex_MARIOFILE_sections.keys()) == ['DEFAULT', 'section']
assert complex_MARIOFILE_sections['DEFAULT'] == ['default text\n', '\n']
simple_mariofile_sections = dict(mariofile.parse_sections(SIMPLE_MARIOFILE.splitlines(True)))
assert len(simple_mariofile_sections) == 3
complex_mariofile_sections = dict(mariofile.parse_sections(COMPLEX_MARIOFILE.splitlines(True)))
assert len(complex_mariofile_sections) == 2
assert sorted(complex_mariofile_sections.keys()) == ['DEFAULT', 'section']
assert complex_mariofile_sections['DEFAULT'] == ['default text\n', '\n']
with pytest.raises(mariofile.ConfigurationFileError):
dict(mariofile.parse_sections(GARBAGE_MARIOFILE.splitlines(True)))
with pytest.raises(mariofile.ConfigurationFileError):
dict(mariofile.parse_sections(INVALID_SECTION_MARIOFILE.splitlines(True)))
more_complex_MARIOFILE_sections = dict(
more_complex_mariofile_sections = dict(
mariofile.parse_sections(MORE_COMPLEX_MARIOFILE.splitlines(True))
)
more_complex_MARIOFILE_sections_keys = ['DEFAULT', 'section_one', 'section_two', 'three']
assert sorted(more_complex_MARIOFILE_sections.keys()) == more_complex_MARIOFILE_sections_keys
assert more_complex_MARIOFILE_sections['three'] == []
more_complex_mariofile_sections_keys = ['DEFAULT', 'section_one', 'section_two', 'three']
assert sorted(more_complex_mariofile_sections.keys()) == more_complex_mariofile_sections_keys
assert more_complex_mariofile_sections['three'] == []


CRASH_MARIOFILE_1 = '''
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_parse_include():


def test_parse_config(tmpdir):
parsed_MARIOFILE = {
parsed_mariofile = {
'DEFAULT': {
'action_template': '',
'sources_repls': '',
Expand All @@ -208,8 +208,8 @@ def test_parse_config(tmpdir):
'sources_repls': 'source1',
'target_pattern': 'target1'}
}
mariofile.parse_config(MARIOFILE.splitlines(True)) == parsed_MARIOFILE
parsed_MARIOFILE_include_test = {
mariofile.parse_config(MARIOFILE.splitlines(True)) == parsed_mariofile
parsed_mariofile_include_test = {
'DEFAULT': {
'action_template': '',
'sources_repls': '',
Expand All @@ -235,15 +235,14 @@ def test_parse_config(tmpdir):
g = mario_folder.join('test_include.ini')
g.write('')
mario_folder.chdir()
# with patch('mariobros.mariofile.open', mock_open(read_data=MARIOFILE_INCLUDE), create=True):
parsed_MARIOFILE_include = mariofile.parse_config(
parsed_mariofile_include = mariofile.parse_config(
MARIOFILE_AND_INCLUDE.splitlines(True),
cwd=os.path.join(str(mario_folder.dirname), 'tmpdir')
)
for key, value in parsed_MARIOFILE_include.items():
assert value == parsed_MARIOFILE_include_test[key], print(key)
for key, value in parsed_mariofile_include.items():
assert value == parsed_mariofile_include_test[key], print(key)

parsed_MARIOFILE_multiple_include = {
parsed_mariofile_multiple_include = {
'DEFAULT': {
'action_template': '',
'sources_repls': '',
Expand All @@ -264,8 +263,8 @@ def test_parse_config(tmpdir):
}
h = mario_folder.join('test_parse_config.ini')
h.write(TEST_PARSE_CONFIG)
parsed_MARIOFILE_include = mariofile.parse_config(MARIOFILE_AND_INCLUDE.splitlines(True),
parsed_mariofile_include = mariofile.parse_config(MARIOFILE_AND_INCLUDE.splitlines(True),
cwd=os.path.join(
str(mario_folder.dirname), 'tmpdir'
))
assert parsed_MARIOFILE_include == parsed_MARIOFILE_multiple_include
assert parsed_mariofile_include == parsed_mariofile_multiple_include

0 comments on commit 3b93338

Please sign in to comment.