-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_iust_ai_toolkit.py
146 lines (125 loc) · 5.84 KB
/
test_iust_ai_toolkit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import unittest
from iust_ai_toolkit import course_module
# class TestBaseAuthenticator(unittest.TestCase):
# def setUp(self):
# self.authenticator = BaseAuthenticator(base_dir="./test_dir")
# self.notebook_path = "./test_notebook.ipynb"
# self.predictions = [0.1, 0.2, 0.3]
# # Create a sample notebook for testing
# with open(self.notebook_path, "w") as f:
# json.dump(
# {
# "cells": [
# {
# "cell_type": "code",
# "source": [
# "# Estimation: a: 1.0\n",
# "def test_func():\n",
# " pass\n",
# ],
# },
# {
# "cell_type": "code",
# "source": [
# "# Estimation: b: 2.0\n",
# "def another_func():\n",
# " pass\n",
# ],
# },
# ]
# },
# f,
# )
# def test_encode_notebook(self):
# encoded_data = self.authenticator.encode_notebook(self.notebook_path)
# self.assertIn("encoded_cells", encoded_data)
# self.assertIn("implemented_methods", encoded_data)
# self.assertIn("estimations", encoded_data)
# self.assertEqual(len(encoded_data["encoded_cells"]), 2)
# self.assertEqual(len(encoded_data["implemented_methods"]), 2)
# def test_create_submission_csv(self):
# self.authenticator.create_submission_csv(self.predictions)
# self.assertTrue(os.path.exists("./submission.csv"))
# class TestDecisionTreeSubmission(unittest.TestCase):
# def setUp(self):
# self.submission = DecisionTreeSubmission(base_dir="./test_submission_dir")
# self.student_id = "student_1"
# self.notebook_path = "./test_notebook.ipynb"
# # Create a sample notebook for testing
# with open(self.notebook_path, "w") as f:
# json.dump(
# {
# "cells": [
# {
# "cell_type": "code",
# "source": [
# "# Estimation: a: 1.0\n",
# "def test_func():\n",
# " pass\n",
# ],
# },
# {
# "cell_type": "code",
# "source": [
# "# Estimation: b: 2.0\n",
# "def another_func():\n",
# " pass\n",
# ],
# },
# ]
# },
# f,
# )
# def tearDown(self):
# # Clean up test files
# if os.path.exists(self.notebook_path):
# os.remove(self.notebook_path)
# if os.path.exists(self.submission.base_dir):
# for filename in os.listdir(self.submission.base_dir):
# file_path = os.path.join(self.submission.base_dir, filename)
# if os.path.isfile(file_path):
# os.remove(file_path)
# os.rmdir(self.submission.base_dir)
# def test_create_submission_zip(self):
# self.submission.create_submission_zip(self.student_id, self.notebook_path)
# zip_path = os.path.join(
# self.submission.base_dir,
# f"{os.path.basename(self.notebook_path)}_{self.student_id}-decision_tree.zip",
# )
# self.assertTrue(os.path.exists(zip_path))
# def test_compare_submissions(self):
# # Create another submission for comparison
# self.submission.create_submission_zip("student_2", self.notebook_path)
# result, verbose_result = self.submission.compare_submissions(self.student_id, "student_2")
# self.assertIsInstance(result, float)
# self.assertIsInstance(verbose_result, dict)
# def test_analyze_all_submissions(self):
# # Create multiple submissions for analysis
# self.submission.create_submission_zip("student_2", self.notebook_path)
# self.submission.create_submission_zip("student_3", self.notebook_path)
# submissions = [
# f"{self.student_id}-decision_tree_submission.zip",
# "student_2-decision_tree_submission.zip",
# "student_3-decision_tree_submission.zip",
# ]
# results, verbose_results, ignore_cheating = self.submission.analyze_all_submissions(
# submissions
# )
# self.assertIsInstance(results, list)
# self.assertIsInstance(verbose_results, dict)
# self.assertIsInstance(ignore_cheating, bool)
# # Check if the results contain the expected number of comparisons
# self.assertEqual(len(results), 3) # 3 comparisons for 3 submissions
class TestCourseModule(unittest.TestCase):
def test_course_module_import(self):
"""Test dynamic import of the decision_tree_submission module."""
module = course_module("abdi_4031.decision_tree_submission")
# Check if the module has the submit_notebook function
self.assertTrue(hasattr(module, "submit_notebook"))
# Optionally, you can test if the function works as expected
# Here, you would need to set up a mock or a test case for submit_notebook
# For example:
# result = module.submit_notebook("test_student_id", "./test_notebook.ipynb")
# self.assertIsNotNone(result) # Adjust based on expected behavior
if __name__ == "__main__":
unittest.main()