forked from behave/behave
/
__main__.py
122 lines (95 loc) · 3.4 KB
/
__main__.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
110
111
112
113
114
115
116
117
118
119
120
121
122
import sys
from behave import __version__
from behave.configuration import Configuration, ConfigError
from behave.formatter.ansi_escapes import escapes
from behave.i18n import languages
from behave.formatter import formatters
from behave.runner import Runner
from behave.parser import ParserError
TAG_HELP = """
Scenarios inherit tags declared on the Feature level. The simplest
TAG_EXPRESSION is simply a tag::
--tags @dev
You may even leave off the "@" - behave doesn't mind.
When a tag in a tag expression starts with a ~, this represents boolean NOT::
--tags ~@dev
A tag expression can have several tags separated by a comma, which represents
logical OR::
--tags @dev,@wip
The --tags option can be specified several times, and this represents logical
AND, for instance this represents the boolean expression
"(@foo or not @bar) and @zap"::
--tags @foo,~@bar --tags @zap.
Beware that if you want to use several negative tags to exclude several tags
you have to use logical AND::
--tags ~@fixme --tags ~@buggy.
""".strip()
# TODO
# Positive tags can be given a threshold to limit the number of occurrences.
# Which can be practical if you are practicing Kanban or CONWIP. This will fail
# if there are more than 3 occurrences of the @qa tag:
#
# --tags @qa:3
# """.strip()
def main():
config = Configuration()
if config.version:
print "behave " + __version__
sys.exit(0)
if config.tags_help:
print TAG_HELP
sys.exit(0)
if config.lang_list:
iso_codes = languages.keys()
iso_codes.sort()
print "Languages available:"
for iso_code in iso_codes:
native = languages[iso_code]['native'][0]
name = languages[iso_code]['name'][0]
print u'%s: %s / %s' % (iso_code, native, name)
sys.exit(0)
if config.lang_help:
if config.lang_help not in languages:
sys.exit('%s is not a recognised language: try --lang-list' %
config.lang_help)
trans = languages[config.lang_help]
print u"Translations for %s / %s" % (trans['name'][0],
trans['native'][0])
for kw in trans:
if kw in 'name native'.split():
continue
print u'%16s: %s' % (kw.title().replace('_', ' '),
u', '.join(w for w in trans[kw] if w != '*'))
sys.exit(0)
if not config.format:
config.format = ['pretty']
elif 'help' in config.format:
print "Available formatters:"
formatters.list_formatters(sys.stdout)
sys.exit(0)
stream = config.output
runner = Runner(config)
try:
failed = runner.run()
except ParserError, e:
sys.exit(str(e))
except ConfigError, e:
sys.exit(str(e))
if config.show_snippets and runner.undefined:
msg = "\nYou can implement step definitions for undefined steps with "
msg += "these snippets:\n\n"
printed = set()
for step in set(runner.undefined):
print repr(step)
if step in printed:
continue
printed.add(step)
msg += "@" + step.step_type + "(" + repr(step.name) + ")\n"
msg += "def impl(context):\n"
msg += " assert False\n\n"
stream.write(escapes['undefined'] + msg + escapes['reset'])
stream.flush()
if failed:
sys.exit(1)
if __name__ == '__main__':
main()