Code Duplication    Length = 40-46 lines in 2 locations

tests/test_storage.py 2 locations

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