-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_clincnv2vcf.py
86 lines (64 loc) · 3 KB
/
test_clincnv2vcf.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
import tempfile
import pandas as pd
import pytest
from clincnv2vcf import clean_info, get_DELDUP_by_CN, parse_metadata
def test_parse_metadata() -> None:
# Test case 1: file with no metadata
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
f.write("This is a test file with no metadata.\n")
file_path = f.name
assert parse_metadata(file_path) == ([], {})
# Test case 2: file with metadata but no key-value pairs
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
f.write("## This is a test file with metadata but no key-value pairs.\n")
f.write("##\n")
f.write("## More metadata with no key-value pairs.\n")
file_path = f.name
assert parse_metadata(file_path) == ([0, 1, 2], {})
# Test case 3: file with metadata and key-value pairs
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
f.write("## This is a test file with metadata and key-value pairs.\n")
f.write("## Key1: Value1\n")
f.write("## Key2: Value2\n")
file_path = f.name
assert parse_metadata(file_path) == (
[0, 1, 2],
{"Key1": "Value1", "Key2": "Value2"},
)
def test_get_DELDUP_by_CN_normal() -> None:
assert get_DELDUP_by_CN(0) == "DEL"
assert get_DELDUP_by_CN(0, ltgt=True) == "<DEL>"
assert get_DELDUP_by_CN(4) == "DUP"
assert get_DELDUP_by_CN(4, ltgt=True) == "<DUP>"
assert get_DELDUP_by_CN(100) == "DUP"
assert get_DELDUP_by_CN(100, ltgt=True) == "<DUP>"
assert get_DELDUP_by_CN(3, male_x=True) == "DUP"
assert get_DELDUP_by_CN(3, ltgt=True, male_x=True) == "<DUP>"
assert get_DELDUP_by_CN(100, male_x=True) == "DUP"
assert get_DELDUP_by_CN(100, ltgt=True, male_x=True) == "<DUP>"
def test_get_DELDUP_by_CN_edge_cases() -> None:
assert get_DELDUP_by_CN(0, male_x=True) == "DEL"
assert get_DELDUP_by_CN(0, ltgt=True, male_x=True) == "<DEL>"
assert get_DELDUP_by_CN(1, male_x=True) == "."
assert get_DELDUP_by_CN(1, ltgt=True, male_x=True) == "."
assert get_DELDUP_by_CN(2, male_x=True) == "DUP"
assert get_DELDUP_by_CN(2, ltgt=True, male_x=True) == "<DUP>"
assert get_DELDUP_by_CN(1) == "DEL"
assert get_DELDUP_by_CN(1, ltgt=True) == "<DEL>"
assert get_DELDUP_by_CN(2) == "."
assert get_DELDUP_by_CN(2, ltgt=True) == "."
assert get_DELDUP_by_CN(3) == "DUP"
assert get_DELDUP_by_CN(3, ltgt=True) == "<DUP>"
def test_get_DELDUP_by_CN_error() -> None:
with pytest.raises(TypeError):
get_DELDUP_by_CN(None) # type: ignore
def test_clean_info_with_none() -> None:
assert clean_info(None) == "." # type: ignore
def test_clean_info_with_nan() -> None:
assert clean_info(pd.NA) == "." # type: ignore
def test_clean_info_with_alphanumeric_chars() -> None:
assert clean_info("abc123") == "abc123"
def test_clean_info_with_special_chars() -> None:
assert clean_info("a#b$c%d^") == "a_b_c_d_"
def test_clean_info_with_mixed_chars() -> None:
assert clean_info("a#b123$c45%d^") == "a_b123_c45_d_"