From 348963d403ae63c74ecb4d18b2cf4b2f6649f56d Mon Sep 17 00:00:00 2001 From: Christian Brickhouse Date: Mon, 11 Jul 2022 16:38:33 -0700 Subject: [PATCH 1/3] Add basic python package CI workflow --- .github/workflows/build.yml | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..dac1cdf --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: fave + +on: + push: + branches: [ $default-branch ] + pull_request: + branches: [ $default-branch, "dev" ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From 77be18dd22b9f8b262d3dc9bf0f0a90edb4836b1 Mon Sep 17 00:00:00 2001 From: Christian Brickhouse Date: Mon, 11 Jul 2022 18:16:15 -0700 Subject: [PATCH 2/3] Add basic tests for TranscriptProcessor --- tests/fave/align/test_transcriptprocessor.py | 71 ++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/fave/align/test_transcriptprocessor.py diff --git a/tests/fave/align/test_transcriptprocessor.py b/tests/fave/align/test_transcriptprocessor.py new file mode 100644 index 0000000..8854167 --- /dev/null +++ b/tests/fave/align/test_transcriptprocessor.py @@ -0,0 +1,71 @@ +import pytest +from fave.align import transcriptprocessor + +def test_replace_smart_quotes(): + def test_func( testcase ): + return transcriptprocessor.TranscriptProcessor.replace_smart_quotes(testcase) + for test in provide_replace_smart_quotes(): + testcase = test[0] + expected = test[1] + assert test_func(testcase) == expected + +def provide_replace_smart_quotes(): + return [ + [[u'\u2018'], ["'"]], + [[u'\u2019'], ["'"]], + [[u'\u201a'], ["'"]], + [[u'\u201b'], ["'"]], + [[u'\u201c'], ['"']], + [[u'\u201d'], ['"']], + [[u'\u201e'], ['"']], + [[u'\u201f'], ['"']], + [[u'\u2018foo'], ["'foo"]], + [[u'foo\u2019'], ["foo'"]], + [[u'\u201afoo'], ["'foo"]], + [[u'foo\u201b'], ["foo'"]], + [[u'\u201cfoo'], ['"foo']], + [[u'foo\u201d'], ['foo"']], + [[u'\u201efoo'], ['"foo']], + [[u'foo\u201f'], ['foo"']], + [ + [ u'\u2018', u'\u2019', u'\u201a', u'\u201b', u'\u201c', u'\u201d', u'\u201e', u'\u201f' ], + ["'","'","'","'",'"','"','"','"'] + ] + ] + +def test_check_transcription_format_output(): + def test_func( testcase ): + return transcriptprocessor.TranscriptProcessor.check_transcription_format(testcase) + for test in provide_check_transcription_format_output(): + testcase = test[0] + expected = test[1] + assert test_func(testcase) == expected + +def provide_check_transcription_format_output(): + return [ + [ '', ( None, '' ) ], # Empty line should return None and original line + [ ' '*6, ( None, ' '*6 ) ], # Line of only whitespace should return None and the original line + [ ' \n ', (None, ' \n ') ], # Test mixed whitespace lines + [ 'a\tb\tc\td\te', (['a','b','c','d','e'], None) ], # Split tsv into entries, return toople of entries and None + [ 'a\tb\tc\td\te\n', (['a','b','c','d','e'], None) ], # Trailing newline should be ignored + [ 'a\tb\tc\td\te\t\t\t', (['a','b','c','d','e'], None) ], # Remove trailing tabs THEN split + ] + +def test_check_transcription_format_raises_value_error(): + def test_func( testcase ): + return transcriptprocessor.TranscriptProcessor.check_transcription_format(testcase) + for test in provide_check_transcription_format_raises_value_error(): + testcase = test[0] + expected_error = test[1] + with pytest.raises(expected_error): + test_func(testcase) + +def provide_check_transcription_format_raises_value_error(): + return [ + [ 'a', ValueError ], # 1 entry + [ 'a\tb', ValueError ], # 2 entries + [ 'a\tb\tc', ValueError], # 3 entries + [ 'a\tb\tc\td', ValueError], # 4 entries + # Skip 5 entries (not an error) + [ 'a\tb\tc\td\te\tf', ValueError], # 6 entries + ] From 6adfde3bb8186ae98e3b9a9c16b1890e77e64bf7 Mon Sep 17 00:00:00 2001 From: Christian Brickhouse Date: Tue, 12 Jul 2022 13:41:59 -0700 Subject: [PATCH 3/3] Set to run on this branch --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dac1cdf..9ae180c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ name: fave on: push: - branches: [ $default-branch ] + branches: [ $default-branch, "workflows" ] pull_request: branches: [ $default-branch, "dev" ]