teststyleref.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2007 Søren Roug, European Environment Agency
  4. #
  5. # This is free software. You may redistribute it under the terms
  6. # of the Apache license and the GNU General Public License Version
  7. # 2 or at your option any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public
  15. # License along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. # Contributor(s):
  19. #
  20. import unittest
  21. from odf import dr3d, draw, office, style
  22. from odf.element import IllegalChild
  23. class TestStyleRefs(unittest.TestCase):
  24. def testTxtStylename(self):
  25. """ Check that 'name' is required """
  26. self.assertRaises(AttributeError, dr3d.Cube, stylename="Bold")
  27. def testBadFamily(self):
  28. """ Family must be graphic or presentation """
  29. boldstyle = style.Style(name='Bold', family="paragraph")
  30. self.assertRaises(ValueError, dr3d.Cube,stylename=boldstyle)
  31. self.assertRaises(ValueError, dr3d.Cube, stylename=boldstyle)
  32. self.assertRaises(ValueError, dr3d.Extrude, stylename=boldstyle, d="x", viewbox="0 0 1000 1000")
  33. self.assertRaises(ValueError, dr3d.Rotate, stylename=boldstyle, d="x", viewbox="0 0 1000 1000")
  34. self.assertRaises(ValueError, dr3d.Scene, stylename=boldstyle)
  35. self.assertRaises(ValueError, dr3d.Sphere, stylename=boldstyle)
  36. self.assertRaises(ValueError, draw.Caption, stylename=boldstyle)
  37. self.assertRaises(ValueError, draw.Circle, stylename=boldstyle)
  38. self.assertRaises(ValueError, draw.Connector, stylename=boldstyle)
  39. self.assertRaises(ValueError, draw.Control, stylename=boldstyle, control="x")
  40. self.assertRaises(ValueError, draw.CustomShape, stylename=boldstyle)
  41. self.assertRaises(ValueError, draw.Ellipse, stylename=boldstyle)
  42. self.assertRaises(ValueError, draw.Frame, stylename=boldstyle)
  43. self.assertRaises(ValueError, draw.G, stylename=boldstyle)
  44. self.assertRaises(ValueError, draw.Line, stylename=boldstyle, x1="0", y1="0", x2="1", y2="1")
  45. self.assertRaises(ValueError, draw.Measure, stylename=boldstyle, x1="0", y1="0", x2="1", y2="1")
  46. self.assertRaises(ValueError, draw.PageThumbnail, stylename=boldstyle)
  47. self.assertRaises(ValueError, draw.Path, stylename=boldstyle, d="x", viewbox="0 0 1000 1000")
  48. self.assertRaises(ValueError, draw.Polygon, stylename=boldstyle, points=((0,0),(1,1)), viewbox="0 0 1000 1000")
  49. self.assertRaises(ValueError, draw.Polygon, stylename=boldstyle, points="0,0 1,1", viewbox="0 0 1000 1000")
  50. self.assertRaises(ValueError, draw.Polyline, stylename=boldstyle, points="0,0 1,1", viewbox="0 0 1000 1000")
  51. self.assertRaises(ValueError, draw.Rect, stylename=boldstyle)
  52. self.assertRaises(ValueError, draw.RegularPolygon, stylename=boldstyle, corners="x")
  53. self.assertRaises(ValueError, office.Annotation, stylename=boldstyle)
  54. def testCalls(self):
  55. """ Simple calls """
  56. for family in ("graphic","presentation"):
  57. boldstyle = style.Style(name='Bold', family=family)
  58. dr3d.Cube(stylename=boldstyle)
  59. dr3d.Extrude(stylename=boldstyle, d="x", viewbox="0 0 1000 1000")
  60. dr3d.Rotate(stylename=boldstyle, d="x", viewbox="0 0 1000 1000")
  61. dr3d.Scene(stylename=boldstyle)
  62. dr3d.Sphere(stylename=boldstyle)
  63. draw.Caption(stylename=boldstyle)
  64. draw.Circle(stylename=boldstyle)
  65. draw.Connector(stylename=boldstyle, viewbox="0 0 1000 1000")
  66. draw.Control(stylename=boldstyle, control="x")
  67. draw.CustomShape(stylename=boldstyle)
  68. draw.Ellipse(stylename=boldstyle)
  69. draw.Frame(stylename=boldstyle)
  70. draw.G(stylename=boldstyle)
  71. draw.Line(stylename=boldstyle, x1="0%", y1="0%", x2="100%", y2="100%")
  72. draw.Measure(stylename=boldstyle, x1="0cm", y1="0cm", x2="100%", y2="100%")
  73. draw.PageThumbnail(stylename=boldstyle)
  74. draw.Path(stylename=boldstyle, d="x", viewbox="0 0 1000 1000")
  75. draw.Polygon(stylename=boldstyle, points=((0,0),(1,1)), viewbox="0 0 1000 1000")
  76. draw.Polygon(stylename=boldstyle, points="0,0 1,1", viewbox="0 0 1000 1000")
  77. draw.Polyline(stylename=boldstyle, points="0,0 1,1", viewbox="0 0 1000 1000")
  78. draw.Rect(stylename=boldstyle)
  79. draw.RegularPolygon(stylename=boldstyle, corners="x")
  80. office.Annotation(stylename=boldstyle)
  81. if __name__ == '__main__':
  82. unittest.main()