[Tests] Avoid comparing the text in diffs when not Debian

This commit is contained in:
Salvador E. Tropea 2022-09-23 09:35:57 -03:00
parent 1f7cff4fe8
commit 80d69acaa6
2 changed files with 11 additions and 8 deletions

View File

@ -44,6 +44,8 @@ POS_DIR = 'positiondir'
MK_TARGETS = ['position', 'archive', 'interactive_bom', 'run_erc', '3D', 'kibom_internal', 'drill', 'pcb_render',
'print_front', 'svg_sch_def', 'svg_sch_int', 'pdf_sch_def', 'pdf_sch_int', 'fake_sch', 'update_xml',
'run_drc']
# If we are not running on Debian skip the text part at the top of diff PDFs
OFFSET_Y = '0' if os.path.isfile('/etc/debian_version') is not None else '80'
def test_skip_pre_and_outputs(test_dir):
@ -1275,7 +1277,7 @@ def test_diff_file_1(test_dir):
yaml = 'diff_file_'+('k5' if context.ki5() else 'k6')
ctx = context.TestContext(test_dir, prj, yaml)
ctx.run()
ctx.compare_pdf(prj+'-diff_pcb.pdf', reference='light_control-diff_pcb.pdf')
ctx.compare_pdf(prj+'-diff_pcb.pdf', reference='light_control-diff_pcb.pdf', off_y=OFFSET_Y)
ctx.clean_up(keep_project=True)
@ -1305,7 +1307,7 @@ def test_diff_git_1(test_dir):
shutil.copy2(ctx.board_file.replace(prj, prj+'_diff'), file)
# Run the test
ctx.run(extra=['-b', file], no_board_file=True)
ctx.compare_pdf(prj+'-diff_pcb.pdf')
ctx.compare_pdf(prj+'-diff_pcb.pdf', off_y=OFFSET_Y)
ctx.clean_up(keep_project=True)
@ -1359,7 +1361,7 @@ def test_diff_git_2(test_dir):
f.write('Bye!\n')
# Run the test
ctx.run(extra=['-b', file], no_board_file=True, extra_debug=True)
ctx.compare_pdf(prj+'-diff_pcb.pdf')
ctx.compare_pdf(prj+'-diff_pcb.pdf', off_y=OFFSET_Y)
# Check the submodule was restored
with open(some_file, 'rt') as f:
msg = f.read()
@ -1398,7 +1400,7 @@ def test_diff_git_3(test_dir):
ctx.run_command(['git', 'commit', '-m', 'New version'], chdir_out=True)
# Run the test
ctx.run(extra=['-b', file], no_board_file=True, extra_debug=True)
ctx.compare_pdf(prj+'-diff_pcb.pdf')
ctx.compare_pdf(prj+'-diff_pcb.pdf', off_y=OFFSET_Y)
ctx.clean_up(keep_project=True)

View File

@ -476,7 +476,8 @@ class TestContext(object):
def search_not_in_file_d(self, file, texts):
return self.search_not_in_file(os.path.join(self.sub_dir, file), texts)
def compare_image(self, image, reference=None, diff='diff.png', ref_out_dir=False, fuzz='5%', tol=0, height='87%'):
def compare_image(self, image, reference=None, diff='diff.png', ref_out_dir=False, fuzz='5%', tol=0, height='87%',
off_y='0'):
""" For images and single page PDFs """
if reference is None:
reference = image
@ -503,7 +504,7 @@ class TestContext(object):
image,
reference,
# Avoid the part where KiCad version is printed
'-crop', '100%x'+height+'+0+0', '+repage',
'-crop', '100%x'+height+'+0+'+off_y, '+repage',
'-colorspace', 'RGB',
self.get_out_path(diff)]
logging.debug('Comparing images with: '+usable_cmd(cmd))
@ -519,7 +520,7 @@ class TestContext(object):
os.remove(png_image)
assert ae <= tol
def compare_pdf(self, gen, reference=None, diff='diff-{}.png', height='87%'):
def compare_pdf(self, gen, reference=None, diff='diff-{}.png', height='87%', off_y='0'):
""" For multi-page PDFs """
if reference is None:
reference = gen
@ -544,7 +545,7 @@ class TestContext(object):
# Compare each page
for page in range(len(ref_pages)):
self.compare_image('gen-'+str(page)+'.png', 'ref-'+str(page)+'.png', diff.format(page), ref_out_dir=True,
height=height)
height=height, off_y=off_y)
def compare_txt(self, text, reference=None, diff='diff.txt'):
if reference is None: