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

Delete test files generated from running sphinx gallery examples #1517

Merged
merged 11 commits into from
Aug 14, 2022
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ docs/tmpl.index.rst
# coverage output
tests/coverage/htmlcov
.coverage
.coverage.*

# duecredit output
.duecredit.p
Expand Down
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

### Documentation and tutorial enhancements:
- Support explicit ordering of sphinx gallery tutorials in the docs. @oruebel (#1504), @bdichter (#1495)
- Add developer guide on how to create a new tutorial. @oruebel (#1504)
- Add developer guide on how to create a new tutorial. @oruebel (#1504)
- Add images tutorial. @weiglszonja (#1470)
- Add example code for s3fs in the streaming tutorial. @bdichter (#1499)

### Enhancements and minor changes
- Update coverage workflow, report separate unit vs integration coverage. @rly (#1509)
- Enable passing an S3File created through s3fs, which provides a method for reading an NWB file directly
- Delete test files generated from running sphinx gallery examples. @rly (#1517)
- Enable passing an S3File created through s3fs, which provides a method for reading an NWB file directly
from s3 that is an alternative to ros3. This required relaxing of `NWBHDF5IO` input validation. The `path`
arg is not needed if `file` is provided. `mode` now has a default value of "r".
arg is not needed if `file` is provided. `mode` now has a default value of "r".
@bendichter (#1499)
- Added a method to `NWBMixin` that only raises an error when a check is violated on instance creation,
otherwise throws a warning when reading from a file. The new checks in `ImageSeries` when `external_file`
otherwise throws a warning when reading from a file. The new checks in `ImageSeries` when `external_file`
is provided is used with this method to ensure that that files with invalid data can be read, but prohibits
the user from creating new instances when these checks are violated. @weiglszonja (#1516)

Expand Down
7 changes: 3 additions & 4 deletions docs/gallery/advanced_io/h5dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@

from pynwb import NWBHDF5IO

io = NWBHDF5IO('advanced_io_example.nwb', 'w')
io.write(nwbfile)
io.close()
with NWBHDF5IO('advanced_io_example.nwb', 'w') as io:
io.write(nwbfile)

####################
# Reading the data
Expand All @@ -182,7 +181,7 @@
v.data.chunks,
v.data.compression,
v.data.maxshape))

io.close()
####################
#
# .. code-block:: python
Expand Down
20 changes: 10 additions & 10 deletions docs/gallery/advanced_io/iterative_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,16 +542,16 @@ def iter_largearray(filename, shape, dtype='float64'):
# Read the NWB file
from pynwb import NWBHDF5IO # noqa: F811

io = NWBHDF5IO('basic_sparse_iterwrite_largearray.nwb', 'r')
nwbfile = io.read()
data = nwbfile.get_acquisition('synthetic_timeseries').data
# Compare all the data values of our two arrays
data_match = np.all(arrdata == data[:]) # Don't do this for very large arrays!
# Print result message
if data_match:
print("Success: All data values match")
else:
print("ERROR: Mismatch between data")
with NWBHDF5IO('basic_sparse_iterwrite_largearray.nwb', 'r') as io:
nwbfile = io.read()
data = nwbfile.get_acquisition('synthetic_timeseries').data
# Compare all the data values of our two arrays
data_match = np.all(arrdata == data[:]) # Don't do this for very large arrays!
# Print result message
if data_match:
print("Success: All data values match")
else:
print("ERROR: Mismatch between data")


####################
Expand Down
3 changes: 3 additions & 0 deletions docs/gallery/advanced_io/linking_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
io4.write(nwbfile4,
link_data=True) # <-------- Specify default behavior to link rather than copy data
io4.close()
io1.close()

#####################
# .. note::
Expand Down Expand Up @@ -240,6 +241,8 @@
io3 = NWBHDF5IO(filename3, 'w', manager=manager)
io3.write(nwbfile3)
io3.close()
io1.close()
io2.close()


####################
Expand Down
3 changes: 3 additions & 0 deletions docs/gallery/domain/icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,6 @@
# consisting of acquisition and stimulus, from sweep 1.

series = nwbfile.sweep_table.get_series(1)

# close the file
io.close()
12 changes: 5 additions & 7 deletions docs/gallery/general/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def __init__(self, **kwargs):
# explicitly specify this. This behavior is enabled by the *load_namespaces*
# argument to the :py:class:`~pynwb.NWBHDF5IO` constructor.

io = NWBHDF5IO('cache_spec_example.nwb', mode='r', load_namespaces=True)
nwbfile = io.read()
with NWBHDF5IO('cache_spec_example.nwb', mode='r', load_namespaces=True) as io:
nwbfile = io.read()

####################
# .. _MultiContainerInterface:
Expand Down Expand Up @@ -345,16 +345,14 @@ class PotatoSack(MultiContainerInterface):

load_namespaces(ns_path)
# from xxx import PotatoSack, Potato
io = NWBHDF5IO('test_multicontainerinterface.nwb', 'r')
nwb = io.read()
print(nwb.get_processing_module()['potato_sack'].get_potato('big_potato').weight)
with NWBHDF5IO('test_multicontainerinterface.nwb', 'r') as io:
nwb = io.read()
print(nwb.get_processing_module()['potato_sack'].get_potato('big_potato').weight)
# note: you can call get_processing_module() with or without the module name as
# an argument. however, if there is more than one module, the name is required.
# here, there is more than one potato, so the name of the potato is required as
# an argument to get get_potato

io.close()

####################
# Example: Cortical Surface Mesh
# -----------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions docs/gallery/general/plot_timeintervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@
with NWBHDF5IO('example_timeintervals_file.nwb', 'w') as io:
io.write(nwbfile)
# read the file
io = NWBHDF5IO('example_timeintervals_file.nwb', 'r')
nwbfile_in = io.read()
# plot the sleep stages TimeIntervals table
nwbfile.get_time_intervals('sleep_stages').to_dataframe()
with NWBHDF5IO('example_timeintervals_file.nwb', 'r') as io:
nwbfile_in = io.read()

# plot the sleep stages TimeIntervals table
nwbfile_in.get_time_intervals('sleep_stages').to_dataframe()
5 changes: 5 additions & 0 deletions docs/gallery/general/scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,8 @@
# .. note::
# We recommend writing scratch data into copies of files only. This will make it easier to
# isolate and discard scratch data and avoids updating files that store precious data.

# close the IO objects
raw_io.close()
proc_io.close()
scratch_io.close()
4 changes: 4 additions & 0 deletions docs/source/make_a_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Create a new tutorial
include the prefix ``plot_`` as part of the name of tutorial file. Tutorials
without the prefix will render just the code cells and text.

2. Add the names of any files created by running the python file to the
``files_to_remove`` variable in ``clean_up_tests()`` in ``test.py``. This function
will remove the created output files after the sphinx-gallery tests are completed.

2. **Optional:** To specify an explicit position for your tutorial in the subsection of the
gallery, update the ``GALLERY_ORDER`` variable of the ``CustomSphinxGallerySectionSortKey``
class defined in ``docs/source/conf.py``. If you skip this step, the tutorial will
Expand Down
52 changes: 52 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def get_namespaces(nwbfile):
cmds += [["python", "-m", "pynwb.validate", "--no-cached-namespace", nwb]]

for ns in namespaces:
# for some reason, this logging command is necessary to correctly printing the namespace in the
# next logging command
logging.info("Namespace found: %s" % ns)
cmds += [["python", "-m", "pynwb.validate", "--cached-namespace", "--ns", ns, nwb]]

for cmd in cmds:
Expand Down Expand Up @@ -228,6 +231,51 @@ def run_integration_tests(verbose=True):
run_test_suite("tests/validation", "validation CLI tests", verbose=verbose)


def clean_up_tests():
# remove files generated from running example files
files_to_remove = [
"advanced_io_example.nwb",
"basic_alternative_custom_write.nwb",
"basic_iterwrite_example.nwb",
"basic_sparse_iterwrite_*.nwb",
"basic_sparse_iterwrite_*.npy",
"basics_tutorial.nwb",
"behavioral_tutorial.nwb",
"brain_observatory.nwb",
"cache_spec_example.nwb",
"ecephys_tutorial.nwb",
"ecog.extensions.yaml",
"ecog.namespace.yaml",
"ex_test_icephys_file.nwb",
"example_timeintervals_file.nwb",
"exported_nwbfile.nwb",
"external_linkcontainer_example.nwb",
"external_linkdataset_example.nwb",
"external1_example.nwb",
"external2_example.nwb",
"icephys_example.nwb",
"icephys_pandas_testfile.nwb",
"images_tutorial.nwb",
"manifest.json",
"mylab.extensions.yaml",
"mylab.namespace.yaml",
"nwbfile.nwb",
"ophys_tutorial.nwb",
"processed_data.nwb",
"raw_data.nwb",
"scratch_analysis.nwb",
"test_cortical_surface.nwb",
"test_icephys_file.nwb",
"test_multicontainerinterface.extensions.yaml",
"test_multicontainerinterface.namespace.yaml",
"test_multicontainerinterface.nwb",
]
for f in files_to_remove:
for name in glob.glob(f):
if os.path.exists(name):
os.remove(name)


def main():
# setup and parse arguments
parser = argparse.ArgumentParser('python test.py [options]')
Expand Down Expand Up @@ -303,6 +351,10 @@ def main():
if flags['ros3'] in args.suites:
run_test_suite("tests/integration/ros3", "pynwb ros3 streaming tests", verbose=args.verbosity)

# Delete files generated from running example tests above
if flags['example'] in args.suites or flags['validation'] in args.suites:
clean_up_tests()

final_message = 'Ran %s tests' % TOTAL
exitcode = 0
if ERRORS > 0 or FAILURES > 0:
Expand Down