Exemplo n.º 1
0
    def test_bad_viewbox_entry(self):
        """Fallback test: Bad viewBox default to 100"""
        # First, demonstrate that 3779px is 1m, so unit should be 'm'.
        self.assertEqual(svg('width="3779px" viewBox="0 0 1 1"').unit, 'm')

        # Corrupt the viewBox to include a non-float value; will default to 'px'
        self.assertEqual(svg('width="3779px" viewBox="x 0 1 1"').unit, 'px')
Exemplo n.º 2
0
 def test_scale(self):
     """Scale of a document"""
     doc = svg('id="empty" viewBox="0 0 100 100" width="200" height="200"')
     self.assertEqual(doc.width, 200.0)
     self.assertEqual(doc.get_viewbox()[2], 100.0)
     self.assertEqual(doc.scale, 2.0)
     doc = svg('id="empty" viewBox="0 0 0 0" width="200" height="200"')
     self.assertEqual(doc.scale, 1.0)
Exemplo n.º 3
0
    def test_bad_width_number(self):
        """Fallback test: Bad numbers default to 100"""
        # First, demonstrate that 1in is 2.54cm, so unit should be 'cm'.
        self.assertEqual(svg('width="1in" viewBox="0 0 2.54 1"').unit, 'cm')

        # Corrupt the width to contain an invalid number component; note that
        # the units change to 'px'. This is because the corrupt number part is
        # replaced with 100px, producing a width of "100px";
        self.assertEqual(svg('width="ABCDin" viewBox="0 0 2.54 1"').unit, 'px')
Exemplo n.º 4
0
 def test_svg_select_id(self):
     """Select an id from the document"""
     doc = svg('id="bananas"')
     doc.selection.set('bananas')
     self.assertEqual(doc.selection['bananas'], doc)
     self.assertEqual(doc.selection.first(), doc)
     doc = svg('id="apples"')
     doc.selected.set(doc.getElementById('apples'))
     self.assertEqual(doc.selection['apples'], doc)
     self.assertEqual(doc.selection.first(), doc)
Exemplo n.º 5
0
 def test_svg_new_id(self):
     """Test generatign a new id for a given tag"""
     doc = svg('id="apples"')
     usedids = set(['apples'])
     for prefix in ['apples'] * 3:
         newid = doc.get_unique_id(prefix)
         self.assertTrue(newid.startswith(prefix))
         self.assertTrue(newid not in usedids)
         usedids.add(newid)
Exemplo n.º 6
0
 def test_width_and_viewbox_in(self):
     """100mm is ~3.94in, so unit should be 'in'."""
     self.assertEqual(svg('width="100mm" viewBox="0 0 3.94 5.90"').unit, 'in')
Exemplo n.º 7
0
 def test_width_and_viewbox_px(self):
     """100mm is ~377px, so unit should be 'px'."""
     self.assertEqual(svg('width="100mm" viewBox="0 0 377 565"').unit, 'px')
Exemplo n.º 8
0
 def test_non_zero_viewbox_x(self):
     """Demonstrate that a non-zero x value (viewbox[0]) does not affect the width value."""
     self.assertEqual(svg('width="" viewBox="5 7 22 99"').width, 22.0)
Exemplo n.º 9
0
 def test_width_and_viewbox(self):
     """If both are present, width overrides viewBox."""
     self.assertAlmostEqual(svg('width="120mm" viewBox="0 0 22 99"').width, 453.5433071)
Exemplo n.º 10
0
 def test_height_width_and_viewbox(self):
     """100mm is ~23.6pc, so unit should be 'pc'."""
     doc = svg('width="100mm" height="150mm" viewBox="0 0 23.6 35.4"')
     self.assertEqual(doc.unit, 'pc')
Exemplo n.º 11
0
 def test_svg_load(self):
     """Test loading an svg with the right parser"""
     self.assertEqual(type(svg()).__name__, 'SvgDocumentElement')
