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

TST: Fix UnboundLocalError: local variable 'data' referenced before assignment on Windows #7068

Merged
merged 1 commit into from Feb 17, 2017

Conversation

cgohlke
Copy link
Contributor

@cgohlke cgohlke commented Feb 17, 2017

Fixes one test error reported at #7055

======================================================================
ERROR: test_wavfile.test_read_early_eof
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27-x64\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "X:\Python27-x64\lib\site-packages\scipy\io\tests\test_wavfile.py", line 91, in test_read_early_eof
    assert_raises(ValueError, wavfile.read, fp, mmap=mmap)
  File "X:\Python27-x64\lib\site-packages\numpy\testing\utils.py", line 1142, in assert_raises
    return nose.tools.assert_raises(*args,**kwargs)
  File "X:\Python27-x64\lib\unittest\case.py", line 473, in assertRaises
    callableObj(*args, **kwargs)
  File "X:\Python27-x64\lib\site-packages\scipy\io\wavfile.py", line 281, in read
    return fs, data
UnboundLocalError: local variable 'data' referenced before assignment

@mp4096
Copy link
Contributor

mp4096 commented Feb 17, 2017

Cool, thank you! Would've taken me a lot of time to find this bug.

Actually, maybe it would make sense to rewrite these three tests as follows:

def test_read_fail():
    filename = datafile('example_1.nc')
    for mmap in [False, True]:
        assert_raises(ValueError, wavfile.read, filename, mmap=mmap)


def test_read_early_eof():
    filename = datafile('test-44100Hz-le-1ch-4bytes-early-eof.wav')
    for mmap in [False, True]:
        assert_raises(ValueError, wavfile.read, filename, mmap=mmap)


def test_read_incomplete_chunk():
    filename = datafile('test-44100Hz-le-1ch-4bytes-incomplete-chunk.wav')
    for mmap in [False, True]:
        assert_raises(ValueError, wavfile.read, filename, mmap=mmap)

Seems to work properly on my Linux machine.

Rationale: As I've just realised, mmap is overridden if wavfile.read is given a file handle instead of a filename.

@ev-br ev-br added backport-candidate This fix should be ported by a maintainer to previous SciPy versions. scipy.io labels Feb 17, 2017
@ev-br ev-br added this to the 0.19.0 milestone Feb 17, 2017
@ev-br ev-br merged commit d97c6a8 into scipy:maintenance/0.19.x Feb 17, 2017
@ev-br
Copy link
Member

ev-br commented Feb 17, 2017

Thanks Christoph!

@mp4096 it probably should test it both ways. I merged this PR as a hotfix, a follow-up PR against master would be welcome, I'd say.

ev-br pushed a commit to ev-br/scipy that referenced this pull request Feb 23, 2017
@ev-br ev-br removed the backport-candidate This fix should be ported by a maintainer to previous SciPy versions. label Feb 23, 2017
@ev-br
Copy link
Member

ev-br commented Feb 23, 2017

forward ported in gh-7085

evanlimanto pushed a commit to evanlimanto/scipy that referenced this pull request Mar 17, 2017
evanlimanto pushed a commit to evanlimanto/scipy that referenced this pull request Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants