Strip irrelevant lines from test output

It may happen that aptly retries to download data during tests (maybe because
of a network issue), but our fixtures doesn't account for it. So, we strip
those irrelevant lines before comparison.
This commit is contained in:
Lorenzo Bolla
2022-01-26 17:07:38 +01:00
parent 122ff609e8
commit 48635c8057
2 changed files with 17 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import json
import subprocess
import os
import posixpath
import re
import shlex
import shutil
import string
@@ -279,6 +280,15 @@ class BaseTest(object):
def get_gold(self, gold_name="gold"):
return self.gold_processor(open(self.get_gold_filename(gold_name), "r").read())
def strip_retry_lines(self, s):
for prefix in (
'Following redirect',
'Error downloading',
'Retrying',
):
s = re.sub(r'{}.*\n'.format(prefix), '', s)
return s
def check_output(self):
try:
self.verify_match(self.get_gold(), self.output,
@@ -382,6 +392,10 @@ class BaseTest(object):
a = match_prepare(a)
b = match_prepare(b)
# Make sure there is something to compare after `match_prepare`
if not a or not b:
raise Exception("content empty")
if a != b:
diff = "".join(difflib.unified_diff(
[l + "\n" for l in a.split("\n")], [l + "\n" for l in b.split("\n")]))

View File

@@ -362,6 +362,9 @@ class CreateMirror27Test(BaseTest):
"""
runCmd = "aptly mirror create --ignore-signatures mirror27 http://linux.dell.com/repo/community/ubuntu wheezy openmanage/740"
def outputMatchPrepare(self, s):
return self.strip_retry_lines(s)
def check(self):
self.check_output()
self.check_cmd_output("aptly mirror show mirror27", "mirror_show")