def test_scaleddown_join(self): """Scale larger to same size - compare to result.""" with open(self.FILE1) as file1: im_1 = benedict.from_xml(file1.read()) with open(self.FILE2) as file2: im_2 = benedict.from_xml(file2.read()) result = append_svg(im_2, im_1, v_bottom=0, v_top=1) result['svg']['@preserveAspectRatio'] = "xMinYMin" # # to write: # with open('result_scaled_join.svg', 'w') as file: # result.to_xml(output=file, pretty=True) with open(join(self.DIR, 'result_scaled_join.svg'), 'r') as expected: self.assertEqual(result, benedict.from_xml(expected.read()))
def test_simple_join_padding(self): """Test the horizontal padding - compare to result.""" with open(self.FILE1) as file1: im_1 = benedict.from_xml(file1.read()) with open(self.FILE2) as file2: im_2 = benedict.from_xml(file2.read()) result = append_svg(im_2, im_1, centerpad=100) result['svg']['@preserveAspectRatio'] = "xMinYMin" # # to write: # with open('result_simple_join_padding.svg', 'w') as file: # result.to_xml(output=file, pretty=True) with open(join(self.DIR, 'result_simple_join_padding.svg'), 'r') as expected: self.assertEqual(result, benedict.from_xml(expected.read()))
def test_simple_join(self): """Combine two example svg images to a new one - compare to result.""" with open(self.FILE1) as file1: im_1 = benedict.from_xml(file1.read()) with open(self.FILE2) as file2: im_2 = benedict.from_xml(file2.read()) result = append_svg(im_1, im_2) result['svg']['@preserveAspectRatio'] = "xMinYMin" # # to write: # with open('result_simple_join.svg', 'w') as file: # result.to_xml(output=file, pretty=True) with open(join(self.DIR, 'result_simple_join.svg'), 'r') as expected: self.assertEqual(result, benedict.from_xml(expected.read()))
def test_append_svg_pinned(otherargs, filename, reverse, padding, write=WRITE): """Combine two example svg images - scaling with v_bottom and v_top.""" filename += f"_padding{padding}_{reverse=}.svg" with open(FILE1) as file1: im_1 = benedict.from_xml(file1.read()) with open(FILE2) as file2: im_2 = benedict.from_xml(file2.read()) order = (im_2, im_1) if reverse else (im_1, im_2) result = append_svg(*order, centerpad=padding, **otherargs) result['svg']['@preserveAspectRatio'] = "xMinYMin" if write: makedirs(DIR, exist_ok=True) with open(join(DIR, filename), 'w') as outfile: result.to_xml(output=outfile, pretty=True) with open(join(DIR, filename), 'r') as expected: assert result == benedict.from_xml(expected.read())
def test_append_svg_scaled(otherargs, filename, reverse, scale2, write=WRITE): """Combine two example svg images - different scalings for second image.""" filename += f"_scale{int(scale2*10)}to10_{reverse=}.svg" with open(FILE1) as file1: im_1 = benedict.from_xml(file1.read()) with open(FILE2) as file2: im_2 = benedict.from_xml(file2.read()) order = (im_2, im_1) if reverse else (im_1, im_2) result = append_svg(*order, scale2=scale2, **otherargs) result['svg']['@preserveAspectRatio'] = "xMinYMin" if write: makedirs(DIR, exist_ok=True) with open(join(DIR, filename), 'w') as outfile: result.to_xml(output=outfile, pretty=True) with open(join(DIR, filename), 'r') as expected: assert result == benedict.from_xml(expected.read())
def test_centered_larger_join(self): """Center the smaller image - compare to result.""" with open(self.FILE1) as file1: im_1 = benedict.from_xml(file1.read()) with open(self.FILE2) as file2: im_2 = benedict.from_xml(file2.read()) result = append_svg(im_2, im_1, v_bottom='center', v_top='center') result['svg']['@preserveAspectRatio'] = "xMinYMin" # # to write: # with open('result_centered_join2.svg', 'w') as file: # result.to_xml(output=file, pretty=True) with open(join(self.DIR, 'result_centered_join2.svg'), 'r') as expected: self.assertEqual(result, benedict.from_xml(expected.read()))