Skip to content

Commit 6d29b9e

Browse files
[Testing:Developer] Rework test suite to use pytest (#11)
Co-authored-by: William Allen <[email protected]>
1 parent d3dc844 commit 6d29b9e

15 files changed

+91
-83
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test/data/**/* -linguist-detectable
1+
tests/fixtures/**/* -linguist-detectable

.github/workflows/test.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- name: Build executable
1414
run: bash ./build.sh
15+
- name: install dev dependencies
16+
run: python3 -m pip install -r requirements_dev.txt
1517
- name: run tests
16-
run: python3 testRunner.py
18+
run: pytest

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
include/
22
build/
3+
__pycache__/

requirements_dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest

testRunner.py

-30
This file was deleted.

testSuite/commands.json

-51
This file was deleted.

tests/__init__.py

Whitespace-only changes.

tests/fixtures/commands.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"🔥.py": [
3+
["call", "print", 1],
4+
["node", "for", 2],
5+
["node", "continue", 1],
6+
["node", "break", 1],
7+
["node", "if", 1],
8+
["node", "elif", 1]
9+
],
10+
"max.c": [
11+
["identifier", "num1", 5],
12+
["call", "max", 1],
13+
["call", "printf", 1],
14+
["node", "return", 3],
15+
["node", "if", 1],
16+
["node", "else", 1],
17+
["function", "max", 1]
18+
],
19+
"solution.cpp": [
20+
["call", "cout", 1],
21+
["call", "erase", 1],
22+
["call", "begin", 1],
23+
["identifier", "numbers", 4]
24+
],
25+
"solution.py": [
26+
["call", "print", 2],
27+
["call", "age", 1],
28+
["function", "age", 1],
29+
["call", "dog", 1],
30+
["node", "class", 1],
31+
["identifier", "dog", 6]
32+
],
33+
"oop.java": [
34+
["node", "interface", 1],
35+
["node", "abstract", 1],
36+
["node", "extends", 1],
37+
["function", "sound", 2],
38+
["call", "println", 2],
39+
["call", "sound", 1],
40+
["identifier", "Dog", 3]
41+
],
42+
"fibonacci.java": [
43+
["node", "if", 1],
44+
["node", "for", 1],
45+
["node", "+", 4],
46+
["function", "printFibonacci", 1],
47+
["call", "print", 2],
48+
["identifier", "fibonacci", 2],
49+
["identifier", "Fibonacci", 4]
50+
]
51+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test_integration.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from pathlib import Path
2+
import subprocess
3+
import json
4+
import pytest
5+
from typing import Dict, List, Tuple
6+
7+
this_dir = Path(__file__).parent.resolve()
8+
fixtures_dir = this_dir / 'fixtures'
9+
exe_path = this_dir / '..' / 'build' / 'submitty_count_ts'
10+
11+
def execute_command(file: str, countable: str, feature: str) -> int:
12+
args = [str(exe_path), '-l', file.split('.')[-1], countable, feature, str(this_dir / 'fixtures' / file)]
13+
print(args)
14+
result = subprocess.run(args, capture_output=True)
15+
output = result.stdout.decode().strip("\n")
16+
print(output)
17+
if not output.isnumeric():
18+
raise Exception("Result is not numeric")
19+
return int(output)
20+
21+
22+
with (this_dir / 'fixtures' / 'commands.json').open() as file:
23+
commands: Dict[str, List[Tuple[str, int]]] = json.load(file)
24+
25+
testcases = []
26+
27+
file: str
28+
for file in commands:
29+
for test in commands[file]:
30+
testcases.append([file, test[0], test[1], test[2]])
31+
32+
@pytest.mark.parametrize("file, countable, feature, expected_output", testcases)
33+
def test_integration(file, countable, feature, expected_output):
34+
assert expected_output == execute_command(file, countable, feature)

0 commit comments

Comments
 (0)