コード例 #1
0
    def test_missing_or_bad_attrs(self):
        svg = ElementTree.fromstring(XML_HEADER + b'<svg></svg>')
        self.assertIsNone(svg_util.make_square(svg))

        svg = ElementTree.fromstring(
            XML_HEADER + b'<svg widTH="abc" height="2222px"></svg>')
        self.assertIsNone(svg_util.make_square(svg))
コード例 #2
0
 def test_resized_float_width_height(self):
     svg = ElementTree.fromstring(
         XML_HEADER + b'<svg width="21.12" height="21.22"></svg>')
     result = ElementTree.tostring(svg_util.make_square(svg))
     self.assertTrue(b'width="80"' in result)
     self.assertTrue(b'height="80"' in result)
     self.assertTrue(b'viewBox="0 0 21 21"' in result)
コード例 #3
0
 def test_resized_no_viewbox(self):
     svg = ElementTree.fromstring(XML_HEADER +
                                  b'<svg width="30" hEIght="15"></svg>')
     result = ElementTree.tostring(svg_util.make_square(svg))
     self.assertTrue(b'width="80"' in result)
     self.assertTrue(b'hEIght="80"' in result)
     self.assertTrue(b'viewBox="0 -7 30 30"' in result)
コード例 #4
0
 def test_resized_viewbox_no_width_height(self):
     """Truncate decimals"""
     svg = ElementTree.fromstring(XML_HEADER + b'<svg viewBox="-10.23 32.18 75.876 75.956"></svg>')
     result = ElementTree.tostring(svg_util.make_square(svg))
     self.assertTrue(b'width="80"' in result)
     self.assertTrue(b'height="80"' in result)
     self.assertTrue(b'viewBox="-10 32 75 75"' in result)
コード例 #5
0
 def test_resized_viewbox_no_width_height(self):
     """Truncate decimals"""
     svg = ElementTree.fromstring(
         XML_HEADER + b'<svg viewBox="-10.23 32.18 75.876 75.956"></svg>')
     result = ElementTree.tostring(svg_util.make_square(svg))
     self.assertTrue(b'width="80"' in result)
     self.assertTrue(b'height="80"' in result)
     self.assertTrue(b'viewBox="-10 32 75 75"' in result)
コード例 #6
0
 def test_resized_with_viewbox(self):
     svg = ElementTree.fromstring(
         XML_HEADER +
         b'<svg width="30" height="15" vIewBox="-15 10 60 30"></svg>')
     result = ElementTree.tostring(svg_util.make_square(svg))
     self.assertTrue(b'width="80"' in result)
     self.assertTrue(b'height="80"' in result)
     self.assertTrue(b'vIewBox="-15 -5 60 60"' in result)
コード例 #7
0
ファイル: models.py プロジェクト: isabella232/peacecorps-site
 def save(self, *args, **kwargs):
     """Save other colors of the issue icon. We assume it is validated in
     the clean function"""
     if self.icon:
         xml = svg.validate_svg(self.icon.file.read())
         square = svg.make_square(xml)
         colors = svg.color_icon(square)
         super(Issue, self).save(*args, **kwargs)
         for key, content in colors.items():
             filename = self.icon_color(key)
             if self.icon.storage.exists(filename):
                 self.icon.storage.delete(filename)
             self.icon.storage.save(filename, svg.as_file(content))
     else:
         super(Issue, self).save(*args, **kwargs)
コード例 #8
0
ファイル: models.py プロジェクト: Threespot/peacecorps-site
 def save(self, *args, **kwargs):
     """Save other colors of the issue icon. We assume it is validated in
     the clean function"""
     if self.icon:
         xml = svg.validate_svg(self.icon.file.read())
         square = svg.make_square(xml)
         colors = svg.color_icon(square)
         super(Issue, self).save(*args, **kwargs)
         for key, content in colors.items():
             filename = self.icon_color(key)
             if self.icon.storage.exists(filename):
                 self.icon.storage.delete(filename)
             self.icon.storage.save(filename, svg.as_file(content))
     else:
         super(Issue, self).save(*args, **kwargs)
コード例 #9
0
 def test_resized_with_viewbox(self):
     svg = ElementTree.fromstring(XML_HEADER + b'<svg width="30" height="15" vIewBox="-15 10 60 30"></svg>')
     result = ElementTree.tostring(svg_util.make_square(svg))
     self.assertTrue(b'width="80"' in result)
     self.assertTrue(b'height="80"' in result)
     self.assertTrue(b'vIewBox="-15 -5 60 60"' in result)
コード例 #10
0
 def test_resized_float_width_height(self):
     svg = ElementTree.fromstring(XML_HEADER + b'<svg width="21.12" height="21.22"></svg>')
     result = ElementTree.tostring(svg_util.make_square(svg))
     self.assertTrue(b'width="80"' in result)
     self.assertTrue(b'height="80"' in result)
     self.assertTrue(b'viewBox="0 0 21 21"' in result)
コード例 #11
0
 def test_resized_no_viewbox(self):
     svg = ElementTree.fromstring(XML_HEADER + b'<svg width="30" hEIght="15"></svg>')
     result = ElementTree.tostring(svg_util.make_square(svg))
     self.assertTrue(b'width="80"' in result)
     self.assertTrue(b'hEIght="80"' in result)
     self.assertTrue(b'viewBox="0 -7 30 30"' in result)
コード例 #12
0
    def test_missing_or_bad_attrs(self):
        svg = ElementTree.fromstring(XML_HEADER + b"<svg></svg>")
        self.assertIsNone(svg_util.make_square(svg))

        svg = ElementTree.fromstring(XML_HEADER + b'<svg widTH="abc" height="2222px"></svg>')
        self.assertIsNone(svg_util.make_square(svg))