Skip to content
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
9 changes: 6 additions & 3 deletions pyndl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ def sysinfo():

if uname.sysname == "Linux":
_, *lines = os.popen("free -m").readlines()
for identifier in ["Mem:", "Swap:"]:
memory = [line for line in lines if identifier in line][0]
_, total, used, *_ = memory.split()
for identifier in ("Mem:", "Swap:"):
memory = [line for line in lines if identifier in line]
if len(memory) > 0:
_, total, used, *_ = memory[0].split()
else:
total, used = '?', '?'
osinfo += "{} {}MiB/{}MiB\n".format(identifier, used, total)

osinfo += "\n"
Expand Down
4 changes: 3 additions & 1 deletion pyndl/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def read_clean_gzfile(gz_file_path, *, break_duration=2.0):
text = word_tag.text
if text in PUNCTUATION:
words.append(text)
else:
elif text is not None:
words.extend((' ', text))
else:
raise ValueError("Text content of word tag is None.")
result = ''.join(words)
result = result.strip()

Expand Down
10 changes: 6 additions & 4 deletions pyndl/ndl.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ def worker():

def _attributes(event_path, number_events, alpha, betas, lambda_, cpu_time,
wall_time, function, method=None, attrs=None):
if not isinstance(alpha, (float, int)):
alpha_str = 'varying'
else:
alpha_str = str(alpha)

width = max([len(ss) for ss in (event_path,
str(number_events),
str(alpha),
Expand All @@ -235,13 +240,10 @@ def _attributes(event_path, number_events, alpha, betas, lambda_, cpu_time,
def _format(value):
return '{0: <{width}}'.format(value, width=width)

if not isinstance(alpha, (float, int)):
alpha = 'varying'

new_attrs = {'date': _format(time.strftime("%Y-%m-%d %H:%M:%S")),
'event_path': _format(event_path),
'number_events': _format(number_events),
'alpha': _format(str(alpha)),
'alpha': _format(alpha_str),
'betas': _format(str(betas)),
'lambda': _format(str(lambda_)),
'function': _format(function),
Expand Down
13 changes: 12 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
Configuration for py.test-3.

'''
import pytest


def pytest_addoption(parser):
"""
adds custom option to the pytest parser
"""
parser.addoption("--runslow", action="store_true",
help="run slow tests")
default=False, help="run slow tests")


def pytest_collection_modifyitems(config, items):
if config.getoption("--runslow"):
# --runslow given in cli: do not skip slow tests
return
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
4 changes: 1 addition & 3 deletions tests/test_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from pyndl import ndl
from pyndl.activation import activation

slow = pytest.mark.skipif(not pytest.config.getoption("--runslow"), # pylint: disable=invalid-name
reason="need --runslow option to run")

TEST_ROOT = os.path.join(os.path.pardir, os.path.dirname(__file__))
FILE_PATH_SIMPLE = os.path.join(TEST_ROOT, "resources/event_file_simple.tab.gz")
Expand Down Expand Up @@ -140,7 +138,7 @@ def test_ignore_missing_cues_dict():
assert np.allclose(reference_activations[outcome], activation_list)


@slow
@pytest.mark.slow
def test_activation_matrix_large():
"""
Test with a lot of data. Better run only with at least 12GB free RAM.
Expand Down