Пример #1
0
 def testCmp_00(self):
     """Dim() cmp() [00]."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(72, 'px')
     #print myObj_0 == myObj_1
     self.assertEqual(myObj_0, myObj_1)
     self.assertTrue(myObj_0 == myObj_1)
Пример #2
0
 def testConvertFails(self):
     """Dim() convert() fails."""
     myObj = Coord.Dim(72, 'WTF')
     self.assertRaises(Coord.ExceptionCoordUnitConvert, myObj.convert, 'in')
     myObj = Coord.Dim(72, 'px')
     self.assertRaises(Coord.ExceptionCoordUnitConvert, myObj.convert,
                       'WTF')
Пример #3
0
 def testAdd(self):
     """Dim() addition."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(18, 'px')
     myResult = myObj_0 + myObj_1
     #print myResult
     self.assertEqual(myResult.value, 1.25)
     self.assertEqual(myResult.units, 'in')
Пример #4
0
 def testSub(self):
     """Dim() subtraction."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(18, 'px')
     myResult = myObj_0 - myObj_1
     #print myResult
     self.assertEqual(myResult.value, 0.75)
     self.assertEqual(myResult.units, 'in')
Пример #5
0
 def testIadd_00(self):
     """Dim() +=."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(18, 'px')
     myObj_0 += myObj_1
     #print myObj
     self.assertEqual(myObj_0.value, 1.25)
     self.assertEqual(myObj_0.units, 'in')
Пример #6
0
 def testStr(self):
     """Pt() __str__()."""
     myPt = Coord.Pt(
         Coord.Dim(12, 'px'),
         Coord.Dim(24, 'px'),
     )
     #print myPt
     self.assertEqual(str(myPt), 'Pt(x=Dim(12px), y=Dim(24px))')
Пример #7
0
 def testConstructor(self):
     """Pt() constructor."""
     myPt = Coord.Pt(
         Coord.Dim(12, 'px'),
         Coord.Dim(24, 'px'),
     )
     #print myPt
     self.assertEqual(myPt.x, Coord.Dim(12, 'px'))
     self.assertEqual(myPt.y, Coord.Dim(24, 'px'))
Пример #8
0
 def testSum_00(self):
     """Dim() sum(...) raises type error [00]."""
     myObj_0 = Coord.Dim(71, 'px')
     myObj_1 = Coord.Dim(72, 'px')
     try:
         sum([myObj_0, myObj_1])
         self.fail('TypeError not raised')
     except TypeError:
         pass
Пример #9
0
 def testCmp_03(self):
     """Dim() cmp() [03]."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(73, 'px')
     self.assertFalse(myObj_0 == myObj_1)
     self.assertTrue(myObj_0 <= myObj_1)
     self.assertFalse(myObj_0 >= myObj_1)
     self.assertTrue(myObj_0 != myObj_1)
     self.assertTrue(myObj_0 < myObj_1)
     self.assertFalse(myObj_0 > myObj_1)
Пример #10
0
    def test_00(self):
        """TestSVGWriter.test_00(): construction."""
        myViewPort = Coord.Box(
            Coord.Dim(100, 'mm'),
            Coord.Dim(20, 'mm'),
        )
        with SVGWriter.SVGWriter(myViewPort) as xS:
            pass
        # print()
        # print(xS.getvalue())
        self.assertEqual(
            xS.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="20.0mm" version="1.1" width="100.0mm" xmlns="http://www.w3.org/2000/svg" />\n"""
        )
Пример #11
0
 def testConvert(self):
     """Dim() convert()."""
     myObj = Coord.Dim(72, 'px')
     myObj = myObj.convert('px')
     self.assertEqual(myObj.value, 72)
     self.assertEqual(myObj.units, 'px')
     myObj = myObj.convert('in')
     self.assertEqual(myObj.value, 1.0)
     self.assertEqual(myObj.units, 'in')
Пример #12
0
 def test_convertPt(self):
     myPt = Coord.Pt(
         Coord.Dim(72, 'px'),
         Coord.Dim(36, 'px'),
     )
     myResult = Coord.convertPt(myPt, 'in')
     expected = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(0.5, 'in'),
     )
     # print()
     # print(myResult)
     self.assertEqual(myResult, expected)
