-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_data_validation.py
79 lines (64 loc) · 2.66 KB
/
test_data_validation.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
import unittest
from data_validation import validate_json, validate_file_path, validate_language, validate_content, validate_analysis, validate_metadata, validate_data
class TestDataValidation(unittest.TestCase):
def test_validate_json(self):
# Test case 1: Valid JSON
valid_json = {
"file_path": "example.py",
"language": "python",
"content": "print('Hello, World!')",
"analysis": {},
"metadata": {"size": 24}
}
self.assertTrue(validate_json(valid_json))
# Test case 2: Invalid JSON (missing required fields)
invalid_json = {
"file_path": "example.py",
"language": "python",
"content": "print('Hello, World!')"
}
self.assertFalse(validate_json(invalid_json))
def test_validate_file_path(self):
# Test case 1: Valid file path
self.assertTrue(validate_file_path("example.py"))
# Test case 2: Empty file path
self.assertFalse(validate_file_path(""))
def test_validate_language(self):
# Test case 1: Valid language
self.assertTrue(validate_language("python"))
# Test case 2: Invalid language
self.assertFalse(validate_language("invalid_language"))
def test_validate_content(self):
# Test case 1: Valid content
self.assertTrue(validate_content("print('Hello, World!')"))
# Test case 2: Empty content
self.assertFalse(validate_content(""))
def test_validate_analysis(self):
# Test case 1: Valid analysis
self.assertTrue(validate_analysis({"entities": []}))
# Test case 2: Empty analysis
self.assertTrue(validate_analysis({}))
def test_validate_metadata(self):
# Test case 1: Valid metadata
self.assertTrue(validate_metadata({"size": 24}))
# Test case 2: Missing size in metadata
self.assertFalse(validate_metadata({"md5_hash": "abcdef"}))
def test_validate_data(self):
# Test case 1: Valid data
valid_data = {
"file_path": "example.py",
"language": "python",
"content": "print('Hello, World!')",
"analysis": {},
"metadata": {"size": 24}
}
self.assertTrue(validate_data(valid_data))
# Test case 2: Invalid data (missing required fields)
invalid_data = {
"file_path": "example.py",
"language": "python",
"content": "print('Hello, World!')"
}
self.assertFalse(validate_data(invalid_data))
if __name__ == '__main__':
unittest.main()