Skip to content

Commit

Permalink
added test_readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pauladkisson committed Jul 23, 2024
1 parent cb9ce4d commit dd4d873
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/pynwb/tests/integration/test_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pathlib import Path
from pynwb import NWBHDF5IO

def test_readme(tmp_path):
"""Test the first python code block in the README by simply executing it."""
with open("README.md") as f:
lines = f.readlines()
nwbfile_paths = []
start_line = None
for i, line in enumerate(lines):
if line == "```python\n":
start_line = i
elif line == "```\n" and start_line is not None:
end_line = i
elif line.startswith('nwbfile_path = '):
nwbfile_path = Path(line.split('=')[-1].strip())
nwbfile_paths.append(nwbfile_path)
code_lines = lines[start_line+1:end_line]
code_block = "".join(code_lines)
readme_outputs = {}
exec(code_block, globals(), readme_outputs)
nwbfile = readme_outputs['nwbfile']
nwbfile_path = tmp_path / 'test_ndx_fiber_photometry.nwb'
with NWBHDF5IO(nwbfile_path, mode='w') as io:
io.write(nwbfile)

0 comments on commit dd4d873

Please sign in to comment.