diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e65ca2..aa889dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## [1.16.2] - 2019-??-?? ### Added - Allow loading from already opened file objects, e.g. in-memory files or network streams ([#51](https://github.com/xdf-modules/xdf-python/pull/51) by [Tristan Stenner](https://github.com/tstenner)). +- Add CI tests with example data ([#49](https://github.com/xdf-modules/xdf-Python/pull/49) by [Clemens Brunner](https://github.com/cbrnr)). ### Fixed - Compare nominal to effective sampling rates only for regularly sampled streams ([#47](https://github.com/xdf-modules/xdf-Python/pull/47) by [Clemens Brunner](https://github.com/cbrnr)). diff --git a/azure-pipelines.yml b/azure-pipelines.yml index da89156..6369046 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -31,16 +31,20 @@ steps: - script: | python -m pip install --upgrade pip wheel twine setuptools_scm pip install numpy - displayName: 'Install Dependencies' + displayName: 'Install dependencies' + +- script: | + git clone --depth 1 https://github.com/xdf-modules/example-files.git + displayName: 'Download test data' - script: | pip install pytest pytest-azurepipelines pytest - displayName: 'pytest' + displayName: 'Test' - script: | python setup.py sdist bdist_wheel - displayName: 'Build Wheel' + displayName: 'Build wheel' - task: TwineAuthenticate@0 condition: and(succeeded(), contains(variables['Build.SourceBranch'], 'refs/tags/')) diff --git a/pyxdf/test/test_data.py b/pyxdf/test/test_data.py new file mode 100644 index 0000000..b8005d0 --- /dev/null +++ b/pyxdf/test/test_data.py @@ -0,0 +1,68 @@ +from pathlib import Path +from pyxdf import load_xdf +import pytest +import numpy as np + + +# requires git clone https://github.com/xdf-modules/example-files.git +# into the root xdf-python folder +path = Path("example-files") +extensions = ["*.xdf", "*.xdfz", "*.xdf.gz"] +files = [] +for ext in extensions: + files.extend(path.glob(ext)) +files = [str(file) for file in files] + + +@pytest.mark.parametrize("file", files) +def test_load_file(file): + streams, header = load_xdf(file) + + if file.endswith("minimal.xdf"): + assert header["info"]["version"][0] == "1.0" + + assert len(streams) == 2 + assert streams[0]["info"]["name"][0] == "SendDataC" + assert streams[0]["info"]["type"][0] == "EEG" + assert streams[0]["info"]["channel_count"][0] == "3" + assert streams[0]["info"]["nominal_srate"][0] == "10" + assert streams[0]["info"]["channel_format"][0] == "int16" + assert streams[0]["info"]["stream_id"] == 0 + + s = np.array([[192, 255, 238], + [12, 22, 32], + [13, 23, 33], + [14, 24, 34], + [15, 25, 35], + [12, 22, 32], + [13, 23, 33], + [14, 24, 34], + [15, 25, 35]], dtype=np.int16) + t = np.array([5., 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8]) + np.testing.assert_array_equal(streams[0]["time_series"], s) + np.testing.assert_array_almost_equal(streams[0]["time_stamps"], t) + + assert streams[1]["info"]["name"][0] == "SendDataString" + assert streams[1]["info"]["type"][0] == "StringMarker" + assert streams[1]["info"]["channel_count"][0] == "1" + assert streams[1]["info"]["nominal_srate"][0] == "10" + assert streams[1]["info"]["channel_format"][0] == "string" + assert streams[1]["info"]["stream_id"] == 0x02C0FFEE + + s = [['LabRecorder xdfwriter' + '5.1' + '5.99' + '-.01' + '-.02' + ''], + ['Hello'], + ['World'], + ['from'], + ['LSL'], + ['Hello'], + ['World'], + ['from'], + ['LSL']] + t = np.array([5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9]) + assert streams[1]["time_series"] == s + np.testing.assert_array_almost_equal(streams[1]["time_stamps"], t)