diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml new file mode 100644 index 0000000..0ab791e --- /dev/null +++ b/.github/workflows/code_coverage.yml @@ -0,0 +1,26 @@ +name: "Code Coverage" + +on: [push, pull_request] + +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install dependencies + run: | + pip install -r requirements.txt + - name: Run pytest with coverage + run: | + pytest --cov=./ --cov-report=xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml + flags: unittests + name: codecov-umbrella + fail_ci_if_error: true \ No newline at end of file diff --git a/.github/workflows/code_security.yml b/.github/workflows/code_security.yml new file mode 100644 index 0000000..da5cdb5 --- /dev/null +++ b/.github/workflows/code_security.yml @@ -0,0 +1,23 @@ +name: "Code Security" + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + schedule: + - cron: '0 5 * * 1' + +jobs: + CodeQL: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: python + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 \ No newline at end of file diff --git a/.github/workflows/code_styling.yml b/.github/workflows/code_styling.yml new file mode 100644 index 0000000..5b79c71 --- /dev/null +++ b/.github/workflows/code_styling.yml @@ -0,0 +1,19 @@ +name: "Code Styling" + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install dependencies + run: | + pip install ruff + - name: Run ruff linter + run: | + ruff check . \ No newline at end of file diff --git a/school_center.py b/school_center.py index ea103ce..a03e859 100644 --- a/school_center.py +++ b/school_center.py @@ -101,17 +101,17 @@ def read_tsv(file_path: str) -> List[Dict[str, str]]: reader = csv.DictReader(file, delimiter='\t') for row in reader: data.append(dict(row)) - except FileNotFoundError: - logger.error(f"File '{file_path}' not found.") + except FileNotFoundError as e: + logger.error(f"File '{file_path} : {e}' not found.") sys.exit(1) - except PermissionError: - logger.error(f"Permission denied while accessing file '{file_path}'.") + except PermissionError as e: + logger.error(f"Permission denied while accessing file '{file_path}' : {e}.") sys.exit(1) - except IOError: - logger.error(f"Error opening or reading file: {file_path}") + except IOError as e: + logger.error(f"Error opening or reading file: '{file_path}' : {e}") sys.exit(1) except Exception as e: - logger.error(f"An unexpected error occurred while reading file '{file_path}': {e}") + logger.error(f"An unexpected error occurred while reading file '{file_path}' : {e}") sys.exit(1) return data @@ -133,14 +133,14 @@ def read_prefs(file_path: str) -> Dict[str, Dict[str, int]]: prefs[row['scode']][row['cscode']] = int(row['pref']) else: prefs[row['scode']] = {row['cscode']: int(row['pref'])} - except FileNotFoundError: - logger.error(f"File '{file_path}' not found.") + except FileNotFoundError as e: + logger.error(f"File '{file_path} :{e}' not found.") sys.exit(1) - except PermissionError: - logger.error(f"Permission denied while accessing file '{file_path}'.") + except PermissionError as e: + logger.error(f"Permission denied while accessing file '{file_path}:{e}'.") sys.exit(1) - except IOError: - logger.error(f"Error opening or reading file: {file_path}") + except IOError as e: + logger.error(f"Error opening or reading file: {file_path} :{e}") sys.exit(1) except Exception as e: logger.error(f"An unexpected error occurred while reading file '{file_path}': {e}")