| 1 | # This file is part of audioread. |
| 2 | # Copyright 2018, Sam Thursfield |
| 3 | # |
| 4 | # Permission is hereby granted, free of charge, to any person obtaining |
| 5 | # a copy of this software and associated documentation files (the |
| 6 | # "Software"), to deal in the Software without restriction, including |
| 7 | # without limitation the rights to use, copy, modify, merge, publish, |
| 8 | # distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | # permit persons to whom the Software is furnished to do so, subject to |
| 10 | # the following conditions: |
| 11 | # |
| 12 | # The above copyright notice and this permission notice shall be |
| 13 | # included in all copies or substantial portions of the Software. |
| 14 | |
| 15 | |
| 16 | import audioread |
| 17 | |
| 18 | |
| 19 | # The 'audiofile' fixture is defined in conftest.py. |
| 20 | |
| 21 | |
| 22 | def test_audioread_early_exit(audiofile): |
| 23 | """Abort the read before it is completed. |
| 24 | |
| 25 | This test guards against regressions such as |
| 26 | https://github.com/beetbox/audioread/pull/78 |
| 27 | |
| 28 | """ |
| 29 | with audioread.audio_open(audiofile.path) as a: |
| 30 | assert int(a.duration) == int(audiofile.duration) |
| 31 | assert a.channels == audiofile.channels |
| 32 | assert a.samplerate == audiofile.samplerate |
| 33 | # Now we exit the context manager without reading any data. |
| 34 | |
| 35 | |
| 36 | def test_audioread_full(audiofile): |
| 37 | """Read the audio data from the file.""" |
| 38 | with audioread.audio_open(audiofile.path) as a: |
| 39 | assert int(a.duration) == int(audiofile.duration) |
| 40 | assert a.channels == audiofile.channels |
| 41 | assert a.samplerate == audiofile.samplerate |
| 42 | |
| 43 | # Now read all the data and assert that it's the correct type. |
| 44 | for block in a: |
| 45 | assert type(block) == bytes |