forked from Lunettenoires/retweet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
executable file
·109 lines (99 loc) · 5.06 KB
/
tests.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-
# Copyright © 2015 Carl Chenet <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## Unit tests for Retweet
'''Unit tests for Retweet '''
import datetime
import sys
import unittest
from retweet.cliparse import CliParse
from retweet.confparse import ConfParse
from retweet.waitamoment import WaitAMoment
class TestRetweet(unittest.TestCase):
'''TestRetweet class'''
def test_getconfigvars(self):
'''Test the ConfParse class'''
confp = ConfParse('tests/getconfigvars/retweet.ini')
self.assertEqual(confp.confvalues, {'user_to_retweet': 'journalduhacker',
'consumer_key': '4s3nOBU7hUkPrTqeWzw6lxzC3',
'consumer_secret': 'aoWjhD7UQcXfxipa2ufkypqiUle9cF0ZlaOngiOAiJyFb23Ftb',
'access_token': '1370158707-m8eN2YcfVcKGfWmVLERDGMd1UPKHVPzAQHoP7qa',
'access_token_secret': 'aB74LfWy551sRTU49buGE6YXIukY74TmBK6JLECeOA5ta',
'retweets': 0,
'waitminsecs': 2,
'waitmaxsecs': 3,
'sqlitepath': '/var/lib/retweet/retweet.db',
'dontretweethashes': ['dnr'],
'onlyifhashtags': ['python'],
'match_regex': '[Rr]egex',
'youngerthan': 180,
'olderthan': 60,
'like': False
})
def test_getconfigvarsnodnr(self):
'''Test the ConfParse class'''
confp = ConfParse('tests/getconfigvars/retweet-nodnr.ini')
self.assertEqual(confp.confvalues, {'user_to_retweet': 'journalduhacker',
'consumer_key': '4s3nOBU7hUkPrTqeWzw6lxzC3',
'consumer_secret': 'aoWjhD7UQcXfxipa2ufkypqiUle9cF0ZlaOngiOAiJyFb23Ftb',
'access_token': '1370158707-m8eN2YcfVcKGfWmVLERDGMd1UPKHVPzAQHoP7qa',
'access_token_secret': 'aB74LfWy551sRTU49buGE6YXIukY74TmBK6JLECeOA5ta',
'retweets': 0,
'waitminsecs': 2,
'waitmaxsecs': 3,
'sqlitepath': '/var/lib/retweet/retweet.db',
'dontretweethashes': [],
'match_regex': '',
'youngerthan': 0,
'olderthan': 0,
'onlyifhashtags': [],
'like': False
})
def test_waitamoment(self):
'''Test WaitAMoment class'''
before = datetime.datetime.now()
wam = WaitAMoment(1,2)
after = datetime.datetime.now()
res = after - before
self.assertTrue(res.seconds >= 1)
#######################################################################################
#
# Testing the consistent given version of the software both in setup.py and cliparse.py
#
#######################################################################################
def test_versionconsistency(self):
'''test the consistency of the version of the software
in both setup.py and README.MD
'''
with open('setup.py') as setuppy:
setuppycode = setuppy.readlines()
with open('README.md') as readme:
readmecode = readme.readlines()
for line in setuppycode:
if 'version=' in line:
setuppyversion = line.split("'")[1]
break
for line in readmecode:
if 'retweet-' in line:
readmeversion = line.split('retweet-')[1].split(".tar.gz")[0]
break
self.assertEqual(setuppyversion, readmeversion)
################################################################
#
# End of the unit tests
#
################################################################
if __name__ == '__main__':
unittest.main()