From fd0926c01ca83235988758717a1cb5e210ab056d Mon Sep 17 00:00:00 2001 From: David-Elias Kuenstle Date: Wed, 16 May 2018 11:01:28 +0200 Subject: [PATCH 1/4] Using pytest.config is discouraged. Config in conftest instead --- tests/conftest.py | 13 ++++++++++++- tests/test_activation.py | 4 +--- 2 files changed, 13 insertions(+), 4 deletions(-) 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. From a63295fc3e043392cdbfc573800301dea1d057b2 Mon Sep 17 00:00:00 2001 From: Marc Weitz Date: Tue, 6 Nov 2018 17:02:35 +0100 Subject: [PATCH 2/4] prevents throwing unexpected 'free -m' result --- pyndl/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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" From 6376e81ccf9deba7c81181add70cf39e00598912 Mon Sep 17 00:00:00 2001 From: Marc Weitz Date: Tue, 6 Nov 2018 17:03:52 +0100 Subject: [PATCH 3/4] adds throwing ValueError if text is None --- pyndl/corpus.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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() From 4cfd38b3b2eca36da78083619db2af5204fc2350 Mon Sep 17 00:00:00 2001 From: Marc Weitz Date: Tue, 6 Nov 2018 17:08:47 +0100 Subject: [PATCH 4/4] restructures alpha instance checking --- pyndl/ndl.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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),