Adding Test Data

There are a few different way to add test data to dascore. The key, however, is to ensure test files and generated patches are small (a few mb at most) so the documentation and test suite still run quickly.

Adding functions which create example data

The examples module contains several functions for creating example Patch and Spool instances. You can add a new function in that module which creates a new patch or spool, then just register the function so it can be called from dc.get_example_patch or dc.get_example_spool. These should be simple objects which can be generated within python. If you need to download a file see adding a data file.

Note

All example functions should have either no arguments or keyword arguments with default values.

# Register an example patch function
@register_func(EXAMPLE_PATCHES, key="new_das_patch")
def create_example_patch(argument_1='default_value'):
    ...

# Register an example spool function
@register_func(EXAMPLE_SPOOLS, key="new_das_spool")
def create_example_spool(another_value=None):
    ...

The new example patches/spools can then be created via

import dascore as dc

patch_example = dc.get_example_patch("new_das_patch", argument_1="bob")

spool_example = dc.get_example_spool("new_das_spool")

If, in the test code, the example patch or spool is used only once, just call the get_example function in the test. If it is needed multiple times, consider putting it in a fixture. See testing for more on fixtures.

Adding a data file

Of course, not all data can easily be generated in python. For example, testing support for new file formats typically requires a test file.

If you have a small file that isn’t already hosted on a permanent site, you can put it into dasdae’s data repo. Simply clone the repo, add you file format, and push back to master or open a PR on a separate branch and someone will merge it in.

Next, add your file to dascore’s data registry (dascore/data_registry.txt). You will have to get the sha256 hash of your test file, for that you can simply use Pooch’s hash_file function, and you can create the proper download url using the other entries as examples.

The name, hash, and url might look something like this:

jingle_test_file.jgl
12e087d2c1cd08c9afd18334e17e21787be0b646151b39802541ee11a516976a
https://github.com/dasdae/test_data/raw/master/das/jingle_test_file.jgl
from dascore.utils.downloader import fetch
path = fetch("jingle_test_file.jgl")