Пример #13
0
 def test_zeroBaseUnitsPad(self):
     myPad = Coord.zeroBaseUnitsPad()
     # print()
     # print(myPad)
     self.assertEqual(
         myPad,
         Coord.Pad(prev=Coord.Dim(0.0, 'px'),
                   next=Coord.Dim(0.0, 'px'),
                   parent=Coord.Dim(0.0, 'px'),
                   child=Coord.Dim(0.0, 'px')))
Пример #14
0
 def testCmp_01(self):
     """Pt() cmp() is -1 for x."""
     myPt_0 = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(2, 'in'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(73, 'px'),
         Coord.Dim(12, 'pc'),
     )
     self.assertTrue(myPt_0 < myPt_1)
Пример #15
0
 def testCmp_04(self):
     """Pt() cmp() is +1 for y."""
     myPt_0 = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(2, 'in'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(72, 'px'),
         Coord.Dim(11, 'pc'),
     )
     self.assertTrue(myPt_0 > myPt_1)
Пример #16
0
 def testCmp_00(self):
     """Pt() cmp() is 0."""
     myPt_0 = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(2, 'in'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(72, 'px'),
         Coord.Dim(12, 'pc'),
     )
     self.assertEqual(myPt_0, myPt_1)
     self.assertTrue(myPt_0 == myPt_1)
