Skip to content

Commit

Permalink
Add tests for repo_assess_files_exist plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofachada committed Mar 7, 2024
1 parent 3c0181a commit e988420
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
21 changes: 20 additions & 1 deletion tests/plugins/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def git_repo(tmp_path, monkeypatch):

@pytest.fixture()
def make_commit(monkeypatch):
"""Fixture to make a simple commit."""
"""Returns a function to make simple commits."""
now: datetime = datetime.now()

def _make_commit(
Expand All @@ -44,3 +44,22 @@ def _make_commit(
git_at(repo, "commit", "-m", f'"{commit_msg}"', f"--date={dt}")

return _make_commit


@pytest.fixture(
params=[
(
"file.txt",
"main.c",
".gitignore",
"file with spaces",
"Makefile",
"two_extensions.md.html",
"UPPERCASE ~ ! lower case.MD",
),
("script.py", "another_script.py", "Documentation.html"),
]
)
def file_list(request):
"""Provides a list of file names."""
return request.param
35 changes: 34 additions & 1 deletion tests/plugins/test_repo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""Tests for repository plug-ins."""

from datetime import datetime, timedelta
from pathlib import Path

import numpy as np
import pytest

from egrader.plugins.repo import assess_commit_date_interval, assess_min_commits
from egrader.plugins.repo import (
assess_commit_date_interval,
assess_files_exist,
assess_min_commits,
)
from egrader.types import StudentGit


Expand Down Expand Up @@ -128,3 +133,31 @@ def test_repo_assess_commit_date_interval_none(git_repo, make_commit, strict):
)

assert grade == 0


@pytest.mark.parametrize("strict", [False, True])
@pytest.mark.parametrize("percent", [0, 0.3, 0.7, 1])
def test_repo_assess_files_exist_ok(tmp_path, file_list, strict, percent):
"""Test if the percentage of files in a repository is correct."""
# Number of files to create
num_files_to_create = round(percent * len(file_list))

# Create files
for i in range(num_files_to_create):
file_path = Path(tmp_path, file_list[i])
with open(file_path, "w"):
pass

# Empty student just for testing
stdgit = StudentGit("", "", "")

# Invoke plugin
grade = assess_files_exist(stdgit, tmp_path, file_list, strict)

if strict and percent < 1:
assert grade == 0
else:
np.testing.assert_allclose(
grade,
num_files_to_create / len(file_list),
)

0 comments on commit e988420

Please sign in to comment.