-
Notifications
You must be signed in to change notification settings - Fork 9
/
test
executable file
·75 lines (67 loc) · 2.97 KB
/
test
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
#!/usr/bin/python3
"""Tester for the bot"""
import argparse
import logging
from AnswerMachine import handle_list
from Externals import setup_database
import Mock
import Persistence
logger = Persistence.init_logger('bot')
def arguments():
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
description=__doc__,
epilog="""Possible sources:
testcases: Use the list of all mocked testcase tweets
id: Out of the list of all mocked testcase tweets, use only the ones given with the --id
attribute
external: Use mocked tweet objects from tweet_details.py. That file may be created with
get_tweet.
""")
Persistence.set_logging_args(parser)
parser.add_argument('--source',
choices=['testcases', 'id', 'external'],
default='testcases',
help='''Specify source of testable tweets. See possible values below''',
required=False,
)
parser.add_argument('--id',
required=False,
nargs='*',
help='''The ids of test tweets to look at. Only valid with --source id'''
)
parser.add_argument('--output',
choices=['summary', 'descriptive'],
default='descriptive',
help='Kind of statistics output: One-line-summary or a little more verbose.'
)
parser.add_argument('--readwrite', default=False, help='Will be forced to be false')
args_ = parser.parse_args()
args_.readwrite = False
if args_.source == 'id' and args_.id is None:
parser.print_help()
parser.exit("Error: --source id given, but no --id found")
if args_.source != 'id' and args_.id is not None:
parser.print_help()
parser.exit("Error: --id given, but --source is not 'id'")
logger.setLevel(getattr(logging, args_.log_level.upper()))
logging.getLogger('msg').setLevel(logging.CRITICAL)
logger.debug("test running args: %s", args_)
return args_
if __name__ == "__main__":
try:
args = arguments()
id_list = args.id if args.id is not None else []
database = setup_database(args, 'twitter')
logger.info("Trying to create mock api from %s", args.source)
twitter = Mock.MockApi(mode=args.source,
id_list=[int(x) for x in id_list])
magic_tags, magic_emojis = database.magic_hashtags()
handle_list(network=twitter,
database=database,
magic_tags=magic_tags,
magic_emojis=magic_emojis)
if args.source != 'external':
raise SystemExit(twitter.statistics(args.output))
except Exception as e: # pylint: disable=W0703
logger.log(51, "TESTS FAIL TO RUN")
logger.exception("%s", e)