From f3fd6d0e25be732d6d5b2dbe9d5b00bdddb7b6cb Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Thu, 5 Sep 2019 16:35:43 +0100 Subject: [PATCH] TEST: Don't hard code line numbers --- tests/test_deprecated.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py index 307818960..ecd035220 100644 --- a/tests/test_deprecated.py +++ b/tests/test_deprecated.py @@ -7,12 +7,22 @@ import pytest import fsl.utils.deprecated as deprecated -# the line number of the warning is hard coded in -# the unit tests below. Don't change the line number! +# these get updated in the relevant functions +WARNING_LINE_NUMBER = None +DEPRECATED_LINE_NUMBER = None + +def _linenum(pattern): + with open(__file__, 'rt') as f: + for i, line in enumerate(f.readlines(), 1): + if pattern in line: + return i + return -1 + + def emit_warning(): deprecated.warn('blag', vin='1.0.0', rin='2.0.0', msg='yo') - -WARNING_LINE_NUMBER = 13 + global WARNING_LINE_NUMBER + WARNING_LINE_NUMBER = _linenum('deprecated.warn(\'blag\'') @deprecated.deprecated(vin='1.0.0', rin='2.0.0', msg='yo') @@ -20,9 +30,9 @@ def depfunc(): pass def call_dep_func(): - depfunc() - -DEPRECATED_LINE_NUMBER = 23 + depfunc() # mark + global DEPRECATED_LINE_NUMBER + DEPRECATED_LINE_NUMBER = _linenum('depfunc() # mark') def _check_warning(w, name, lineno): -- GitLab