-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsnottests.py
212 lines (180 loc) · 8.35 KB
/
snottests.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
__author__ = 'jcorbett'
import snot
from asserts import *
from slickqa import DocStringMetaData
from nose.tools import istest
from nose.plugins import Plugin
import sys
try:
import ConfigParser
except:
import configparser as ConfigParser
import logging
@istest
def test_plugin_inherits_nose_plugin():
"""SlickAsSnot inherits from nose.plugins.Plugin
Make sure that SlickAsSnot class in the snot namespace is available,
can be instantiated, and the instance is an instance of nose.plugins.Plugin
:component: Nose Plugin
:author: Jason Corbett
:steps:
1. Check to see if SlickAsSnotPlugin is an instance of nose.plugins.Plugin
:expectedResults:
1. isinstance SlickAsSnotPlugin, nose.plugins.Plugin returns true
"""
assert_is_instance(snot.SlickAsSnotPlugin(), Plugin)
@istest
def test_parse_doc_string():
"""Test the DocStringMetaData that it can parse a complicated example
:component: DocStringMetaData
:author: Jason Corbett
:steps:
1. Pass a function with a docstring conforming to the standard to DocStringMetaData
2. Check for expected attributes
:expectedResults:
1. No exception raised
2. All doc string attributes provided are seen inside DocStringMetaData
"""
def testfunc():
"""Long Title Test
Purpose paragraph test 1
Purpose paragraph test 2
:component: Component Test
:author: Author Test
:steps:
1. Step 1 Test
2. Step 2 Test
:expectedResults:
1. Step 1 Expected Result
2. Step 2 Expected Result
:requirements: Requirements Test
:automationTool: Automation Tool Test
:automationId: Automation Id Test
:automationKey: Automation Key Test
:automationConfiguration: Automation Configuration Test
:tags: tags test 1, tags test 2
"""
pass
testdata = DocStringMetaData(testfunc)
assert_equal(u"Long Title Test", testdata.name, "The name should be set to 'Long Title Test'")
assert_equal(u"Purpose paragraph test 1\n\nPurpose paragraph test 2", testdata.purpose, "The purpose field should have both paragraphs")
assert_equal(u"Component Test", testdata.component, "The component should be set to 'Component Test'")
assert_equal(u"Author Test", testdata.author, "The author should be set to 'Author Test'")
assert_equal(u"Requirements Test", testdata.requirements, "The requirements should be set to 'Requirements Test'")
assert_equal(u"Automation Tool Test", testdata.automationTool, "The automationTool should be set to 'Automation Tool Test'")
assert_equal(u"Automation Id Test", testdata.automationId, "The automationId should be set to 'Automation Id Test'")
assert_equal(u"Automation Key Test", testdata.automationKey, "The automationKey should be set to 'Automation Key Test'")
assert_equal(u"Automation Configuration Test", testdata.automationConfiguration, "The automationConfiguration should be set to 'Automation Configuration Test'")
assert_equal([u"tags test 1", u"tags test 2"], testdata.tags, "The tags should be set to ['tags test 1', 'tags test 2']")
assert_equal([u"Step 1 Test", u"Step 2 Test"], testdata.steps, "The steps should be set to ['Step 1 Test', 'Step 2 Test']")
assert_equal([u"Step 1 Expected Result", u"Step 2 Expected Result"], testdata.expectedResults, "The expectedResults should be set to ['Step 1 Expected Result', 'Step 2 Expected Result']")
@istest
def test_empty_docstring():
"""Functions with empty doc strings should not cause exceptions.
Check to make sure that a function without a doc string, still is able to be used
to get meta data from a function. Most important is that it not throw an exception.
:component: DocStringMetaData
:author: Jason Corbett
:steps:
1. Instantiate an instance of DocStringMetaData on a function without a doc string
:expectedResults:
1. No exception should be thrown.
"""
def testfunc():
pass
e = None
try:
DocStringMetaData(testfunc)
except:
e = sys.exc_info()
assert_is_none(e, "No exception should be thrown during instantiation of DocStringMetaData on an undocumented method")
@istest
def test_name_conversion():
"""Function with empty doc string should have a name converted from the function name
When getting data about a function (test) without any doc string the name should be converted
from the function's name. In particular underscore characters should be converted to spaces,
"test" at the beginning of the name should be removed, and The first character capitalized.
:component: DocStringMetaData
:author: Jason Corbett
:steps:
1. Instantiate an instance of DocStringMetaData on a function without a doc string
:expectedResults:
1. The name of the function should be converted to the test name
"""
def test_function_name():
pass
testdata = DocStringMetaData(test_function_name)
assert_equal("Function name", testdata.name, "When a function has no docstring the function name should be converted into a nice name.")
@istest
def test_camel_case_name_conversion():
"""Function with empty doc string should have a name converted from the function name (camel case)
When getting data about a function (test) without any doc string the name should be converted
from the function's name. In particular camel case names should be separated at the upper
case letters, spaces added, and only the first letter left capitalized.
:component: DocStringMetaData
:author: Jason Corbett
:steps:
1. Instantiate an instance of DocStringMetaData on a function without a doc string
:expectedResults:
1. The name of the function should be converted to the test name
"""
def testCamelCase():
pass
testdata = DocStringMetaData(testCamelCase)
assert_equal("Camel case", testdata.name, "When a function has no docstring the function name (in camel case) should be converted into a human friendly name.")
@istest
def test_name_conversion_with_docstring():
"""Function with a doc string, and without a first line has the name converted from function name
When getting data about a function (test) with a doc string but without a name at the top,
the name should be converted from the function's name.
:component: DocStringMetaData
:author: Jason Corbett
:steps:
1. Instantiate an instance of DocStringMetaData on a function with a doc string and without a test name
:expectedResults:
1. The name of the function should be converted to the test name
"""
def testCamelCaseWithDocString():
"""
Purpose Test
:component: Test Component
"""
pass
testdata = DocStringMetaData(testCamelCaseWithDocString)
assert_equal("Camel case with doc string", testdata.name)
assert_equal("Purpose Test", testdata.purpose)
assert_equal("Test Component", testdata.component)
@istest
def test_name_conversion_with_test_at_end():
"""
If the 'test' part of the name occurs at the end of the function name, the conversion to a nice name
should catch it and take it out.
:component: DocStringMetaData
:author: Jason Corbett
:steps:
1. Instantiate an instance of DocStringMetaData on a function with a doc string and without a test name
but with 'test' at the end of the name
:expectedResults:
1. The name of the function should be converted to the test name without test at the end of the name
"""
def this_is_a_simple_test():
pass
testdata = DocStringMetaData(this_is_a_simple_test)
assert_equal("This is a simple", testdata.name)
@istest
def config_test():
"""Test configuration loading and parsing
This test makes sure that if snot.config is not None (meaning there were configuration
files passed to nose using the command line), then these are valid config parser objects.
:component: Snot Config
:author: Jason Corbett
:steps:
1. inspect snot.config
:expectedResults:
1. snot.config should not be None, and should be a ConfigParser object
"""
if snot.config is not None:
assert_is_instance(snot.config, ConfigParser.ConfigParser)
else:
log = logging.getLogger('snottests.config_test')
log.warning("No config from which to test")