Skip to content

Commit

Permalink
system-test: correct python re.MULTILINE usage
Browse files Browse the repository at this point in the history
Python re.M flag extends the matching rules for '^' and '$', but it
doesn't mean '.*' will match across the newline char '\n'. For that,
re.DOTALL should be used instead. And since the '*', '+', and '?'
qualifiers are all greedy, and additional '?' should be appended to
prevent it from matching across multiple matches.

Signed-off-by: You-Sheng Yang <vicamo@gmail.com>
  • Loading branch information
vicamo committed Jan 28, 2022
1 parent f563b6c commit f3e9638
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion system/t02_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ConfigInFileTest(BaseTest):
prepare = BaseTest.prepare_remove_all

def outputMatchPrepare(_, s):
return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE)
return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s)


class ConfigInMissingFileTest(BaseTest):
Expand Down
4 changes: 2 additions & 2 deletions system/t03_help/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MainTest(BaseTest):
runCmd = "aptly"

def outputMatchPrepare(_, s):
return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE)
return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s)


class MirrorTest(BaseTest):
Expand All @@ -40,7 +40,7 @@ class MainHelpTest(BaseTest):
runCmd = "aptly help"

def outputMatchPrepare(_, s):
return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE)
return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s)


class MirrorHelpTest(BaseTest):
Expand Down
20 changes: 9 additions & 11 deletions system/t04_mirror/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class CreateMirror10Test(BaseTest):
expectedCode = 1

def outputMatchPrepare(self, s):
return re.sub(r'Signature made .* using|gpgv: keyblock resource .*$|gpgv: Can\'t check signature: .*$', '', s, flags=re.MULTILINE)
return re.sub(r'Signature made .*? using|gpgv: keyblock resource .*?\n|gpgv: Can\'t check signature: .*?\n', '', s, flags=re.DOTALL)


class CreateMirror11Test(BaseTest):
Expand All @@ -127,7 +127,7 @@ class CreateMirror11Test(BaseTest):
fixtureGpg = True

def outputMatchPrepare(self, s):
return re.sub(r'Signature made .* using', '', s)
return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL)

def check(self):
self.check_output()
Expand All @@ -143,7 +143,7 @@ class CreateMirror12Test(BaseTest):
expectedCode = 1

def outputMatchPrepare(self, s):
return re.sub(r'Signature made .* using|gpgv: keyblock resource .*$|gpgv: Can\'t check signature: .*$', '', s, flags=re.MULTILINE)
return re.sub(r'Signature made .*? using|gpgv: keyblock resource .*?\n|gpgv: Can\'t check signature: .*?\n', '', s, flags=re.DOTALL)


class CreateMirror13Test(BaseTest):
Expand All @@ -166,7 +166,7 @@ class CreateMirror14Test(BaseTest):
fixtureGpg = True

def outputMatchPrepare(self, s):
return re.sub(r'Signature made .* using', '', s)
return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL)

def check(self):
def removeDates(s):
Expand Down Expand Up @@ -218,7 +218,7 @@ class CreateMirror18Test(BaseTest):
runCmd = "aptly mirror create -keyring=aptlytest.gpg mirror18 ppa:gladky-anton/gnuplot"

def outputMatchPrepare(self, s):
return re.sub(r'Signature made .* using', '', s)
return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL)

def check(self):
self.check_output()
Expand All @@ -234,7 +234,7 @@ class CreateMirror19Test(BaseTest):
runCmd = "aptly -architectures='i386' mirror create -keyring=aptlytest.gpg -with-sources mirror19 http://security.debian.org/ stretch/updates main"

def outputMatchPrepare(self, s):
return re.sub(r'Signature made .* using', '', s)
return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL)

def check(self):
def removeDates(s):
Expand Down Expand Up @@ -276,7 +276,7 @@ class CreateMirror21Test(BaseTest):
fixtureGpg = True

def outputMatchPrepare(self, s):
return re.sub(r'Signature made .* using', '', s)
return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL)

def check(self):
def removeSHA512(s):
Expand Down Expand Up @@ -321,7 +321,7 @@ class CreateMirror24Test(BaseTest):
fixtureGpg = True

def outputMatchPrepare(self, s):
return re.sub(r'Signature made .* using', '', s)
return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL)

configOverride = {
"gpgDisableVerify": True
Expand Down Expand Up @@ -406,9 +406,7 @@ class CreateMirror32Test(BaseTest):
requiresGPG2 = True

def outputMatchPrepare(self, s):
return \
re.sub(r'([A-F0-9]{8})[A-F0-9]{8}', r'\1',
re.sub(r'^gpgv: (Signature made .+|.+using RSA key.+)\n', '', s, flags=re.MULTILINE))
return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL)

def check(self):
self.check_output()
Expand Down
2 changes: 1 addition & 1 deletion system/t04_mirror/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def filterOutSignature(_, s):
return re.sub(r'Signature made .* using', '', s)
return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL)


def filterOutRedirects(_, s):
Expand Down
2 changes: 1 addition & 1 deletion system/t09_repo/include.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def gpgRemove(_, s):
return re.sub(r'Signature made .* using|gpgv: keyblock resource .*$|gpgv: Can\'t check signature: .*$', '', s, flags=re.MULTILINE)
return re.sub(r'Signature made .*? using|gpgv: keyblock resource .*?\n|gpgv: Can\'t check signature: .*?\n', '', s, flags=re.DOTALL)


def changesRemove(_, s):
Expand Down

0 comments on commit f3e9638

Please sign in to comment.