Exemplo n.º 12
0
 def test_height_and_viewbox(self):
     """If both are present, height overrides viewBox."""
     self.assertEqual(svg('height="330px" viewBox="0 0 22 99"').height, 330)
Exemplo n.º 13
0
 def test_viewbox_only(self):
     """Height from viewBox only"""
     self.assertEqual(svg('viewBox="0 0 22 99"').height, 99.0)
Exemplo n.º 14
0
 def test_empty_height_viewbox(self):
     """Empty values for both should be the same as both missing."""
     self.assertEqual(svg('height="" viewBox=""').height, 0)
Exemplo n.º 15
0
 def test_height_only(self):
     """A simple height only in px"""
     self.assertEqual(svg('height="330px"').height, 330)
Exemplo n.º 16
0
 def test_empty_viewbox(self):
     """An empty viewBox value should be the same as a missing viewBox."""
     self.assertEqual(svg('viewBox=""').height, 0)
Exemplo n.º 17
0
 def test_empty_height(self):
     """An empty height value should be the same as a missing height."""
     self.assertEqual(svg('height=""').height, 0)
Exemplo n.º 18
0
 def test_no_dimensions(self):
     """Test height from blank svg"""
     self.assertEqual(svg().height, 0)
Exemplo n.º 19
0
 def test_unitless_width_and_viewbox(self):
     """Unitless width should be treated as 'px'."""
     # 3779px is ~1m, so unit should be 'm'.
     self.assertEqual(svg('width="3779" viewBox="0 0 1 1.5"').unit, 'm')
Exemplo n.º 20
0
 def test_no_height_valid_viewbox(self):
     """An empty height value should be the same as a missing height."""
     self.assertEqual(svg('height="" viewBox="0 0 22 99"').height, 99.0)
Exemplo n.º 21
0
 def test_height_with_viewbox(self):
     """150mm is ~5.90in, so unit should be 'in', but height is ignored"""
     # TODO: Determine whether returning 'px' in this case is the intended
     #     behavior.
     self.assertEqual(svg('height="150mm" viewBox="0 0 3.94 5.90"').unit, 'px')
Exemplo n.º 22
0
 def test_non_zero_viewbox_y(self):
     """Demonstrate that a non-zero y value (viewbox[1]) does not affect the height value."""
     self.assertEqual(svg('height="" viewBox="5 7 22 99"').height, 99.0)
Exemplo n.º 23
0
 def test_large_error_reverts_to_px(self):
     """'px' instead of using the closest match 'pc'."""
     # 100mm is ~23.6pc; 24.1 is ~2% off from that, so unit should fall back
     self.assertEqual(svg('width="100mm" viewBox="0 0 24.1 35.4"').unit, 'px')
Exemplo n.º 24
0
 def test_width_only(self):
     """Test a fixed width"""
     self.assertAlmostEqual(svg('width="120mm"').width, 453.5433071)
Exemplo n.º 25
0
 def test_viewbox_only(self):
     """IF only the viewBox is present"""
     self.assertEqual(svg('viewBox="0 0 22 99"').width, 22.0)
Exemplo n.º 26
0
 def test_height_only(self):
     """Units from document height only"""
     # TODO: Determine whether returning 'px' in this case is the
     #     intended behavior.
     self.assertEqual(svg('height="100m"').unit, 'px')
Exemplo n.º 27
0
 def test_svg_ids(self):
     """Test a list of ids from an svg document"""
     self.assertEqual(svg('id="apples"').get_ids(), {'apples'})
Exemplo n.º 28
0
 def test_viewbox_only(self):
     """Test viewbox only document units"""
     self.assertEqual(svg('viewBox="0 0 377 565"').unit, 'px')
Exemplo n.º 29
0
 def test_no_dimensions(self):
     """Default units with no arguments"""
     self.assertEqual(svg().unit, 'px')
Exemplo n.º 30
0
 def test_only_valid_viewbox(self):
     """An empty width value should be the same as a missing width."""
     self.assertEqual(svg('width="" viewBox="0 0 22 99"').width, 22.0)