Skip to content

Commit

Permalink
Standardize and layer existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Jun 14, 2024
1 parent 4ab30c3 commit 5eb0ef2
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 332 deletions.
13 changes: 13 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import platform
import os

def get_recording_dir():
if platform.system() == 'Windows':
if os.env("GITHUB_ACTIONS") == "true":
return 'C:\\open-ephys\\data'
else:
os.getenv('OE_RECORD_DIR')
elif platform.system() == 'Linux':
return '<path/to/linux/runner>' # TODO
else:
return '<path/to/Mac/runner>' # TODO
40 changes: 32 additions & 8 deletions run_all.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
import os
import platform
import glob
import pathlib
import time
import platform

tests = (
'processor_graph_actions.py',
'get_set_parameters.py',
'basic_acquire.py',
'basic_record.py',
'get_set_recording_info.py',
'config_audio_device.py',
'round_trip_record.py',
'channel_map.py' #TODO: add more plugin specific tests
)

GHA = os.getenv("GITHUB_ACTIONS") == "true"

tests = glob.glob(os.path.join(pathlib.Path().absolute(), "tests", "*.py"))
RECORD_PATH = ''
if platform.system() == 'Windows':
if GHA: RECORD_PATH = 'C:\\open-ephys\\data'
else:
pass #define local path here
elif platform.system() == 'Linux':
if GHA: pass #RECORD_PATH = '<path/to/linux/runner>' # TODO
else:
pass #define local path here
else: #macos
if GHA: pass #RECORD_PATH = '<path/to/Mac/runner>' # TODO
else: RECORD_PATH = '/Volumes/T7/test-suite/'

for test in tests:
print("Running: ", test)
rc = os.system("python " + test + " --mode local --fetch 1")
print("--------------------------------")
print("Running: ", test[:-3])
print("--------------------------------")
rc = os.system(f"python3 ./tests/{test} --parent_directory {RECORD_PATH}")
if rc != 0:
print("Test failed: ", test)
print("TEST FAILED: ", test)
break
time.sleep(4)
time.sleep(1)
111 changes: 0 additions & 111 deletions tests/add_delete_processors.py

This file was deleted.

28 changes: 3 additions & 25 deletions tests/basic_acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ def test(gui, params):

results = {}

# Fetch fresh data if needed
if params['fetch']:

gui.clear_signal_chain()

gui.add_processor('File Reader')

testName = 'Start acquisition'

gui.acquire()
time.sleep(params['acq_time'])

print(gui.status())

if gui.status() == 'ACQUIRE':
results[testName] = "PASSED"
else:
Expand All @@ -41,36 +40,15 @@ def test(gui, params):
'''
================================================================================================================================================
'''
import os
import sys
import argparse
import platform

from pathlib import Path

if platform.system() == 'Windows':
RECORD_PATH = 'C:\\open-ephys\\data'
elif platform.system() == 'Linux':
RECORD_PATH = '<path/to/linux/runner>' #TODO
else:
RECORD_PATH = '<path/to/mac/runner>' #TODO

if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--mode', required=True, choices={'local', 'githubactions'})
parser.add_argument('--fetch', required=False, type=int, default=1)
parser.add_argument('--address', required=False, type=str, default='http://127.0.0.1')
parser.add_argument('--cfg_path', required=False, type=str, default=os.path.join(Path(__file__).resolve().parent, '../configs/file_reader_config.xml'))
parser.add_argument('--parent_directory', required=False, type=str, default='C:\\open-ephys\\data')
parser.add_argument('--acq_time', required=False, type=int, default=2)
parser.add_argument('--rec_time', required=False, type=int, default=2)
parser.add_argument('--num_rec', required=False, type=int, default=1)
parser.add_argument('--num_exp', required=False, type=int, default=3)
parser.add_argument('--prepend_text', required=False, type=str, default='auto')
parser.add_argument('--base_text', required=False, type=str, default='auto')
parser.add_argument('--append_text', required=False, type=str, default='auto')
parser.add_argument('--parent_directory', required=False, type=str, default=RECORD_PATH)
parser.add_argument('--engine', required=False, type=str, default='engine=0')

params = vars(parser.parse_args(sys.argv[1:]))

Expand Down
35 changes: 18 additions & 17 deletions tests/basic_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from open_ephys.analysis import Session

"""
Test Name: Add/Delete Processor
Test Description: Add and delete a processor from the signal chain
Test Name: Minimal Recording
Test Description: Record and check data from the default signal chain
"""

SET_RECORD_PATH = True

def test(gui, params):

results = {}
Expand All @@ -18,12 +20,12 @@ def test(gui, params):
if params['fetch']:

