forked from rdale-dev/csv-to-xml-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_tests.diff
More file actions
64 lines (56 loc) · 2.7 KB
/
patch_tests.diff
File metadata and controls
64 lines (56 loc) · 2.7 KB
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
--- tests/test_data_cleaning.py
+++ tests/test_data_cleaning.py
@@ -6,7 +6,7 @@
# Add the project root to the Python path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
-from src.data_cleaning import format_date, standardize_state_name, map_value
+from src.data_cleaning import format_date, standardize_state_name, map_value, clean_percentage
class TestFormatDate(unittest.TestCase):
@@ -165,34 +165,29 @@
with self.subTest(value=value):
self.assertEqual(standardize_country_code(value), expected)
-if __name__ == '__main__':
- unittest.main()
-
class TestCleanPercentage(unittest.TestCase):
def test_clean_percentage_valid_strings(self):
- from src.data_cleaning import clean_percentage
self.assertEqual(clean_percentage("50"), "50")
self.assertEqual(clean_percentage("50%"), "50")
self.assertEqual(clean_percentage("0.5"), "0.5")
self.assertEqual(clean_percentage(" 0.5% "), "0.5")
self.assertEqual(clean_percentage("100"), "100")
self.assertEqual(clean_percentage("100%"), "100")
def test_clean_percentage_valid_numbers(self):
- from src.data_cleaning import clean_percentage
self.assertEqual(clean_percentage(50), "50")
self.assertEqual(clean_percentage(0.5), "0.5")
self.assertEqual(clean_percentage(100), "100")
self.assertEqual(clean_percentage(100.0), "100")
self.assertEqual(clean_percentage(0), "0")
def test_clean_percentage_empty_and_none(self):
- from src.data_cleaning import clean_percentage
self.assertEqual(clean_percentage(""), "0")
self.assertEqual(clean_percentage(None), "0")
self.assertEqual(clean_percentage(" "), "0")
self.assertEqual(clean_percentage("nan"), "0")
self.assertEqual(clean_percentage("NaN"), "0")
def test_clean_percentage_out_of_bounds(self):
- from src.data_cleaning import clean_percentage
self.assertEqual(clean_percentage("-10"), "0")
self.assertEqual(clean_percentage("-10%"), "0")
self.assertEqual(clean_percentage("-0.5"), "0")
self.assertEqual(clean_percentage("150"), "100")
self.assertEqual(clean_percentage("150%"), "100")
self.assertEqual(clean_percentage(150), "100")
def test_clean_percentage_invalid_strings(self):
- from src.data_cleaning import clean_percentage
with self.assertRaises(ValueError):
clean_percentage("abc")
with self.assertRaises(ValueError):
clean_percentage("50 percent")
with self.assertRaises(ValueError):
clean_percentage("10.5.5")
+
+if __name__ == '__main__':
+ unittest.main()