diff --git a/pyndl/__init__.py b/pyndl/__init__.py index cfa48ad..bb37f3d 100644 --- a/pyndl/__init__.py +++ b/pyndl/__init__.py @@ -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" diff --git a/pyndl/corpus.py b/pyndl/corpus.py index 2ba3510..bc182b7 100644 --- a/pyndl/corpus.py +++ b/pyndl/corpus.py @@ -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() diff --git a/pyndl/ndl.py b/pyndl/ndl.py index 6de76f6..b67540a 100644 --- a/pyndl/ndl.py +++ b/pyndl/ndl.py @@ -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), @@ -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), diff --git a/tests/conftest.py b/tests/conftest.py index cbabdc9..2b9163a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,6 +2,7 @@ Configuration for py.test-3. ''' +import pytest def pytest_addoption(parser): @@ -9,4 +10,14 @@ 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) diff --git a/tests/test_activation.py b/tests/test_activation.py index b99b363..8136280 100644 --- a/tests/test_activation.py +++ b/tests/test_activation.py @@ -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") @@ -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.