Skip to content

Commit

Permalink
Update badges and support coverage
Browse files Browse the repository at this point in the history
This change also modifies the unit tests so that they can be run from any directory.
  • Loading branch information
chummersone committed Aug 19, 2022
1 parent 7fa6916 commit 91e8308
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 24 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install flake8 pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
Expand All @@ -38,6 +38,15 @@ jobs:
run: |
python -m pip install -e .
- name: Test with pytest
working-directory: ./tests
run: |
pytest
coverage run -m pytest
- name: Get coverage
if: ${{ matrix.python-version == '3.10' }}
run: |
coverage lcov --omit="*/tests/*"
- name: Coveralls
if: ${{ matrix.python-version == '3.10' }}
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.lcov
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
![python-package](https://github.com/chummersone/pywavfile/actions/workflows/python-package.yml/badge.svg)
![python-publish](https://github.com/chummersone/pywavfile/actions/workflows/python-publish.yml/badge.svg)
[![PyPI version](https://badge.fury.io/py/wavfile.svg)](https://pypi.org/project/wavfile/)
![GitHub Workflow Status (event)](https://img.shields.io/github/workflow/status/chummersone/pywavfile/wavfile%20CI?event=push)
![Coveralls](https://img.shields.io/coveralls/github/chummersone/pywavfile)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/chummersone/pywavfile)
![PyPI](https://img.shields.io/pypi/v/wavfile)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/wavfile)

# wavfile

Expand Down
16 changes: 10 additions & 6 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import wavfile


def test_file_path(*args):
return os.path.join(os.path.dirname(os.path.realpath(__file__)), *args)


class TestCaseWithFile(unittest.TestCase):

def assertIsFile(self, path):
Expand All @@ -21,16 +25,16 @@ def assertIsFile(self, path):
class TestModule(TestCaseWithFile):

def test_write_error(self):
self.assertRaises(wavfile.WriteError, wavfile.open, 'junk.wav', 'w', fmt=b'junk')
self.assertRaises(wavfile.WriteError, wavfile.open, test_file_path('junk.wav'), 'w', fmt=b'junk')

def test_mode_error(self):
self.assertRaises(wavfile.Error, wavfile.open, 'junk.wav', 'j')
self.assertRaises(wavfile.Error, wavfile.open, test_file_path('junk.wav'), 'j')

def test_read_error(self):
self.assertRaises(wavfile.Error, wavfile.read, 'osc_tri.wav', fmt='junk')
self.assertRaises(wavfile.Error, wavfile.read, test_file_path('osc_tri.wav'), fmt='junk')

def test_split(self):
wavfile.split('test-file-3.wav')
wavfile.split(test_file_path('test-file-3.wav'))
filenames = [
'test-file-3_00.wav',
'test-file-3_01.wav',
Expand All @@ -39,5 +43,5 @@ def test_split(self):
'test-file-3_04.wav'
]
for f in filenames:
self.assertIsFile(f)
os.remove(f)
self.assertIsFile(test_file_path(f))
os.remove(test_file_path(f))
4 changes: 3 additions & 1 deletion tests/test_wavfile_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

import wavfile

from test_module import test_file_path


class TestWavReadCopy(unittest.TestCase):

filename = "test-file-1.wav"
filename = test_file_path("test-file-1.wav")

def test_basic_copy(self):
with wavfile.open(self.filename) as wfp:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_wavfile_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

import wavfile

from test_module import test_file_path


class TestWavfileFloat(unittest.TestCase):

def run_test(self, audio_data_in, read_callback, sample_rate,
bits_per_sample, num_channels, reference=None):
filename = "tmp.wav"
filename = test_file_path("tmp.wav")
with wavfile.open(filename, 'w',
sample_rate=sample_rate,
bits_per_sample=bits_per_sample,
Expand Down Expand Up @@ -157,7 +159,7 @@ def test_invalid_bitdepth(self):
[-0.1],
[-0.3],
]
with wavfile.open('tmp.wav', 'w',
with wavfile.open(test_file_path('tmp.wav'), 'w',
sample_rate=44100,
bits_per_sample=24,
fmt=wavfile.chunk.WavFormat.IEEE_FLOAT,
Expand Down
12 changes: 7 additions & 5 deletions tests/test_wavfile_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

import wavfile

from test_module import test_file_path


class TestWavfileRead(unittest.TestCase):

filename = "osc_tri.wav"
filename_unsigned = "osc_tri_unsigned.wav"
filename = test_file_path("osc_tri.wav")
filename_unsigned = test_file_path("osc_tri_unsigned.wav")

def test_file_open_filename(self):
wfp = wavfile.open(self.filename)
Expand Down Expand Up @@ -203,21 +205,21 @@ def test_shortcut_read(self):
self.assertEqual(1, len(audio_data[0]))

def test_read_test_file_1(self):
audio_data, fs, bits_per_sample = wavfile.read('test-file-1.wav')
audio_data, fs, bits_per_sample = wavfile.read(test_file_path('test-file-1.wav'))
self.assertEqual(44100, fs)
self.assertEqual(24, bits_per_sample)
self.assertEqual(44100 * 4, len(audio_data))
self.assertEqual(2, len(audio_data[0]))

def test_read_test_file_2(self):
audio_data, fs, bits_per_sample = wavfile.read('test-file-2.wav')
audio_data, fs, bits_per_sample = wavfile.read(test_file_path('test-file-2.wav'))
self.assertEqual(96000, fs)
self.assertEqual(32, bits_per_sample)
self.assertEqual(96000, len(audio_data))
self.assertEqual(1, len(audio_data[0]))

def test_read_test_file_3(self):
audio_data, fs, bits_per_sample = wavfile.read('test-file-3.wav')
audio_data, fs, bits_per_sample = wavfile.read(test_file_path('test-file-3.wav'))
self.assertEqual(48000, fs)
self.assertEqual(24, bits_per_sample)
self.assertEqual(48000, len(audio_data))
Expand Down
10 changes: 6 additions & 4 deletions tests/test_wavfile_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

import wavfile

from test_module import test_file_path


class TestWavfileWrite(unittest.TestCase):

def run_test(self, audio_data_in, read_callback, sample_rate,
bits_per_sample, num_channels, reference=None):
filename = "tmp.wav"
filename = test_file_path("tmp.wav")
with wavfile.open(filename, 'w',
sample_rate=sample_rate,
bits_per_sample=bits_per_sample,
Expand Down Expand Up @@ -222,7 +224,7 @@ def test_incorrect_channel_count(self):
self.assertRaises(wavfile.Error, wfp.write, [[0]])

def test_write_after_close(self):
filename = "tmp.wav"
filename = test_file_path("tmp.wav")
with wavfile.open(filename, 'w',
sample_rate=44100,
bits_per_sample=16,
Expand All @@ -231,7 +233,7 @@ def test_write_after_close(self):
self.assertRaises(ValueError, wfp.write, [[0, 0]])

def test_shortcut_write(self):
filename = "tmp.wav"
filename = test_file_path("tmp.wav")
audio_data_in = [
[0],
[256],
Expand All @@ -251,7 +253,7 @@ def test_shortcut_write(self):
self.assertListEqual(audio_data_in, audio_data_out)

def test_before_write(self):
filename = "tmp.wav"
filename = test_file_path("tmp.wav")
with wavfile.open(filename, 'w',
sample_rate=44100,
bits_per_sample=16) as wfp:
Expand Down

0 comments on commit 91e8308

Please sign in to comment.