-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_data_cleaning.py
88 lines (71 loc) · 3.76 KB
/
test_data_cleaning.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
87
88
import unittest
import Cleaning.data_cleaning as data_cleaning
class TestDataCleaning(unittest.TestCase):
def test_correct_formatted_date_to_datetime(self):
the_date = "May 16, 2019"
date_not_found = True
date_not_found, new_datetime = data_cleaning.convert_date(the_date)
correct_datetime = data_cleaning.datetime.datetime(2019, 5, 16)
self.assertEqual(correct_datetime, new_datetime)
self.assertFalse(date_not_found)
def test_correct_formatted_date2_to_datetime(self):
the_date = "Jan 06, 2019"
date_not_found = True
date_not_found, new_datetime = data_cleaning.convert_date(the_date)
correct_datetime = data_cleaning.datetime.datetime(2019, 1, 6)
self.assertEqual(correct_datetime, new_datetime)
self.assertFalse(date_not_found)
def test_incorrect_formatted_date_to_datetime(self):
the_date = "16 May 2019"
date_not_found = True
date_not_found, new_datetime = data_cleaning.convert_date(the_date)
correct_datetime = None
self.assertEqual(correct_datetime, new_datetime)
self.assertTrue(date_not_found)
def test_incorrect_formatted_date2_to_datetime(self):
the_date = "May 2019"
date_not_found = True
date_not_found, new_datetime = data_cleaning.convert_date(the_date)
correct_datetime = None
self.assertEqual(correct_datetime, new_datetime)
self.assertTrue(date_not_found)
##############################################################################################
### ###
### Retrieve tweet message ###
##############################################################################################
def test_retrieve_tweet_message(self):
tweet_msg = "Hello, world!\n"
look_f_msg, retrieved_msg = data_cleaning.retrieve_msg(tweet_msg)
self.assertEqual("Hello, world!", retrieved_msg)
self.assertFalse(look_f_msg)
def test_retrieve_tweet2_message(self):
tweet_msg = "Hello, world!"
look_f_msg, retrieved_msg = data_cleaning.retrieve_msg(tweet_msg)
self.assertEqual("Hello, world!", retrieved_msg)
self.assertFalse(look_f_msg)
##############################################################################################
### ###
### Retrieve tweet's author ###
##############################################################################################
def test_retrieve_tweets_author(self):
tweet_aut = "@MsabalaSibonelo\n"
look_f_aut, retrieved_aut = data_cleaning.retrieve_aut(tweet_aut)
self.assertEqual("@MsabalaSibonelo", retrieved_aut)
self.assertFalse(look_f_aut)
def test_retrieve_tweet2_author(self):
tweet_aut = "@MsabalaSibonelo"
look_f_aut, retrieved_aut = data_cleaning.retrieve_msg(tweet_aut)
self.assertEqual("@MsabalaSibonelo", retrieved_aut)
self.assertFalse(look_f_aut)
def test_retrieve_tweets_author_incorrect(self):
tweet_aut = "MsabalaSibonelo\n"
look_f_aut, retrieved_aut = data_cleaning.retrieve_aut(tweet_aut)
self.assertEqual(None, retrieved_aut)
self.assertTrue(look_f_aut)
def test_retrieve_tweet2_author_incorrect(self):
tweet_aut = "123MsabalaSibonelo"
look_f_aut, retrieved_aut = data_cleaning.retrieve_aut(tweet_aut)
self.assertEqual(None, retrieved_aut)
self.assertTrue(look_f_aut)
if __name__ == '__main__':
unittest.main()