Writer test is failing on Windows 10
Closed this issue · 2 comments
damian5710 commented
OS: Tested on Windows 10
Reproduction:
- Create a conda environment and install the required packages as stated in the Readme file.
- Run the tests with
mingw32-make test
.
Result:
All but one test are passing and this is the console output:
collected 76 items
mffpy\tests\test_devices.py ........... [ 14%]
mffpy\tests\test_dict2xml.py . [ 15%]
mffpy\tests\test_header_block.py .. [ 18%]
mffpy\tests\test_mffdir.py .... [ 23%]
mffpy\tests\test_raw_bin_files.py ............. [ 40%]
mffpy\tests\test_reader.py .......... [ 53%]
mffpy\tests\test_writer.py ..F [ 57%]
mffpy\tests\test_xml_files.py ........................... [ 93%]
mffpy\tests\test_zipfile.py ..... [100%]
================================== FAILURES ===================================
_____________________________ test_writer_writes ______________________________
def test_writer_writes():
dirname = 'testdir2.mff'
# create some data and add it to a binary writer
device = 'HydroCel GSN 256 1.0'
num_samples = 10
num_channels = 256
sampling_rate = 128
b = BinWriter(sampling_rate=sampling_rate, data_type='EEG')
data = np.random.randn(num_channels, num_samples).astype(np.float32)
b.add_block(data)
# create an mffpy.Writer and add a file info, and the binary file
W = Writer(dirname)
startdatetime = datetime.strptime(
'1984-02-18T14:00:10.000000+0100', XML._time_format)
W.addxml('fileInfo', recordTime=startdatetime)
W.add_coordinates_and_sensor_layout(device)
W.addbin(b)
W.write()
# read it again; compare the result
R = Reader(dirname)
assert R.startdatetime == startdatetime
# Read binary data and compare
read_data = R.get_physical_samples_from_epoch(R.epochs[0])
assert 'EEG' in read_data
read_data, t0 = read_data['EEG']
assert t0 == 0.0
assert read_data == pytest.approx(data)
layout = R.directory.filepointer('sensorLayout')
layout = XML.from_file(layout)
assert layout.name == device
# cleanup
try:
remove(join(dirname, 'info.xml'))
remove(join(dirname, 'info1.xml'))
remove(join(dirname, 'epochs.xml'))
> remove(join(dirname, 'signal1.bin'))
E PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'testdir2.mff\\signal1.bin'
mffpy\tests\test_writer.py:78: PermissionError
During handling of the above exception, another exception occurred:
def test_writer_writes():
dirname = 'testdir2.mff'
# create some data and add it to a binary writer
device = 'HydroCel GSN 256 1.0'
num_samples = 10
num_channels = 256
sampling_rate = 128
b = BinWriter(sampling_rate=sampling_rate, data_type='EEG')
data = np.random.randn(num_channels, num_samples).astype(np.float32)
b.add_block(data)
# create an mffpy.Writer and add a file info, and the binary file
W = Writer(dirname)
startdatetime = datetime.strptime(
'1984-02-18T14:00:10.000000+0100', XML._time_format)
W.addxml('fileInfo', recordTime=startdatetime)
W.add_coordinates_and_sensor_layout(device)
W.addbin(b)
W.write()
# read it again; compare the result
R = Reader(dirname)
assert R.startdatetime == startdatetime
# Read binary data and compare
read_data = R.get_physical_samples_from_epoch(R.epochs[0])
assert 'EEG' in read_data
read_data, t0 = read_data['EEG']
assert t0 == 0.0
assert read_data == pytest.approx(data)
layout = R.directory.filepointer('sensorLayout')
layout = XML.from_file(layout)
assert layout.name == device
# cleanup
try:
remove(join(dirname, 'info.xml'))
remove(join(dirname, 'info1.xml'))
remove(join(dirname, 'epochs.xml'))
remove(join(dirname, 'signal1.bin'))
remove(join(dirname, 'coordinates.xml'))
remove(join(dirname, 'sensorLayout.xml'))
rmdir(dirname)
except BaseException:
raise AssertionError(f"""
> Clean-up failed of '{dirname}'. Were additional files written?""")
E AssertionError:
E Clean-up failed of 'testdir2.mff'. Were additional files written?
mffpy\tests\test_writer.py:84: AssertionError
----------- coverage: platform win32, python 3.6.7-final-0 -----------
Name Stmts Miss Cover
-------------------------------------------------------
mffpy\__init__.py 3 0 100%
mffpy\bin_files.py 40 8 80%
mffpy\bin_writer.py 52 7 87%
mffpy\devices.py 10 0 100%
mffpy\dict2xml.py 31 3 90%
mffpy\epoch.py 23 5 78%
mffpy\header_block.py 49 1 98%
mffpy\mffdir.py 92 18 80%
mffpy\raw_bin_files.py 95 0 100%
mffpy\reader.py 57 2 96%
mffpy\tests\__init__.py 0 0 100%
mffpy\tests\test_devices.py 12 0 100%
mffpy\tests\test_dict2xml.py 15 0 100%
mffpy\tests\test_header_block.py 37 0 100%
mffpy\tests\test_mffdir.py 30 0 100%
mffpy\tests\test_raw_bin_files.py 33 0 100%
mffpy\tests\test_reader.py 26 0 100%
mffpy\tests\test_writer.py 54 3 94%
mffpy\tests\test_xml_files.py 134 1 99%
mffpy\tests\test_zipfile.py 34 0 100%
mffpy\writer.py 51 2 96%
mffpy\xml_files.py 326 8 98%
mffpy\zipfile.py 45 0 100%
-------------------------------------------------------
TOTAL 1249 58 95%
===================== 1 failed, 75 passed in 9.12 seconds =====================
makefile:10: recipe for target 'test' failed
mingw32-make: *** [test] Error 1
Expected:
All tests should be passing with no errors.
ViridianForge commented
In #12 - @damian5710 has submitted code that fixes this issue. As soon as that PR comes in, we'll validate and then close out this bug.
The origin of the problem was specifically that file handles were being treated as a @cached_property
- causing the file pointer to not be relinquished properly upon the conclusion of a test.
Thanks for catching this Damian.
ViridianForge commented
Now that we have merged in #12 - this issue has been resolved. Closing.