Skip to content

Commit 4fe0630

Browse files
committed
Added cli tests and a base class for tests.
1 parent a16a6fb commit 4fe0630

File tree

6 files changed

+229
-185
lines changed

6 files changed

+229
-185
lines changed

tests/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import json
2+
import unittest
3+
4+
FORMAT_STR = "\n--- Expected ---\n%s\n--- Actual ---\n%s\n---\n"
5+
6+
class BaseTest(unittest.TestCase):
7+
"""
8+
A base class for tests.
9+
"""
10+
11+
def assertListEqual(self, a, b):
12+
a_json = json.dumps(a, indent = 4)
13+
b_json = json.dumps(b, indent = 4)
14+
15+
super().assertListEqual(a, b, FORMAT_STR % (a_json, b_json))
16+
17+
def assertDictEqual(self, a, b):
18+
a_json = json.dumps(a, indent = 4)
19+
b_json = json.dumps(b, indent = 4)
20+
21+
super().assertDictEqual(a, b, FORMAT_STR % (a_json, b_json))

tests/cli/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _load_allowed_arg_keys(self, module_name):
107107

108108
def _prepare_string(text, temp_dir):
109109
replacements = [
110-
(tests.server.base.DATA_DIR_ID, DATA_DIR),
110+
(tests.server.base.DATA_DIR_ID, os.path.abspath(DATA_DIR)),
111111
(TEMP_DIR_ID, temp_dir),
112112
]
113113

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"cli": "autograder.cli.config.list",
3+
"arguments": [
4+
"--config", "__DATA_DIR__(configs/simple/autograder.json)",
5+
"--global-config", "__DATA_DIR__(configs/empty)"
6+
]
7+
}
8+
---
9+
user: user@test.edulinq.org
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"cli": "autograder.cli.config.list",
3+
"arguments": [
4+
"--config", "__DATA_DIR__(configs/simple/autograder.json)",
5+
"--global-config", "__DATA_DIR__(configs/empty)",
6+
"--show-origin"
7+
]
8+
}
9+
---
10+
__DATA_DIR__(configs/simple/autograder.json) user: user@test.edulinq.org

tests/server/base.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import json
21
import os
3-
import unittest
42
import re
53

64
import autograder.error
75
import tests.server.server
6+
import tests.base
87

98
SERVER_URL_FORMAT = "http://127.0.0.1:%s"
109
FORMAT_STR = "\n--- Expected ---\n%s\n--- Actual ---\n%s\n---\n"
1110

1211
DATA_DIR_ID = tests.server.server.DATA_DIR_ID
1312

14-
class ServerBaseTest(unittest.TestCase):
13+
class ServerBaseTest(tests.base.BaseTest):
1514
"""
1615
A base tests that need to call the mock server.
1716
"""
@@ -42,18 +41,6 @@ def tearDownClass(cls):
4241
def get_base_arguments(self):
4342
return ServerBaseTest._base_arguments.copy()
4443

45-
def assertDictEqual(self, a, b):
46-
a_json = json.dumps(a, indent = 4)
47-
b_json = json.dumps(b, indent = 4)
48-
49-
super().assertDictEqual(a, b, FORMAT_STR % (a_json, b_json))
50-
51-
def assertListEqual(self, a, b):
52-
a_json = json.dumps(a, indent = 4)
53-
b_json = json.dumps(b, indent = 4)
54-
55-
super().assertListEqual(a, b, FORMAT_STR % (a_json, b_json))
56-
5744
def replace_path(text, key, base_dir):
5845
match = re.search(r'%s\(([^)]*)\)' % (key), text)
5946
if (match is not None):

0 commit comments

Comments
 (0)