@@ -37,5 +37,37 @@ def test_invalid_date_format(self):
37
37
with self .assertRaises (ValueError ):
38
38
parse_whatsapp_chat (BytesIO (chat_data ))
39
39
40
+ def test_24_hour_format (self ):
41
+ chat_data = b"[23/05/2024 21:44:49] Alice: Good evening!\n [23/05/2024 08:30:15] Bob: Good morning!"
42
+ df = parse_whatsapp_chat (BytesIO (chat_data ))
43
+ self .assertEqual (len (df ), 2 )
44
+ self .assertEqual (df .iloc [0 ]['Sender' ], 'Alice' )
45
+ self .assertEqual (df .iloc [1 ]['Sender' ], 'Bob' )
46
+
47
+ #not expected; but just in case
48
+ def test_mixed_formats (self ):
49
+ chat_data = b"[12/01/23, 03:45:12 p.m.] John: Hello!\n [23/05/2024 21:44:49] Jane: How's it going?"
50
+ df = parse_whatsapp_chat (BytesIO (chat_data ))
51
+ self .assertEqual (len (df ), 2 )
52
+ self .assertEqual (df .iloc [0 ]['Sender' ], 'John' )
53
+ self .assertEqual (df .iloc [1 ]['Sender' ], 'Jane' )
54
+
55
+ def test_omitted_media_multiple_entries (self ):
56
+ chat_data = b"[12/01/23, 03:45:12 p.m.] John: audio omitted\n [12/01/23, 03:46:12 p.m.] Jane: image omitted\n [12/01/23, 03:47:12 p.m.] John: How are you?"
57
+ df = parse_whatsapp_chat (BytesIO (chat_data ))
58
+ self .assertEqual (len (df ), 1 ) # Two messages should be skipped
59
+ self .assertEqual (df .iloc [0 ]['Sender' ], 'John' )
60
+ self .assertEqual (df .iloc [0 ]['Message' ], 'How are you?' )
61
+
62
+ def test_case_with_empty_file (self ):
63
+ chat_data = b""
64
+ df = parse_whatsapp_chat (BytesIO (chat_data ))
65
+ self .assertEqual (len (df ), 0 ) # DataFrame should be empty
66
+
67
+ def test_case_with_only_media_omitted (self ):
68
+ chat_data = b"[12/01/23, 03:45:12 p.m.] John: audio omitted\n [12/01/23, 03:46:12 p.m.] Jane: video omitted"
69
+ df = parse_whatsapp_chat (BytesIO (chat_data ))
70
+ self .assertEqual (len (df ), 0 ) # DataFrame should be empty as both messages are media omitted
71
+
40
72
if __name__ == '__main__' :
41
73
unittest .main ()
0 commit comments