TestSampleResponse.test_sample_response fails because of path vs regex issue on Windows
When running the test suite on Windows I get the following error from TestSampleResponse.test_sample_resonse
, and a few other tests:
___________________ TestSampleResponse.test_sample_response ___________________
self = <test.test_uncertainty.TestSampleResponse testMethod=test_sample_response>
def test_sample_response(self):
config2 = '''[reference-model]
model = example_model_files/H1_20190416.ini
[sensing-measurement-files]
mcmc =
gpr =
[x-arm-measurement-files]
tst_mcmc =
pum_mcmc =
uim_mcmc =
tst_gpr =
pum_gpr =
uim_gpr =
[x-arm-sus-cal-lines]
uim = 15.6
pum = 16.4
tst = 17.6
[y-arm-pcal-cal-lines]
sus = 17.1
sensing = 410.3
pcal3 = 1083.7
pcal4 = 7.93
[tdcf-data]
frametype = R
duration = 130
[sensing-tdcf]
kappa_c = CAL-CS_TDEP_KAPPA_C_OUTPUT
f_cc = CAL-CS_TDEP_F_C_OUTPUT
pcal2_unc = 0
pcal_arm = Y
[x-arm-tdcf]
kappa_uim = CAL-CS_TDEP_KAPPA_UIM_REAL_OUTPUT
kappa_pum = CAL-CS_TDEP_KAPPA_PUM_REAL_OUTPUT
kappa_tst = CAL-CS_TDEP_KAPPA_TST_REAL_OUTPUT
pcal1_unc = 0
uim_unc = 0
pum_unc = 0
tst_unc = 0
pcal_arm = Y
[sample-tdcf]
kappa_c = False
f_cc = False
kappa_uim = True
kappa_pum = True
kappa_tst = True
[pcal]
sys_err = 1
sys_unc = 0
sample = True'''
test_unc = pydarm.uncertainty.DARMUncertainty(config2)
test_response, data, c_pars, a_pars, c_syserr, a_syserr = \
> test_unc.sample_response(
1239958818, self.frequencies, data=self.data)
test\test_uncertainty.py:306:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\_test_env\lib\site-packages\pydarm\uncertainty.py:706: in sample_response
EP5 = darm_copy.digital.compute_response(
..\_test_env\lib\site-packages\pydarm\darm.py:63: in compute_response
tf = compute_digital_filter_response(
..\_test_env\lib\site-packages\pydarm\utils.py:347: in compute_digital_filter_response
sysd, pfilt = read_filter_sys(filter_filename, filter_bank_name,
..\_test_env\lib\site-packages\pydarm\utils.py:395: in read_filter_sys
if not re.match(filename, pfilt[0]):
..\_test_env\lib\re.py:190: in match
return _compile(pattern, flags).match(string)
..\_test_env\lib\re.py:303: in _compile
p = sre_compile.compile(pattern, flags)
..\_test_env\lib\sre_compile.py:764: in compile
p = sre_parse.parse(p, flags)
..\_test_env\lib\sre_parse.py:950: in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
..\_test_env\lib\sre_parse.py:443: in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
..\_test_env\lib\sre_parse.py:525: in _parse
code = _escape(source, this, state)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
source = <sre_parse.Tokenizer object at 0x000001BBC45B7160>, escape = '\\H'
state = <sre_parse.State object at 0x000001BBC45317E0>
def _escape(source, escape, state):
# handle escape code in expression
code = CATEGORIES.get(escape)
if code:
return code
code = ESCAPES.get(escape)
if code:
return code
try:
c = escape[1:2]
if c == "x":
# hexadecimal escape
escape += source.getwhile(2, HEXDIGITS)
if len(escape) != 4:
raise source.error("incomplete escape %s" % escape, len(escape))
return LITERAL, int(escape[2:], 16)
elif c == "u" and source.istext:
# unicode escape (exactly four digits)
escape += source.getwhile(4, HEXDIGITS)
if len(escape) != 6:
raise source.error("incomplete escape %s" % escape, len(escape))
return LITERAL, int(escape[2:], 16)
elif c == "U" and source.istext:
# unicode escape (exactly eight digits)
escape += source.getwhile(8, HEXDIGITS)
if len(escape) != 10:
raise source.error("incomplete escape %s" % escape, len(escape))
c = int(escape[2:], 16)
chr(c) # raise ValueError for invalid code
return LITERAL, c
elif c == "N" and source.istext:
import unicodedata
# named unicode escape e.g. \N{EM DASH}
if not source.match('{'):
raise source.error("missing {")
charname = source.getuntil('}', 'character name')
try:
c = ord(unicodedata.lookup(charname))
except KeyError:
raise source.error("undefined character name %r" % charname,
len(charname) + len(r'\N{}'))
return LITERAL, c
elif c == "0":
# octal escape
escape += source.getwhile(2, OCTDIGITS)
return LITERAL, int(escape[1:], 8)
elif c in DIGITS:
# octal escape *or* decimal group reference (sigh)
if source.next in DIGITS:
escape += source.get()
if (escape[1] in OCTDIGITS and escape[2] in OCTDIGITS and
source.next in OCTDIGITS):
# got three octal digits; this is an octal escape
escape += source.get()
c = int(escape[1:], 8)
if c > 0o377:
raise source.error('octal escape value %s outside of '
'range 0-0o377' % escape,
len(escape))
return LITERAL, c
# not an octal escape, so this is a group reference
group = int(escape[1:])
if group < state.groups:
if not state.checkgroup(group):
raise source.error("cannot refer to an open group",
len(escape))
state.checklookbehindgroup(group, source)
return GROUPREF, group
raise source.error("invalid group reference %d" % group, len(escape) - 1)
if len(escape) == 2:
if c in ASCIILETTERS:
> raise source.error("bad escape %s" % escape, len(escape))
E re.error: bad escape \H at position 6
..\_test_env\lib\sre_parse.py:426: error
I think the issue is that the pydarm.utils.read_filter_sys
is trying to compile a file path (with directory separators) as a regular expression, on Windows the directory separator is \
so re.compile
is interpreting the example_model_files\H1_20190416.ini
as including an invalid escape sequence \H
. Is it enough to modify the re.search
expression in that function to use only the basename of the file (os.path.basename
)?
Edited by Duncan Macleod