Пример #17
0
 def testConvert_00(self):
     """Pt() convert() [00]."""
     myPt_0 = Coord.Pt(
         Coord.Dim(1, 'in'),
         Coord.Dim(2, 'in'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(72, 'px'),
         Coord.Dim(12, 'pc'),
     )
     myPt_1 = myPt_1.convert('in')
     #print myPt_1
     self.assertEqual(myPt_0, myPt_1)
     self.assertTrue(myPt_0 == myPt_1)
Пример #18
0
 def testConvert_01(self):
     """Pt() convert() [01]."""
     myPt_0 = Coord.Pt(
         Coord.Dim(20, 'mm'),
         Coord.Dim(10, 'mm'),
     )
     myPt_1 = Coord.Pt(
         Coord.Dim(20 * 72 / 25.4, 'px'),
         Coord.Dim(10 * 72 / 25.4, 'px'),
     )
     myPt_0 = myPt_0.convert('px')
     #print myPt_1
     self.assertEqual(myPt_0, myPt_1)
     self.assertTrue(myPt_0 == myPt_1)
Пример #19
0
 def test_scale(self):
     """Pt() scale() [01]."""
     myPt = Coord.Pt(
         Coord.Dim(8, 'mm'),
         Coord.Dim(4, 'mm'),
     )
     expected = Coord.Pt(
         Coord.Dim(4, 'mm'),
         Coord.Dim(2, 'mm'),
     )
     myPt_scaled = myPt.scale(0.5)
     #print myPt_1
     self.assertEqual(myPt_scaled, expected)
     self.assertTrue(myPt_scaled == expected)
Пример #20
0
    def test_07(self):
        """TestSVGlWriter.test_07(): text.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/text.html#TextElement"""
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myViewPort,
                                 {'viewBox': "0 0 1000 300"}) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters("Example text01 - 'Hello, out there' in blue")
            myPt = Coord.Pt(Coord.baseUnitsDim(250), Coord.baseUnitsDim(150))
            with SVGWriter.SVGText(xS, myPt, "Verdans", 55, {'fill': "blue"}):
                xS.characters('Hello, out there')
            #xS.comment(" Show outline of canvas using 'rect' element ")
            myPt = Coord.Pt(Coord.baseUnitsDim(1), Coord.baseUnitsDim(1))
            myBx = Coord.Box(Coord.baseUnitsDim(998), Coord.baseUnitsDim(298))
            with SVGWriter.SVGRect(xS, myPt, myBx, {
                    'fill': "none",
                    'stroke': "blue",
                    'stroke-width': "2"
            }):
                pass
        #print
        #print xS.getvalue()
        self.assertEqual(
            xS.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="4.00cm" version="1.1" viewBox="0 0 1000 300" width="12.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Example text01 - &apos;Hello, out there&apos; in blue</desc>
  <text fill="blue" font-family="Verdans" font-size="55" x="250px" y="150px">Hello, out there</text>
  <rect fill="none" height="298px" stroke="blue" stroke-width="2" width="998px" x="1px" y="1px" />
</svg>
""")
Пример #21
0
    def test_06(self):
        """TestSVGlWriter.test_06(): a polygon.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/shapes.html#PolygonElement"""
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myViewPort,
                                 {'viewBox': "0 0 1200 400"}) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters(
                    'Example line01 - lines expressed in user coordinates')
            #xS.comment(" Show outline of canvas using 'rect' element ")
            myPt = Coord.Pt(Coord.baseUnitsDim(1), Coord.baseUnitsDim(1))
            myBx = Coord.Box(Coord.baseUnitsDim(1198), Coord.baseUnitsDim(398))
            with SVGWriter.SVGRect(xS, myPt, myBx, {
                    'fill': "none",
                    'stroke': "blue",
                    'stroke-width': "2"
            }):
                pass
            # Make a group
            with SVGWriter.SVGPolygon(xS, [
                    Coord.Pt(Coord.baseUnitsDim(350), Coord.baseUnitsDim(75)),
                    Coord.Pt(Coord.baseUnitsDim(379), Coord.baseUnitsDim(161)),
                    Coord.Pt(Coord.baseUnitsDim(469), Coord.baseUnitsDim(161)),
                    Coord.Pt(Coord.baseUnitsDim(397), Coord.baseUnitsDim(215)),
                    Coord.Pt(Coord.baseUnitsDim(423), Coord.baseUnitsDim(301)),
                    Coord.Pt(Coord.baseUnitsDim(350), Coord.baseUnitsDim(250)),
                    Coord.Pt(Coord.baseUnitsDim(277), Coord.baseUnitsDim(301)),
                    Coord.Pt(Coord.baseUnitsDim(303), Coord.baseUnitsDim(215)),
                    Coord.Pt(Coord.baseUnitsDim(231), Coord.baseUnitsDim(161)),
                    Coord.Pt(Coord.baseUnitsDim(321), Coord.baseUnitsDim(161)),
            ], {
                    'fill': 'red',
                    'stroke': 'blue',
                    'stroke-width': "10"
            }):
                pass
        #print
        #print xS.getvalue()
        self.assertEqual(
            xS.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="4.00cm" version="1.1" viewBox="0 0 1200 400" width="12.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Example line01 - lines expressed in user coordinates</desc>
  <rect fill="none" height="398px" stroke="blue" stroke-width="2" width="1198px" x="1px" y="1px" />
  <polygon fill="red" points="350,75 379,161 469,161 397,215 423,301 350,250 277,301 303,215 231,161 321,161" stroke="blue" stroke-width="10" />
</svg>
""")
Пример #22
0
    def test_05(self):
        """TestSVGlWriter.test_05(): a polyline.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/shapes.html#PolylineElement"""
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myViewPort,
                                 {'viewBox': "0 0 1200 400"}) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters(
                    'Example line01 - lines expressed in user coordinates')
            #xS.comment(" Show outline of canvas using 'rect' element ")
            myPt = Coord.Pt(Coord.baseUnitsDim(1), Coord.baseUnitsDim(1))
            myBx = Coord.Box(Coord.baseUnitsDim(1198), Coord.baseUnitsDim(398))
            with SVGWriter.SVGRect(xS, myPt, myBx, {
                    'fill': "none",
                    'stroke': "blue",
                    'stroke-width': "2"
            }):
                pass
            # Make a group
            with SVGWriter.SVGPolyline(xS, [
                    Coord.Pt(Coord.baseUnitsDim(50), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(150), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(150), Coord.baseUnitsDim(325)),
                    Coord.Pt(Coord.baseUnitsDim(250), Coord.baseUnitsDim(325)),
                    Coord.Pt(Coord.baseUnitsDim(250), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(350), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(350), Coord.baseUnitsDim(250)),
                    Coord.Pt(Coord.baseUnitsDim(450), Coord.baseUnitsDim(250)),
                    Coord.Pt(Coord.baseUnitsDim(450), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(550), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(550), Coord.baseUnitsDim(175)),
                    Coord.Pt(Coord.baseUnitsDim(650), Coord.baseUnitsDim(175)),
                    Coord.Pt(Coord.baseUnitsDim(650), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(750), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(750), Coord.baseUnitsDim(100)),
                    Coord.Pt(Coord.baseUnitsDim(850), Coord.baseUnitsDim(100)),
                    Coord.Pt(Coord.baseUnitsDim(850), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(950), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(950), Coord.baseUnitsDim(25)),
                    Coord.Pt(Coord.baseUnitsDim(1050), Coord.baseUnitsDim(25)),
                    Coord.Pt(Coord.baseUnitsDim(1050),
                             Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(1150),
                             Coord.baseUnitsDim(375)),
            ], {
                    'fill': 'none',
                    'stroke': 'blue',
                    'stroke-width': "5"
            }):
                pass
        #print
        #print xS.getvalue()
        self.assertEqual(
            xS.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="4.00cm" version="1.1" viewBox="0 0 1200 400" width="12.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Example line01 - lines expressed in user coordinates</desc>
  <rect fill="none" height="398px" stroke="blue" stroke-width="2" width="1198px" x="1px" y="1px" />
  <polyline fill="none" points="50,375 150,375 150,325 250,325 250,375 350,375 350,250 450,250 450,375 550,375 550,175 650,175 650,375 750,375 750,100 850,100 850,375 950,375 950,25 1050,25 1050,375 1150,375" stroke="blue" stroke-width="5" />
</svg>
""")
Пример #23
0
    def test_04(self):
        """TestSVGlWriter.test_04(): a line.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/shapes.html#LineElement"""
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myViewPort) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters(
                    'Example line01 - lines expressed in user coordinates')
            #xS.comment(" Show outline of canvas using 'rect' element ")
            myPt = Coord.Pt(Coord.baseUnitsDim(1), Coord.baseUnitsDim(1))
            myBx = Coord.Box(Coord.baseUnitsDim(1198), Coord.baseUnitsDim(398))
            with SVGWriter.SVGRect(xS, myPt, myBx, {
                    'fill': "none",
                    'stroke': "blue",
                    'stroke-width': "2"
            }):
                pass
            # Make a group
            with SVGWriter.SVGGroup(xS, {'stroke': 'green'}):
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(100),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(300),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "5"}):
                    pass
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(300),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(500),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "10"}):
                    pass
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(500),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(700),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "15"}):
                    pass
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(700),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(900),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "20"}):
                    pass
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(900),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(1100),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "25"}):
                    pass
        #print
        #print xS.getvalue()
        self.assertEqual(
            xS.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="4.00cm" version="1.1" width="12.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Example line01 - lines expressed in user coordinates</desc>
  <rect fill="none" height="398px" stroke="blue" stroke-width="2" width="1198px" x="1px" y="1px" />
  <g stroke="green">
    <line stroke-width="5" x1="100px" x2="300px" y1="300px" y2="100px" />
    <line stroke-width="10" x1="300px" x2="500px" y1="300px" y2="100px" />
    <line stroke-width="15" x1="500px" x2="700px" y1="300px" y2="100px" />
    <line stroke-width="20" x1="700px" x2="900px" y1="300px" y2="100px" />
    <line stroke-width="25" x1="900px" x2="1100px" y1="300px" y2="100px" />
  </g>
</svg>
""")
Пример #24
0
    def test_03(self):
        """TestSVGlWriter.test_03(): an elipse.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/shapes.html#EllipseElement"""
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myViewPort) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters('Example ellipse01 - examples of ellipses')
            #xS.comment(" Show outline of canvas using 'rect' element ")
            myPt = Coord.Pt(Coord.baseUnitsDim(1), Coord.baseUnitsDim(1))
            myBx = Coord.Box(Coord.baseUnitsDim(1198), Coord.baseUnitsDim(398))
            with SVGWriter.SVGRect(xS, myPt, myBx, {
                    'fill': "none",
                    'stroke': "blue",
                    'stroke-width': "2"
            }):
                pass
            myPt = Coord.Pt(Coord.baseUnitsDim(600), Coord.baseUnitsDim(200))
            myRadX = Coord.baseUnitsDim(250)
            myRadY = Coord.baseUnitsDim(100)
            with SVGWriter.SVGElipse(xS, myPt, myRadX, myRadY, {
                    'fill': "red",
                    'stroke': "blue",
                    'stroke-width': "10"
            }):
                pass
        #print
        #print xS.getvalue()
        self.assertEqual(
            xS.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="4.00cm" version="1.1" width="12.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Example ellipse01 - examples of ellipses</desc>
  <rect fill="none" height="398px" stroke="blue" stroke-width="2" width="1198px" x="1px" y="1px" />
  <elipse cx="600px" cy="200px" fill="red" rx="250px" ry="100px" stroke="blue" stroke-width="10" />
</svg>
""")
Пример #25
0
 def testIsub_00(self):
     """Dim() -=."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_0 -= Coord.Dim(18, 'px')
     self.assertEqual(myObj_0.value, 0.75)
     self.assertEqual(myObj_0.units, 'in')
Пример #26
0
 def testIadd_01(self):
     """Dim() += when initial units are None."""
     myObj_0 = Coord.Dim(12, None)
     myObj_0 += Coord.Dim(18, 'px')
     self.assertEqual(myObj_0.value, 30)
     self.assertEqual(myObj_0.units, 'px')
Пример #27
0
 def testStr(self):
     """Dim() __str__()."""
     myObj = Coord.Dim(12, 'px')
     self.assertEqual(str(myObj), 'Dim(12px)')
Пример #28
0
 def testConstructor(self):
     """Dim() constructor."""
     myObj = Coord.Dim(12, 'px')
     #print myObj
     self.assertEqual(myObj.value, 12)
     self.assertEqual(myObj.units, 'px')
Пример #29
0
    def test_01(self):
        """TestSVGlWriter.test_01(): <desc> and four rectangles.
        From second example in http://www.w3.org/TR/2003/REC-SVG11-20030114/struct.html#NewDocumentOverview"""
        myViewPort = Coord.Box(
            Coord.Dim(5, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myViewPort) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters('Four separate rectangles')
            myPt = Coord.Pt(Coord.Dim(0.5, 'cm'), Coord.Dim(0.5, 'cm'))
            myBx = Coord.Box(Coord.Dim(2.0, 'cm'), Coord.Dim(1.0, 'cm'))
            with SVGWriter.SVGRect(xS, myPt, myBx):
                pass
            myPt = Coord.Pt(Coord.Dim(0.5, 'cm'), Coord.Dim(2.0, 'cm'))
            myBx = Coord.Box(Coord.Dim(1.0, 'cm'), Coord.Dim(1.5, 'cm'))
            with SVGWriter.SVGRect(xS, myPt, myBx):
                pass
            myPt = Coord.Pt(Coord.Dim(3.0, 'cm'), Coord.Dim(0.5, 'cm'))
            myBx = Coord.Box(Coord.Dim(1.5, 'cm'), Coord.Dim(2.0, 'cm'))
            with SVGWriter.SVGRect(xS, myPt, myBx):
                pass
            myPt = Coord.Pt(Coord.Dim(3.5, 'cm'), Coord.Dim(3.0, 'cm'))
            myBx = Coord.Box(Coord.Dim(1.0, 'cm'), Coord.Dim(0.5, 'cm'))
            with SVGWriter.SVGRect(xS, myPt, myBx):
                pass
            myPt = Coord.Pt(Coord.Dim(0.01, 'cm'), Coord.Dim(0.01, 'cm'))
            myBx = Coord.Box(Coord.Dim(4.98, 'cm'), Coord.Dim(3.98, 'cm'))
            with SVGWriter.SVGRect(xS,
                                   myPt,
                                   myBx,
                                   attrs={
                                       'fill': "none",
                                       'stroke': "blue",
                                       'stroke-width': ".02cm",
                                   }):
                pass
        #print
        #print xS.getvalue()
        self.assertEqual(
            xS.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="4.00cm" version="1.1" width="5.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Four separate rectangles</desc>
  <rect height="1.00cm" width="2.00cm" x="0.50cm" y="0.50cm" />
  <rect height="1.50cm" width="1.00cm" x="0.50cm" y="2.00cm" />
  <rect height="2.00cm" width="1.50cm" x="3.00cm" y="0.50cm" />
  <rect height="0.50cm" width="1.00cm" x="3.50cm" y="3.00cm" />
  <rect fill="none" height="3.98cm" stroke="blue" stroke-width=".02cm" width="4.98cm" x="0.01cm" y="0.01cm" />
</svg>
""")
Пример #30
0
 def testUnitRange(self):
     """Tests the units are in range."""
     self.assertEqual(
         set(Coord.units()),
         set([None, 'cm', 'in', 'mm', 'pc', 'pt', 'px']),
     )