forked from thanhleviet/sample_sheet_validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests_app.py
51 lines (46 loc) · 1.97 KB
/
tests_app.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
import io
import pandas as pd
from app import replace_special_characters, remove_unicode, columns_to_title_case, process_data
def test_replace_special_characters():
# Test that multiple special characters are replaced with a single hyphen
input_text = "PID-1453-LCP21S3-B1@!$%"
expected_output = "PID-1453-LCP21S3-B1-"
assert replace_special_characters(input_text) == expected_output
# Test that multiple hyphens are replaced with a single hyphen
input_text = "PID-1453-LCP21S3-B1---"
expected_output = "PID-1453-LCP21S3-B1-"
assert replace_special_characters(input_text) == expected_output
# Test that multiple underscores are replaced with a single underscore
input_text = "PID_1453_LCP21S3_B1___"
expected_output = "PID-1453-LCP21S3-B1-"
assert replace_special_characters(input_text) == expected_output
def test_remove_unicode():
# Test that Unicode characters are removed from a DataFrame
input_data = pd.DataFrame({
"Sample_Id": ["PID-1453-LCP21S3-B1", "\\U0001F600"],
"Index": ["TAACTTGGTC", "CGTAGAACAG"],
"Index2": ["GATTCACGAC", "\\U0001F600"],
"Sample_Project": ["A", "B"]
})
expected_output = pd.DataFrame({
"Sample_Id": ["PID-1453-LCP21S3-B1", ""],
"Index": ["TAACTTGGTC", "CGTAGAACAG"],
"Index2": ["GATTCACGAC", ""],
"Sample_Project": ["A", "B"]
})
assert remove_unicode(input_data).equals(expected_output)
def test_columns_to_title_case():
# Test that column names are converted to title case format
input_data = pd.DataFrame({
"Sample_Id": ["PID-1453-LCP21S3-B1"],
"index": ["TAACTTGGTC"],
"index2": ["GATTCACGAC"],
"Sample_Project": ["A"]
})
expected_output = pd.DataFrame({
"Sample_Id": ["PID-1453-LCP21S3-B1"],
"Index": ["TAACTTGGTC"],
"Index2": ["GATTCACGAC"],
"Sample_Project": ["A"]
})
assert columns_to_title_case(input_data).equals(expected_output)