Test reading, writing and slicing of raw classes. Parameters ---------- reader : function Function to test. test_preloading : bool Whether not preloading is implemented for the reader. If True, both cases and memory mapping to file are tested. test_kwargs
(
reader,
test_preloading=True,
test_kwargs=True,
boundary_decimal=2,
test_scaling=True,
test_rank=True,
**kwargs,
)
| 100 | |
| 101 | |
| 102 | def _test_raw_reader( |
| 103 | reader, |
| 104 | test_preloading=True, |
| 105 | test_kwargs=True, |
| 106 | boundary_decimal=2, |
| 107 | test_scaling=True, |
| 108 | test_rank=True, |
| 109 | **kwargs, |
| 110 | ): |
| 111 | """Test reading, writing and slicing of raw classes. |
| 112 | |
| 113 | Parameters |
| 114 | ---------- |
| 115 | reader : function |
| 116 | Function to test. |
| 117 | test_preloading : bool |
| 118 | Whether not preloading is implemented for the reader. If True, both |
| 119 | cases and memory mapping to file are tested. |
| 120 | test_kwargs : dict |
| 121 | Test _init_kwargs support. |
| 122 | boundary_decimal : int |
| 123 | Number of decimals up to which the boundary should match. |
| 124 | **kwargs : |
| 125 | Arguments for the reader. Note: Do not use preload as kwarg. |
| 126 | Use ``test_preloading`` instead. |
| 127 | |
| 128 | Returns |
| 129 | ------- |
| 130 | raw : instance of Raw |
| 131 | A preloaded Raw object. |
| 132 | """ |
| 133 | tempdir = _TempDir() |
| 134 | rng = np.random.RandomState(0) |
| 135 | montage = None |
| 136 | if "montage" in kwargs: |
| 137 | montage = kwargs["montage"] |
| 138 | del kwargs["montage"] |
| 139 | if test_preloading: |
| 140 | raw = reader(preload=True, **kwargs) |
| 141 | rep = repr(raw) |
| 142 | assert rep.count("<") == 1 |
| 143 | assert rep.count(">") == 1 |
| 144 | if montage is not None: |
| 145 | raw.set_montage(montage) |
| 146 | # don't assume the first is preloaded |
| 147 | buffer_fname = op.join(tempdir, "buffer") |
| 148 | picks = rng.permutation(np.arange(len(raw.ch_names) - 1))[:10] |
| 149 | picks = np.append(picks, len(raw.ch_names) - 1) # test trigger channel |
| 150 | bnd = min(int(round(raw.buffer_size_sec * raw.info["sfreq"])), raw.n_times) |
| 151 | slices = [ |
| 152 | slice(0, bnd), |
| 153 | slice(bnd - 1, bnd), |
| 154 | slice(3, bnd), |
| 155 | slice(3, 300), |
| 156 | slice(None), |
| 157 | slice(1, bnd), |
| 158 | ] |
| 159 | if raw.n_times >= 2 * bnd: # at least two complete blocks |
no test coverage detected