Debian Codegraph @

tools/test-features/steps/steps.py

raw
1 # -*- coding: UTF-8 -*-
2
3 from __future__ import absolute_import
4 from behave import given, when, then
5 import logging
6 from six.moves import zip
7
8 spam_log = logging.getLogger('spam')
9 ham_log = logging.getLogger('ham')
10
11 @given("I am testing stuff")
12 def step_impl(context):
13 context.testing_stuff = True
14
15 @given("some stuff is set up")
16 def step_impl(context):
17 context.stuff_set_up = True
18
19 @given("stuff has been set up")
20 def step_impl(context):
21 assert context.testing_stuff is True
22 assert context.stuff_set_up is True
23
24 @when("I exercise it work")
25 def step_impl(context):
26 spam_log.error('logging!')
27 ham_log.error('logging!')
28
29 @then("it will work")
30 def step_impl(context):
31 pass
32
33 @given("some text {prefix}")
34 def step_impl(context, prefix):
35 context.prefix = prefix
36
37 @when('we add some text {suffix}')
38 def step_impl(context, suffix):
39 context.combination = context.prefix + suffix
40
41 @then('we should get the {combination}')
42 def step_impl(context, combination):
43 assert context.combination == combination
44
45 @given('some body of text')
46 def step_impl(context):
47 assert context.text
48 context.saved_text = context.text
49
50 TEXT = ''' Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
51 do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
52 enim ad minim veniam, quis nostrud exercitation ullamco laboris
53 nisi ut aliquip ex ea commodo consequat.'''
54 @then('the text is as expected')
55 def step_impl(context):
56 assert context.saved_text, 'context.saved_text is %r!!' % (context.saved_text, )
57 context.saved_text.assert_equals(TEXT)
58
59 @given('some initial data')
60 def step_impl(context):
61 assert context.table
62 context.saved_table = context.table
63
64 TABLE_DATA = [
65 dict(name='Barry', department='Beer Cans'),
66 dict(name='Pudey', department='Silly Walks'),
67 dict(name='Two-Lumps', department='Silly Walks'),
68 ]
69 @then('we will have the expected data')
70 def step_impl(context):
71 assert context.saved_table, 'context.saved_table is %r!!' % (context.saved_table, )
72 for expected, got in zip(TABLE_DATA, iter(context.saved_table)):
73 assert expected['name'] == got['name']
74 assert expected['department'] == got['department']
75
76 @then('the text is substituted as expected')
77 def step_impl(context):
78 assert context.saved_text, 'context.saved_text is %r!!' % (context.saved_text, )
79 expected = TEXT.replace('ipsum', context.active_outline['ipsum'])
80 context.saved_text.assert_equals(expected)
81
82
83 TABLE_DATA = [
84 dict(name='Barry', department='Beer Cans'),
85 dict(name='Pudey', department='Silly Walks'),
86 dict(name='Two-Lumps', department='Silly Walks'),
87 ]
88 @then('we will have the substituted data')
89 def step_impl(context):
90 assert context.saved_table, 'context.saved_table is %r!!' % (context.saved_table, )
91 value = context.active_outline['spam']
92 expected = value + ' Cans'
93 assert context.saved_table[0]['department'] == expected, '%r != %r' % (
94 context.saved_table[0]['department'], expected)
95
96 @given('the tag "{tag}" is set')
97 def step_impl(context, tag):
98 assert tag in context.tags, '%r NOT present in %r!' % (tag, context.tags)
99 if tag == 'spam':
100 assert context.is_spammy
101
102 @given('the tag "{tag}" is not set')
103 def step_impl(context, tag):
104 assert tag not in context.tags, '%r IS present in %r!' % (tag, context.tags)
105
106 @given('a string {argument} an argument')
107 def step_impl(context, argument):
108 context.argument = argument
109
110 from behave.matchers import register_type
111 register_type(custom=lambda s: s.upper())
112
113 @given('a string {argument:custom} a custom type')
114 def step_impl(context, argument):
115 context.argument = argument
116
117 @then('we get "{argument}" parsed')
118 def step_impl(context, argument):
119 assert context.argument == argument
120