-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
59 lines (45 loc) · 2.94 KB
/
test.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
import unittest
from csv_to_sql.csv_to_sql import format_sql_row
from csv_to_sql.csv_to_sql import escape_sql_characters
class TestFormatFunctions(unittest.TestCase):
def test_escape_sql_characters(self):
# Test case 1: Normal case
assert escape_sql_characters("Claire O'Connell") == "Claire O\\'Connell"
# Test case 2: Special characters
assert escape_sql_characters("Claire O\"Connell") == "Claire O\\\"Connell"
assert escape_sql_characters("Claire O/Connell") == "Claire O\\/Connell"
assert escape_sql_characters("Claire O%Connell") == "Claire O\\%Connell"
assert escape_sql_characters("Claire O_Connell") == "Claire O\\_Connell"
# Test case 3: NULL, TRUE, FALSE values
assert escape_sql_characters("NULL") == "NULL"
assert escape_sql_characters("null") == "null"
assert escape_sql_characters("TRUE") == "TRUE"
assert escape_sql_characters("true") == "true"
assert escape_sql_characters("FALSE") == "FALSE"
assert escape_sql_characters("false") == "false"
# Test case 4: Empty string
assert escape_sql_characters("") == ""
# Test case 5: String with only spaces
assert escape_sql_characters(" ") == " "
def test_format_sql_row(self):
# Test case 1: Normal case
assert format_sql_row(["52", "Rice", "20.7", "TRUE"]) == ["52", "E'Rice'", "20.7", "TRUE"]
# Test case 2: Special characters
assert format_sql_row(["52", "Ri'ce", "20.7", "TRUE"]) == ["52", r"E'Ri\'ce'", "20.7", "TRUE"]
assert format_sql_row(["52", "Ri\"ce", "20.7", "TRUE"]) == ["52", "E'Ri\\\"ce'", "20.7", "TRUE"]
assert format_sql_row(["52", "Ri/ce", "20.7", "TRUE"]) == ["52", r"E'Ri\/ce'", "20.7", "TRUE"]
assert format_sql_row(["52", "Ri%ce", "20.7", "TRUE"]) == ["52", r"E'Ri\%ce'", "20.7", "TRUE"]
assert format_sql_row(["52", "Ri_ce", "20.7", "TRUE"]) == ["52", r"E'Ri\_ce'", "20.7", "TRUE"]
# Test case 3: NULL, TRUE, FALSE values
assert format_sql_row(["52", "NULL", "20.7", "TRUE"]) == ["52", "NULL", "20.7", "TRUE"]
assert format_sql_row(["52", "null", "20.7", "TRUE"]) == ["52", "NULL", "20.7", "TRUE"]
assert format_sql_row(["52", "TRUE", "20.7", "TRUE"]) == ["52", "TRUE", "20.7", "TRUE"]
assert format_sql_row(["52", "true", "20.7", "TRUE"]) == ["52", "TRUE", "20.7", "TRUE"]
assert format_sql_row(["52", "FALSE", "20.7", "TRUE"]) == ["52", "FALSE", "20.7", "TRUE"]
assert format_sql_row(["52", "false", "20.7", "TRUE"]) == ["52", "FALSE", "20.7", "TRUE"]
# Test case 4: Empty string
assert format_sql_row(["52", "", "20.7", "TRUE"]) == ["52", "E''", "20.7", "TRUE"]
# Test case 5: String with only spaces
assert format_sql_row(["52", " ", "20.7", "TRUE"]) == ["52", "E' '", "20.7", "TRUE"]
if __name__ == "__main__":
unittest.main()