Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit 8ef846c

Browse files
committed
make unittest_runner package
1 parent 3f59b8b commit 8ef846c

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ The current patches are:
1010
- We patch `requests` in order to route requests through code.org's request proxy. This protects students
1111
by only allowing requests to an allow-list of urls.
1212

13-
All Python Lab programs are prefixed with `setup_pythonlab()`, the method this package exposes, which applies
14-
the above patches.
13+
All Python Lab programs are prefixed with `setup_pythonlab()`, the method this package exposes, which only applies
14+
the matplotlib patch for now.
1515

1616
## Setup
1717
- Install `pyenv`.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "unittest_runner"
7+
version = "0.0.1"
8+
dependencies = ["unittest"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .run_tests import run_student_tests, run_validation_tests
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import unittest
2+
from .validation_runner import ValidationTestResult
3+
4+
def run_validation_tests(file_pattern):
5+
run_tests(file_pattern, ValidationTestResult)
6+
7+
def run_student_tests(file_pattern):
8+
run_tests(file_pattern, unittest.TextTestResult)
9+
10+
def run_tests(file_pattern, resultclass):
11+
loader = unittest.TestLoader()
12+
test_suite = loader.discover('.', file_pattern)
13+
runner = unittest.TextTestRunner(verbosity=2, resultclass=resultclass)
14+
result = runner.run(test_suite)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
from unittest import TextTestResult
3+
4+
class ValidationTestResult(TextTestResult):
5+
# The default behavior is to display the test name and short description.
6+
# We want to display only the short description if it exists, otherwise just the test name.
7+
# Students don't see the tests, so we don't need to display the test name.
8+
def getDescription(self, test):
9+
doc_first_line = test.shortDescription()
10+
if doc_first_line:
11+
return doc_first_line
12+
else:
13+
return str(test)

0 commit comments

Comments
 (0)