From 7a1219d9219ce12c0c46f91cf036775ad66b9030 Mon Sep 17 00:00:00 2001 From: Nathaniel Handan <87228776+Tinny-Robot@users.noreply.github.com> Date: Wed, 30 Oct 2024 05:55:48 +0000 Subject: [PATCH] Refactor Pylint workflow and update configuration - Refactor the Pylint workflow to include Python versions 3.9, 3.10, and 3.11. - Update the Pylint configuration to disable the E0015 check. Resolves: #issue-number --- .github/workflows/pylint.yml | 11 +++++++++-- .pylintrc | 3 ++- core/__init__.py | 2 +- core/audio_processing.py | 7 ++++++- core/utils.py | 7 +++++++ core/video_processing.py | 8 +++++++- tests/test_audio_processing.py | 8 ++++++-- tests/test_utils.py | 17 ++++++++++++++--- tests/test_video_processing.py | 6 ++++++ 9 files changed, 58 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 60cc1a9..1eb2067 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -26,5 +26,12 @@ jobs: python -m pip install --upgrade pip pip install pylint - name: Run pylint + id: pylint run: | - pylint --rcfile=.pylintrc $(git ls-files '*.py') + pylint --rcfile=.pylintrc $(git ls-files '*.py') > pylint_output.txt || true + score=$(tail -n 2 pylint_output.txt | head -n 1 | grep -oP '\d+\.\d+') + echo "Pylint score: $score" + if (( $(echo "$score < 8" | bc -l) )); then + echo "Pylint score is less than 8. Failing the job." + exit 1 + fi diff --git a/.pylintrc b/.pylintrc index 9fbabfe..c79f765 100644 --- a/.pylintrc +++ b/.pylintrc @@ -438,7 +438,8 @@ disable=raw-checker-failed, deprecated-pragma, use-symbolic-message-instead, use-implicit-booleaness-not-comparison-to-string, - use-implicit-booleaness-not-comparison-to-zero + use-implicit-booleaness-not-comparison-to-zero, + E0015 # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/core/__init__.py b/core/__init__.py index 49fe5b4..9c27181 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1 +1 @@ -# Initialization for the main core module \ No newline at end of file +# Initialization for the main core module diff --git a/core/audio_processing.py b/core/audio_processing.py index 0bd1727..5638e2f 100644 --- a/core/audio_processing.py +++ b/core/audio_processing.py @@ -1,3 +1,8 @@ +'''This module provides functionality to extract audio from video files. + +Functions: + extract_audio(video_path, output_audio_path):''' + from moviepy.editor import VideoFileClip def extract_audio(video_path, output_audio_path): @@ -16,5 +21,5 @@ def extract_audio(video_path, output_audio_path): audio.write_audiofile(output_audio_path) audio.close() video.close() - + return output_audio_path diff --git a/core/utils.py b/core/utils.py index 91994f0..ba0f420 100644 --- a/core/utils.py +++ b/core/utils.py @@ -1,3 +1,10 @@ +""" +This module provides utility functions. + +Functions: + check_file_exists(file_path): Checks if a file exists at the given file path. +""" + import os def check_file_exists(file_path): diff --git a/core/video_processing.py b/core/video_processing.py index 3b62682..1344a78 100644 --- a/core/video_processing.py +++ b/core/video_processing.py @@ -1,3 +1,10 @@ +""" +This module contains functions for processing videos. + +Functions: + resize_video(video_path, output_video_path, width, height): +""" + from moviepy.editor import VideoFileClip def resize_video(video_path, output_video_path, width, height): @@ -18,5 +25,4 @@ def resize_video(video_path, output_video_path, width, height): resized_video.write_videofile(output_video_path) resized_video.close() video.close() - return output_video_path diff --git a/tests/test_audio_processing.py b/tests/test_audio_processing.py index 9bb0437..8aa3a1b 100644 --- a/tests/test_audio_processing.py +++ b/tests/test_audio_processing.py @@ -1,23 +1,27 @@ +'''Test cases for the audio processing functions.''' + import unittest import os from core.audio_processing import extract_audio class TestAudioProcessing(unittest.TestCase): - + '''Test cases for the audio processing functions.''' def setUp(self): # Paths to test files (replace these with actual test paths as needed) self.video_path = "tests/files/test_video.mp4" self.output_audio_path = "tests/files/test_audio.mp3" def test_extract_audio(self): + '''Test the extract_audio function.''' # Run the extract_audio function and capture the returned path result_path = extract_audio(self.video_path, self.output_audio_path) - + # Check if the returned path is correct and if the file was created self.assertEqual(result_path, self.output_audio_path) self.assertTrue(os.path.exists(result_path)) def tearDown(self): + '''Clean up the test files after tests.''' # Cleanup test files if os.path.exists(self.output_audio_path): os.remove(self.output_audio_path) diff --git a/tests/test_utils.py b/tests/test_utils.py index 682de88..8b0b9db 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,21 +1,32 @@ +''' +This module contains the test cases for the utility functions. +''' + import unittest import os from core.utils import check_file_exists class TestUtils(unittest.TestCase): + """Test cases for the utility functions. + + Functions: + test_check_file_exists(self): Test the check_file_exists function. + """ def setUp(self): self.existing_file = "tests/files/existing_file.txt" self.non_existing_file = "tests/files/non_existing_file.txt" - + # Create a dummy file for testing - with open(self.existing_file, 'w') as f: + with open(self.existing_file, 'w', encoding='utf-8') as f: f.write("Test content") def test_check_file_exists(self): + """ + Test the check_file_exists function.""" # Test with an existing file self.assertTrue(check_file_exists(self.existing_file)) - + # Test with a non-existing file self.assertFalse(check_file_exists(self.non_existing_file)) diff --git a/tests/test_video_processing.py b/tests/test_video_processing.py index e5741b2..8945e61 100644 --- a/tests/test_video_processing.py +++ b/tests/test_video_processing.py @@ -1,8 +1,13 @@ +''' +This file contains the unit tests for the video_processing module. +''' + import unittest import os from core.video_processing import resize_video class TestVideoProcessing(unittest.TestCase): + '''Test cases for the video processing functions.''' def setUp(self): self.video_path = "tests/files/test_video.mp4" @@ -11,6 +16,7 @@ def setUp(self): self.height = 360 def test_resize_video(self): + '''Test the resize_video function.''' result_path = resize_video(self.video_path, self.output_video_path, self.width, self.height) self.assertEqual(result_path, self.output_video_path) self.assertTrue(os.path.exists(result_path))