Skip to content

Commit 5ce3380

Browse files
zoldelloPhilip Adenekan
authored andcommitted
e2eTests
1 parent a9bb879 commit 5ce3380

24 files changed

+1841
-1
lines changed

.github/workflows/e2eTest.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Project Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
defaults:
9+
run:
10+
shell: bash -l {0}
11+
strategy:
12+
matrix:
13+
python-version: ["3.6"]
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
- uses: conda-incubator/setup-miniconda@v2
21+
with:
22+
miniconda-version: "latest"
23+
activate-environment: rec_to_binaries
24+
environment-file: environment.yml
25+
- run: mkdir -p ~/SpikeGadgets
26+
- run: python -m pytest rec_to_binaries/test/e2etests/

environment.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: rec_to_binaries
22
channels:
33
- conda-forge
4+
- franklab
45
dependencies:
56
- jupyter
67
- jupyterlab
78
- matplotlib
8-
- pandas
9+
- "pandas = 0.24.0"
910
- numpy
1011
- scipy
1112
- "python >= 3.6"
@@ -14,6 +15,7 @@ dependencies:
1415
- pytest
1516
- pytest-cov
1617
- coveralls
18+
- rec_to_binaries
1719
- pip
1820
- pip:
1921
- mountainlab-pytools

my_file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
abc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# __init__.py
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
import os
3+
4+
CURRENT_DIRECTORY = os.getcwd()
5+
6+
def _clear_file_content(file_path):
7+
if file_path is None or file_path.strip() == '':
8+
raise FileNotFoundError
9+
with open(file_path, 'r+') as file:
10+
file.truncate(0)
11+
12+
@pytest.fixture
13+
def e2etests_directory_path():
14+
return f'{CURRENT_DIRECTORY}/rec_to_binaries/test/e2etests/'
15+
16+
@pytest.fixture
17+
def current_directory():
18+
return CURRENT_DIRECTORY
19+
20+
@pytest.fixture
21+
def clear_file_content():
22+
return _clear_file_content
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
import numpy as np
3+
from rec_to_binaries.adjust_timestamps import (
4+
fix_timestamp_lag,
5+
)
6+
7+
@pytest.mark.skip(reason='not implemented')
8+
def test_fix_timestamp_lag_check_if_data_is_written_no_systime(e2etests_directory_path, clear_file_content):
9+
# # arrange
10+
# file_path = f'{e2etests_directory_path}/test_data/fix_timestamp_lag_check_if_data_is_written_no_systime.txt'
11+
# clear_file_content(file_path)
12+
# fake_data = np.array([
13+
# ('just', 1),
14+
# ('another', 2),
15+
# ('part', 3)], dtype=[('one', 'b1'), ('two', '<b1')]
16+
# )
17+
# with open(file_path, "wb") as file:
18+
# file.write(bytes(b'<Start settings>'))
19+
# file.write(bytes(b'\n'))
20+
# file.write(b'data: ')
21+
# file.write(fake_data)
22+
# file.write(bytes(b'\n'))
23+
# file.write(bytes(b'<End settings>'))
24+
25+
# fix_timestamp_lag(file_path)
26+
# # act
27+
28+
# # assert
29+
pass
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import pytest
2+
from rec_to_binaries.binary_utils import (
3+
TrodesBinaryFormatError,
4+
TrodesBinaryReader,
5+
TrodesLFPBinaryLoader,
6+
TrodesTimestampBinaryLoader,
7+
TrodesSpikeBinaryLoader,
8+
TrodesPosBinaryLoader,
9+
TrodesDIOBinaryLoader,
10+
)
11+
12+
def test_TrodesBinaryReader_first_line_not_Start_settings_error(e2etests_directory_path):
13+
file_path = f'{e2etests_directory_path}/test_data/TrodesBinaryReader_test_first_line_exception.txt'
14+
15+
with pytest.raises(TrodesBinaryFormatError) as ex:
16+
trodes_binary_reader = TrodesBinaryReader(file_path)
17+
18+
19+
def test_TrodesBinaryReader_more_than_1000_length_error(e2etests_directory_path):
20+
file_path = f'{e2etests_directory_path}/test_data/TrodesBinaryReader_test_more_than_1000_line_exception.txt'
21+
22+
with pytest.raises(TrodesBinaryFormatError):
23+
trodes_binary_reader = TrodesBinaryReader(file_path)
24+
25+
def test_TrodesBinaryReader_check_if_valid_file_is_read(e2etests_directory_path):
26+
file_path = f'{e2etests_directory_path}/test_data/TrodesBinaryReader_check_if_valid_file_is_read.txt'
27+
trodes_binary_reader = TrodesBinaryReader(file_path)
28+
29+
assert trodes_binary_reader.data_start_byte == 43
30+
assert trodes_binary_reader.header_params == {'a': '1', 'data': '2'}
31+
32+
def test_TrodesLFPBinaryLoader_check_if_file_can_be_read(e2etests_directory_path):
33+
file_path = f'{e2etests_directory_path}/test_data/TrodesLFPBinaryLoader_test_file_read.txt'
34+
trodes_LFP_binary_loader = TrodesLFPBinaryLoader(file_path)
35+
36+
assert trodes_LFP_binary_loader.header_params['Original_file'] == 'test_Original_file'
37+
assert trodes_LFP_binary_loader.header_params['Trode_ID'] == 'test_Trode_ID'
38+
assert trodes_LFP_binary_loader.header_params['Trode_channel'] == 'test_Trode_channel'
39+
assert trodes_LFP_binary_loader.header_params['Clock rate'] == 'test_Clock rate'
40+
assert trodes_LFP_binary_loader.header_params['Voltage_scaling'] == 'test_Voltage_scaling'
41+
assert trodes_LFP_binary_loader.header_params['Decimation'] == 'test_Decimation'
42+
assert trodes_LFP_binary_loader.header_params['First_timestamp'] == 'test_First_timestamp'
43+
assert trodes_LFP_binary_loader.header_params['Reference'] == 'test_Reference'
44+
assert trodes_LFP_binary_loader.header_params['Low_pass_filter'] == 'test_Low_pass_filter'
45+
assert trodes_LFP_binary_loader.header_params['Fields'] == 'test_Fields'
46+
47+
def test_TrodesTimestampBinaryLoader_check_if_file_can_be_read(e2etests_directory_path):
48+
file_path = f'{e2etests_directory_path}/test_data/TrodesTimestampBinaryLoader_test_file_read.txt'
49+
trodes_timestamp_binary_loader = TrodesTimestampBinaryLoader(file_path)
50+
51+
assert trodes_timestamp_binary_loader.header_params['Byte_order'] == 'test_Byte_order'
52+
assert trodes_timestamp_binary_loader.header_params['Original_file'] == 'test_Original_file'
53+
assert trodes_timestamp_binary_loader.header_params['Clock rate'] == 'test_Clock rate'
54+
assert trodes_timestamp_binary_loader.header_params['Decimation'] == 'test_Decimation'
55+
assert trodes_timestamp_binary_loader.header_params['Time_offset'] == 'test_Time_offset'
56+
assert trodes_timestamp_binary_loader.header_params['Fields'] == 'test_Fields'
57+
58+
def test_TrodesSpikeBinaryLoader_check_if_data_file_is_read(e2etests_directory_path):
59+
file_path = f'{e2etests_directory_path}/test_data/TrodesSpikeBinaryLoader_test_file_read.txt'
60+
trodes_spike_binary_loader = TrodesSpikeBinaryLoader(file_path)
61+
62+
63+
assert trodes_spike_binary_loader.header_params['Original_file'] == 'test_Original_file'
64+
assert trodes_spike_binary_loader.header_params['nTrode_ID'] == '1'
65+
assert trodes_spike_binary_loader.num_channels == 10
66+
assert trodes_spike_binary_loader.header_params['Clock rate'] == '3'
67+
assert trodes_spike_binary_loader.header_params['Voltage_scaling'] == 'v'
68+
assert trodes_spike_binary_loader.header_params['Time_offset'] == '4'
69+
assert trodes_spike_binary_loader.header_params['Threshold'] == '5'
70+
assert trodes_spike_binary_loader.header_params['Spike_invert'] == 't'
71+
assert trodes_spike_binary_loader.header_params['Reference'] == '6'
72+
assert trodes_spike_binary_loader.header_params['ReferenceNTrode'] == '7'
73+
assert trodes_spike_binary_loader.header_params['ReferenceChannel'] == '8'
74+
assert trodes_spike_binary_loader.header_params['Filter'] == 't'
75+
assert trodes_spike_binary_loader.header_params['lowPassFilter'] == 'y'
76+
assert trodes_spike_binary_loader.header_params['highPassFilter'] == 'n'
77+
assert trodes_spike_binary_loader.header_params['Fields'] == 'test_field'
78+
assert trodes_spike_binary_loader.spike_rec_size == 804
79+
80+
@pytest.mark.skip(reason="I have to figure out why pos_list stays empty")
81+
def test_TrodesPosBinaryLoader_check_if_data_file_is_read(e2etests_directory_path):
82+
file_path = f'{e2etests_directory_path}/test_data/TrodesPosBinaryLoader_check_if_data_file_is_read.txt'
83+
trodes_pos_binary_loader = TrodesPosBinaryLoader(file_path)
84+
85+
breakpoint()
86+
87+
assert trodes_pos_binary_loader.header_params['threshold'] == 'test_threshold'
88+
assert trodes_pos_binary_loader.header_params['dark'] == 'test_dark'
89+
assert trodes_pos_binary_loader.header_params['clockrate'] == 'test_clockrate'
90+
assert trodes_pos_binary_loader.header_params['field_str'] == 'test_Fields'
91+
assert trodes_pos_binary_loader.rec_size == 12
92+
assert trodes_pos_binary_loader.unpack_format == 'IHHHH'
93+
94+
@pytest.mark.skip(reason="I have to figure out why pos_list stays empty")
95+
def test_TrodesDIOBinaryLoader_check_if_data_file_is_read(e2etests_directory_path):
96+
file_path = f'{e2etests_directory_path}/test_data/TrodesPosBinaryLoader_check_if_data_file_is_read.txt'
97+
trodes_pos_binary_loader = TrodesDIOBinaryLoader(file_path)
98+
99+
assert True
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
from rec_to_binaries.core import (
3+
extract_trodes_rec_file,
4+
convert_binaries_to_hdf5,
5+
)
6+
7+
@pytest.mark.skip(reason='Got to figure out the many cases')
8+
def extract_trodes_rec_file():
9+
pass
10+
11+
@pytest.mark.skip(reason='Got to figure out - type object \'object\' has no attribute \'dtype')
12+
def test_convert_binaries_to_hdf5_rec_file_write_to_file(e2etests_directory_path):
13+
data_dir = e2etests_directory_path
14+
animal = 'test_animal'
15+
convert_binaries_to_hdf5(data_dir,
16+
animal,
17+
out_dir=None,
18+
dates=None,
19+
parallel_instances=1,
20+
convert_dio=False,
21+
convert_lfp=False,
22+
convert_pos=False,
23+
convert_spike=False
24+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pytest
2+
3+
@pytest.mark.skip(reason='not implemented')
4+
def test_infer_systime():
5+
pass
6+
7+
@pytest.mark.skip(reason='not implemented')
8+
def test_create_systime():
9+
pass
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Start settings>
2+
a:1
3+
data:2
4+
<End settings>

0 commit comments

Comments
 (0)