Skip to content

Commit

Permalink
chore: init examples CI test action
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlinjui committed Aug 13, 2024
1 parent ae3a427 commit d6ee438
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 32 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Examples Test
on:
push:
branches:
- main
- '*.x'
paths-ignore:
- '*.md'
pull_request:
paths-ignore:
- '*.md'
jobs:
local-test:
name: Local-Ubuntu20.04-Python${{ matrix.python }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- {python: '3.12'}
- {python: '3.11'}
- {python: '3.10'}
- {python: '3.9'}
- {python: '3.8'}
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Install GCC and Make
run: |
sudo apt-get update
sudo apt-get install -y build-essential
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --with dev
- name: Run Examples Test
run: poetry run pytest -vs -n auto

container-test:
name: GCC Docker Container
runs-on: ubuntu-latest
container:
image: gcc:latest
volumes:
- ${{ github.workspace }}:/app
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4

- name: Install dependencies
run: |
apt-get update
apt-get install -y python3-pip
python3 -m pip install --upgrade pip --break-system-packages
pip install poetry --break-system-packages
poetry install --with dev
- name: Run Examples Test
run: poetry run pytest -vs -n auto
15 changes: 0 additions & 15 deletions requirements.txt

This file was deleted.

7 changes: 4 additions & 3 deletions src/cpGrader/cpGrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import objprint
from typing import (
List,
Callable
Callable,
Union
)

import toml
Expand All @@ -29,7 +30,7 @@
class Grader:
def __init__(
self,
config_file: str | None = DEFAULT_CONFIG_FILE
config_file: Union[str, None] = DEFAULT_CONFIG_FILE
):
self.grade_report: List[List[str]] = []

Expand Down Expand Up @@ -84,7 +85,7 @@ def __read_config(self, config_file: str) -> None:

def setcase(
self,
match_case: str | List[str] = ALL_MATCH_CASE
match_case: Union[str, List[str]] = ALL_MATCH_CASE
) -> Callable:

def wrapper(func: Callable) -> None:
Expand Down
25 changes: 13 additions & 12 deletions src/cpGrader/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from inspect import currentframe
from typing import (
List,
Callable
Callable,
Union
)

from .utils import (
Expand All @@ -22,18 +23,18 @@ class Case:
def __init__(
self,
name: str,
case_file: str | None,
command: str | None,
pts: int | float,
correct_file: str | None,
verify_func: Callable | None
case_file: Union[str, None],
command: Union[str, None],
pts: Union[int, float],
correct_file: Union[str, None],
verify_func: Union[Callable, None]
):
self.name: str = name
self.case_file: str | None = case_file
self.command: str | None = command
self.pts: int | float = pts
self.correct_file: str | None = correct_file
self.verify_func: Callable | None = verify_func
self.case_file: Union[str, None] = case_file
self.command: Union[str, None] = command
self.pts: Union[int, float] = pts
self.correct_file: Union[str, None] = correct_file
self.verify_func: Union[Callable, None] = verify_func

self.case_data: List[str] = []
self.student_output: str = ""
Expand Down Expand Up @@ -94,7 +95,7 @@ def __correct_setup(self) -> None:
with open(output_filepath, "w+") as f:
f.write(self.correct_output)

def execute(self, student_dir: str) -> ExecuteException | None:
def execute(self, student_dir: str) -> Union[None, ExecuteException]:
# setup case data and build/execute correct file
if self.case_file != None:
self.case_data = [line.strip() for line in open(self.case_file, "r").readlines()]
Expand Down
5 changes: 3 additions & 2 deletions src/cpGrader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import zipfile
from typing import (
List,
Tuple
Tuple,
Union
)

import pexpect
Expand Down Expand Up @@ -166,7 +167,7 @@ def execute(folder:str, command:str, stdin_list:list=[]) -> str:
return output

def grade(
grade_report: List[Tuple[str, List[int | float], List[str]]],
grade_report: List[Tuple[str, List[Union[int, str]], List[str]]],
save_path: str
) -> None:

Expand Down

0 comments on commit d6ee438

Please sign in to comment.