Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
update splitfuncs.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed Mar 7, 2018
1 parent 3e388f9 commit 95f9a18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
8 changes: 4 additions & 4 deletions alphatwirl/loop/splitfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ def create_files_start_length_list(

files = _apply_max_files(files, max_files)

if not _need_get_number_of_events_in_files(max_events, max_events_per_run):
if max_events == 0 or max_events_per_run == 0:
return [ ]

if max_events < 0 and max_events_per_run < 0:
return _fast_path(files, max_files_per_run)

return _full_path(files, func_get_nevents_in_file, max_events,
Expand All @@ -20,9 +23,6 @@ def _apply_max_files(files, max_files):
return files
return files[:min(max_files, len(files))]

def _need_get_number_of_events_in_files(max_events, max_events_per_run):
return max_events >= 0 or max_events_per_run >= 0

def _fast_path(files, max_files_per_run):
if not files:
return [ ]
Expand Down
35 changes: 17 additions & 18 deletions tests/unit/loop/test_splitfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@
from alphatwirl.loop.splitfuncs import _apply_max_files
from alphatwirl.loop.splitfuncs import _file_nevents_list
from alphatwirl.loop.splitfuncs import _fast_path
from alphatwirl.loop.splitfuncs import _need_get_number_of_events_in_files

##__________________________________________________________________||
@pytest.fixture()
def wrapped_apply_max_files(monkeypatch):
module = sys.modules['alphatwirl.loop.splitfuncs']
ret = mock.Mock(wraps=_apply_max_files)
monkeypatch.setattr(module, '_apply_max_files', ret)
return ret

@pytest.fixture()
def mock_fast_path(monkeypatch):
module = sys.modules['alphatwirl.loop.splitfuncs']
Expand All @@ -36,6 +42,7 @@ def mock_full_path(monkeypatch):
def test_create_files_start_length_list(
files, max_events, max_events_per_run,
max_files, max_files_per_run,
wrapped_apply_max_files,
mock_fast_path, mock_full_path
):
actual = create_files_start_length_list(
Expand All @@ -47,6 +54,15 @@ def test_create_files_start_length_list(
max_files_per_run=max_files_per_run
)

wrapped_apply_max_files.assert_called_once()

if max_events == 0 or max_events_per_run == 0:
assert [ ] == actual
elif max_events < 0 and max_events_per_run < 0:
assert mock_fast_path() == actual
else:
assert mock_full_path() == actual

##__________________________________________________________________||
def test_create_files_start_length_list_default():
files = mock.sentinel.files
Expand Down Expand Up @@ -183,20 +199,3 @@ def test_fast_path(files, max_files_per_run, expected):
assert expected == actual

##__________________________________________________________________||
@pytest.mark.parametrize('max_events, max_events_per_run, expected', [
( 0, 0, True),
( 0, -1, True),
( 0, 1, True),
(-1, 0, True),
(-1, -1, False),
(-1, 1, True),
( 1, 0, True),
( 1, -1 , True),
( 1, 1, True),
])
def test_need_get_number_of_events_in_files(max_events, max_events_per_run, expected):
actual = _need_get_number_of_events_in_files(max_events, max_events_per_run)
assert expected == actual

##__________________________________________________________________||

0 comments on commit 95f9a18

Please sign in to comment.