# Load config for this test
if params['mode'] == 'local':
gui.load(params['cfg_path'])
gui.load(params['cfg_path'])

for node in gui.get_processors("Record Node"):
gui.set_record_engine(node['id'], params['engine'])
gui.set_record_path(node['id'], params['parent_directory'])
if SET_RECORD_PATH:
for node in gui.get_processors("Record Node"):
gui.set_record_engine(node['id'], params['engine'])
gui.set_record_path(node['id'], params['parent_directory'])

# Run some actions and record data
for _ in range(params['num_exp']):
Expand All @@ -41,6 +43,8 @@ def test(gui, params):
show = False
session = Session(gui.get_latest_recordings(params['parent_directory'])[0])

if show: print(session)

for node_idx, node in enumerate(session.recordnodes):

testName = "Total recordings"
Expand All @@ -63,6 +67,12 @@ def test(gui, params):
else:
results[testName] = "FAILED\nExpected: %d\nActual: %d" % (len(stream.timestamps), params['rec_time']*stream.metadata['sample_rate'])

#print first few samples, sample_numbers and timestamps in 3 cols
if show:
print("Sample Number\tTimestamp\tData")
for i in range(10):
print("%d\t\t%.5f\t\t%.3f" % (stream.sample_numbers[i], stream.timestamps[i], stream.samples[i,1]))

return results


Expand All @@ -76,19 +86,11 @@ def test(gui, params):

from pathlib import Path

if platform.system() == 'Windows':
RECORD_PATH = 'C:\\open-ephys\\data'
elif platform.system() == 'Linux':
RECORD_PATH = '<path/to/linux/runner>' #TODO
else:
RECORD_PATH = '/Users/pavelkulik/Projects/Allen/OpenEphys/data/test-suite'

if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--mode', required=True, choices={'local', 'githubactions'})
parser.add_argument('--fetch', required=False, type=int, default=1)
parser.add_argument('--address', required=False, type=str, default='http://127.0.0.1')
parser.add_argument('--parent_directory', required=False, type=str, default='C:\\open-ephys\\data')
parser.add_argument('--cfg_path', required=False, type=str, default=os.path.join(Path(__file__).resolve().parent, '../configs/file_reader_config.xml'))
parser.add_argument('--acq_time', required=False, type=int, default=2)
parser.add_argument('--rec_time', required=False, type=int, default=5)
Expand All @@ -97,7 +99,6 @@ def test(gui, params):
parser.add_argument('--prepend_text', required=False, type=str, default='')
parser.add_argument('--base_text', required=False, type=str, default='')
parser.add_argument('--append_text', required=False, type=str, default='')
parser.add_argument('--parent_directory', required=False, type=str, default=RECORD_PATH)
parser.add_argument('--engine', required=False, type=str, default='engine=0')

params = vars(parser.parse_args(sys.argv[1:]))
Expand Down
9 changes: 5 additions & 4 deletions tests/audio_device.py → tests/config_audio_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ def test(gui, params):
gui.idle()

#Record data with various buffer sizes and sample rates
BUFFER_SIZES = [512, 1024, 2048, 4096]
SAMPLE_RATES = [44100, 48000, 88200, 96000]

for buffer_size in [512, 1024, 2048, 4096]:
for buffer_size in BUFFER_SIZES:

for sample_rate in [44100, 48000, 88200, 96000]:
for sample_rate in SAMPLE_RATES:

gui.set_buffer_size(buffer_size)
gui.set_sample_rate(sample_rate)
Expand Down Expand Up @@ -85,7 +87,7 @@ def test(gui, params):

testName = "Recording %d length" % (rec_idx+1)

if abs(stream.data.shape[0] - SAMPLE_RATE * params['rec_time']) < SAMPLE_NUM_TOLERANCE:
if abs(stream.samples.shape[0] - SAMPLE_RATE * params['rec_time']) < SAMPLE_NUM_TOLERANCE:
results[testName] = "PASSED"
else:
results[testName] = "FAILED\nExpected: %d\nActual: %d" % (SAMPLE_RATE * params['rec_time'], stream.data.shape[0])
Expand Down Expand Up @@ -113,7 +115,6 @@ def test(gui, params):
if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--mode', required=True, choices={'local', 'githubactions'})
parser.add_argument('--fetch', required=False, type=int, default=1)
parser.add_argument('--address', required=False, type=str, default='http://127.0.0.1')
parser.add_argument('--cfg_path', required=False, type=str, default=os.path.join(Path(__file__).resolve().parent, '../configs/file_reader_config.xml'))
Expand Down
Loading

0 comments on commit 5eb0ef2

Please sign in to comment.