Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for example data to CI #49

Merged
merged 11 commits into from
Oct 23, 2019
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)).
Expand Down
10 changes: 7 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/'))
Expand Down
68 changes: 68 additions & 0 deletions pyxdf/test/test_data.py
Original file line number Diff line number Diff line change
@@ -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)
cbrnr marked this conversation as resolved.
Show resolved Hide resolved

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 = [['<?xml version="1.0"?><info><writer>LabRecorder xdfwriter'
'</writer><first_timestamp>5.1</first_timestamp><last_timestamp>'
'5.9</last_timestamp><sample_count>9</sample_count>'
'<clock_offsets><offset><time>50979.76</time><value>-.01</value>'
'</offset><offset><time>50979.86</time><value>-.02</value>'
'</offset></clock_offsets></info>'],
['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)