diff --git a/tests/plugins/conftest.py b/tests/plugins/conftest.py index b806547..d5c9ec8 100644 --- a/tests/plugins/conftest.py +++ b/tests/plugins/conftest.py @@ -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( @@ -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 diff --git a/tests/plugins/test_repo.py b/tests/plugins/test_repo.py index 07e9358..47c764a 100644 --- a/tests/plugins/test_repo.py +++ b/tests/plugins/test_repo.py @@ -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 @@ -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), + )