Code Duplication    Length = 40-46 lines in 2 locations

tests/test_storage.py 2 locations

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