Code Duplication    Length = 40-46 lines in 2 locations

tests/test_storage.py 2 locations

@@ 222-267 (lines=46) @@
219
    }[name_format]
220
221
222
@pytest.mark.skipif(sys.version_info[:2] < (2, 7),
223
                    reason="Something weird going on, see: https://bugs.python.org/issue4482")
224
def test_regression_checks_inf(sess, name_format):
225
    output = make_logger(sess)
226
    sess.compare = '0002'
227
    sess.handle_loading()
228
    sess.performance_regressions = []
229
    sess.compare_fail = [
230
        PercentageRegressionCheck("stddev", 5),
231
        DifferenceRegressionCheck("max", 0.000001)
232
    ]
233
    sess.finish()
234
    pytest.raises(PerformanceRegression, sess.display, Namespace(
235
        ensure_newline=lambda: None,
236
        write_line=lambda line, **opts: output.write(force_text(line) + u'\n'),
237
        write=lambda text, **opts: output.write(force_text(text)),
238
        rewrite=lambda text, **opts: output.write(force_text(text)),
239
    ))
240
    print(output.getvalue())
241
    assert sess.performance_regressions == {
242
        'normal': [
243
            ('test_xfast_parametrized[0] (0002_b87b9aa)',
244
             "Field 'stddev' has failed PercentageRegressionCheck: inf > 5.000000000"),
245
            ('test_xfast_parametrized[0] (0002_b87b9aa)',
246
             "Field 'max' has failed DifferenceRegressionCheck: 0.000005551 > 0.000001000")
247
        ],
248
        'short': [
249
            ('xfast_parametrized[0] (0002)',
250
             "Field 'stddev' has failed PercentageRegressionCheck: inf > 5.000000000"),
251
            ('xfast_parametrized[0] (0002)',
252
             "Field 'max' has failed DifferenceRegressionCheck: 0.000005551 > 0.000001000")
253
        ],
254
        'long': [
255
            ('tests/test_normal.py::test_xfast_parametrized[0] '
256
             '(0002_b87b9aae14ff14a7887a6bbaa9731b9a8760555d_20150814_190348_uncommitted-changes)',
257
             "Field 'stddev' has failed PercentageRegressionCheck: inf > 5.000000000"),
258
            ('tests/test_normal.py::test_xfast_parametrized[0] '
259
             '(0002_b87b9aae14ff14a7887a6bbaa9731b9a8760555d_20150814_190348_uncommitted-changes)',
260
             "Field 'max' has failed DifferenceRegressionCheck: 0.000005551 > "
261
             '0.000001000')
262
        ]
263
    }[name_format]
264
    output = make_logger(sess)
265
    pytest.raises(PerformanceRegression, sess.check_regressions)
266
    print(output.getvalue())
267
    assert output.getvalue() == {
268
        'short': """Performance has regressed:
269
\txfast_parametrized[0] (0002) - Field 'stddev' has failed PercentageRegressionCheck: inf > 5.000000000
270
\txfast_parametrized[0] (0002) - Field 'max' has failed DifferenceRegressionCheck: 0.000005551 > 0.000001000
@@ 167-206 (lines=40) @@
164
    ))
165
166
167
def test_regression_checks(sess, name_format):
168
    output = make_logger(sess)
169
    sess.handle_loading()
170
    sess.performance_regressions = []
171
    sess.compare_fail = [
172
        PercentageRegressionCheck("stddev", 5),
173
        DifferenceRegressionCheck("max", 0.000001)
174
    ]
175
    sess.finish()
176
    pytest.raises(PerformanceRegression, sess.display, Namespace(
177
        ensure_newline=lambda: None,
178
        write_line=lambda line, **opts: output.write(force_text(line) + u'\n'),
179
        write=lambda text, **opts: output.write(force_text(text)),
180
        rewrite=lambda text, **opts: output.write(force_text(text)),
181
    ))
182
    print(output.getvalue())
183
    assert sess.performance_regressions == {
184
        'normal': [
185
            ('test_xfast_parametrized[0] (0001_b87b9aa)',
186
             "Field 'stddev' has failed PercentageRegressionCheck: 23.331641765 > 5.000000000"),
187
            ('test_xfast_parametrized[0] (0001_b87b9aa)',
188
             "Field 'max' has failed DifferenceRegressionCheck: 0.000001843 > 0.000001000")
189
        ],
190
        'short': [
191
            ('xfast_parametrized[0] (0001)',
192
             "Field 'stddev' has failed PercentageRegressionCheck: 23.331641765 > 5.000000000"),
193
            ('xfast_parametrized[0] (0001)',
194
             "Field 'max' has failed DifferenceRegressionCheck: 0.000001843 > 0.000001000")
195
        ],
196
        'long': [
197
            ('tests/test_normal.py::test_xfast_parametrized[0] (0001_b87b9aae14ff14a7887a6bbaa9731b9a8760555d_20150814_190343_uncommitted-changes)',
198
             "Field 'stddev' has failed PercentageRegressionCheck: 23.331641765 > 5.000000000"),
199
            ('tests/test_normal.py::test_xfast_parametrized[0] (0001_b87b9aae14ff14a7887a6bbaa9731b9a8760555d_20150814_190343_uncommitted-changes)',
200
             "Field 'max' has failed DifferenceRegressionCheck: 0.000001843 > 0.000001000")
201
        ],
202
    }[name_format]
203
    output = make_logger(sess)
204
    pytest.raises(PerformanceRegression, sess.check_regressions)
205
    print(output.getvalue())
206
    assert output.getvalue() == {
207
        'short': """Performance has regressed:
208
\txfast_parametrized[0] (0001) - Field 'stddev' has failed PercentageRegressionCheck: 23.331641765 > 5.000000000
209
\txfast_parametrized[0] (0001) - Field 'max' has failed DifferenceRegressionCheck: 0.000001843 > 0.000001000