pytestify icon indicating copy to clipboard operation
pytestify copied to clipboard

Regex conversions don't seem right

Open paul545 opened this issue 3 years ago • 1 comments

self.assertRegex(a, b)      # assert a.search(b)
self.assertNotRegex(a, b)   # assert not a.search(b)

Not sure these are correct. I don't think search() is a method of string. It should probably be

import re

self.assertRegex(string, pattern) # assert re.match(pattern, string)
self.assertnotRegex(string, pattern) # assert not re.match(pattern, string)

Not sure if I'm missing something but that's what I did to get it to work

paul545 avatar Apr 12 '22 22:04 paul545

hey, thanks for the issue! i originally chose a.search(b) based off the chart above this link https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertAlmostEqual

but... a) i got it backwards, it should be b.search(a) b) in the unittest implementation, it accommodates not just regex objects, but also strings and bytes

your suggested fix is more future proof, but i'd also be happy with just swapping the two, given that's unittest's guidance

dannysepler avatar May 15 '22 03:05 dannysepler