-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_gaan.py
107 lines (94 loc) · 3.7 KB
/
test_gaan.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
import unittest
from gaan.gaan import (
sanitize_input,
create_gene_model_identifier,
validate_gene_model_identifier,
create_assembly_identifier
)
class TestGAANFunctions(unittest.TestCase):
def test_sanitize_input(self):
# Test valid input
self.assertEqual(sanitize_input("test123", "field"), "test123")
# Test input with invalid characters
self.assertEqual(sanitize_input("test!@#123", "field"), "test123")
# Test empty input
self.assertEqual(sanitize_input("", "field"), "")
# Test input with spaces
self.assertEqual(sanitize_input(" test input ", "field"), "testinput")
def test_create_gene_model_identifier(self):
# Test with valid prefix, type, and ID
result = create_gene_model_identifier("prefix", "g", 123)
self.assertEqual(result, "prefix.g.000123")
# Test edge-case ID: 0
result = create_gene_model_identifier("prefix", "g", 0)
self.assertEqual(result, "prefix.g.000000")
# Test maximum ID number
result = create_gene_model_identifier("prefix", "g", 999999)
self.assertEqual(result, "prefix.g.999999")
def test_create_assembly_identifier(self):
# Test assembly identifier WITHOUT the optional field
result = create_assembly_identifier(
tol_id="TOL123",
sample_identifier="SAMPLE1",
consortium="GRP",
version=1,
subversion=0
)
self.assertEqual(result, "TOL123.SAMPLE1.GRP.1.0.fasta")
# Test assembly identifier WITH the optional field
result_with_optional = create_assembly_identifier(
tol_id="TOL123",
sample_identifier="SAMPLE1",
consortium="GRP",
version=1,
subversion=0,
optional="EXTRA"
)
self.assertEqual(result_with_optional, "TOL123.SAMPLE1.GRP.1.0.EXTRA.fasta")
# Test input sanitization
result_sanitized = create_assembly_identifier(
tol_id="TOL!@#123",
sample_identifier="SAM!@#PLE1",
consortium="GRP",
version=2,
subversion=1
)
self.assertEqual(result_sanitized, "TOL123.SAMPLE1.GRP.2.1.fasta")
# Test empty optional field
result_empty_optional = create_assembly_identifier(
tol_id="TOL123",
sample_identifier="SAMPLE1",
consortium="GRP",
version=3,
subversion=2,
optional=""
)
self.assertEqual(result_empty_optional, "TOL123.SAMPLE1.GRP.3.2.fasta")
def test_create_assembly_identifier_invalid(self):
# Test invalid version (not a number)
with self.assertRaises(ValueError):
create_assembly_identifier(
tol_id="TOL123",
sample_identifier="SAMPLE1",
consortium="GRP",
version="invalid",
subversion=0
)
# Test invalid subversion (not a number)
with self.assertRaises(ValueError):
create_assembly_identifier(
tol_id="TOL123",
sample_identifier="SAMPLE1",
consortium="GRP",
version=1,
subversion="invalid"
)
def test_validate_gene_model_identifier(self):
# Test valid gene model identifier
valid_id = "assemblyprefix.g.000123"
self.assertTrue(validate_gene_model_identifier(valid_id))
# Test invalid gene model identifier
invalid_id = "assemblyprefix.invalid.123"
self.assertFalse(validate_gene_model_identifier(invalid_id))
if __name__ == "__main__":
unittest.main()