xstc-to-python.xsl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:ts="TestSuite" version="1.0"
  5. xmlns:xl="http://www.w3.org/1999/xlink">
  6. <xsl:param name="vendor" select="'NIST'"/>
  7. <xsl:output method="text"/>
  8. <xsl:template match="/">
  9. <xsl:text>#!/usr/bin/python -u
  10. # -*- coding: UTF-8 -*-
  11. #
  12. # This file is generated from the W3C test suite description file.
  13. #
  14. import xstc
  15. from xstc import XSTCTestRunner, XSTCTestGroup, XSTCSchemaTest, XSTCInstanceTest
  16. xstc.vendor = "</xsl:text><xsl:value-of select="$vendor"/><xsl:text>"
  17. r = XSTCTestRunner()
  18. # Group definitions.
  19. </xsl:text>
  20. <xsl:apply-templates select="ts:testSet/ts:testGroup" mode="group-def"/>
  21. <xsl:text>
  22. # Test definitions.
  23. </xsl:text>
  24. <xsl:apply-templates select="ts:testSet/ts:testGroup" mode="test-def"/>
  25. <xsl:text>
  26. r.run()
  27. </xsl:text>
  28. </xsl:template>
  29. <!-- groupName, descr -->
  30. <xsl:template match="ts:testGroup" mode="group-def">
  31. <xsl:text>r.addGroup(XSTCTestGroup("</xsl:text>
  32. <!-- group -->
  33. <xsl:value-of select="@name"/><xsl:text>", "</xsl:text>
  34. <!-- main schema -->
  35. <xsl:value-of select="ts:schemaTest[1]/ts:schemaDocument/@xl:href"/><xsl:text>", """</xsl:text>
  36. <!-- group-description -->
  37. <xsl:call-template name="str">
  38. <xsl:with-param name="str" select="ts:annotation/ts:documentation/text()"/>
  39. </xsl:call-template>
  40. <xsl:text>"""))
  41. </xsl:text>
  42. </xsl:template>
  43. <xsl:template name="str">
  44. <xsl:param name="str"/>
  45. <xsl:choose>
  46. <xsl:when test="contains($str, '&quot;')">
  47. <xsl:call-template name="str">
  48. <xsl:with-param name="str" select="substring-before($str, '&quot;')"/>
  49. </xsl:call-template>
  50. <xsl:text>'</xsl:text>
  51. <xsl:call-template name="str">
  52. <xsl:with-param name="str" select="substring-after($str, '&quot;')"/>
  53. </xsl:call-template>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. <xsl:value-of select="$str"/>
  57. </xsl:otherwise>
  58. </xsl:choose>
  59. </xsl:template>
  60. <xsl:template match="ts:testGroup" mode="test-def">
  61. <xsl:param name="group" select="@name"/>
  62. <xsl:for-each select="ts:schemaTest">
  63. <!-- groupName, isSchema, Name, Accepted, File, Val, Descr -->
  64. <xsl:text>r.addTest(XSTCSchemaTest("</xsl:text>
  65. <!-- group -->
  66. <xsl:value-of select="$group"/><xsl:text>", "</xsl:text>
  67. <!-- test-name -->
  68. <xsl:value-of select="@name"/><xsl:text>", </xsl:text>
  69. <!-- accepted -->
  70. <xsl:value-of select="number(ts:current/@status = 'accepted')"/><xsl:text>, "</xsl:text>
  71. <!-- filename -->
  72. <xsl:value-of select="ts:schemaDocument/@xl:href"/><xsl:text>", </xsl:text>
  73. <!-- validity -->
  74. <xsl:value-of select="number(ts:expected/@validity = 'valid')"/><xsl:text>, "</xsl:text>
  75. <!-- test-description -->
  76. <xsl:value-of select="ts:annotation/ts:documentation/text()"/><xsl:text>"))
  77. </xsl:text>
  78. </xsl:for-each>
  79. <xsl:for-each select="ts:instanceTest">
  80. <!-- groupName, isSchema, Name, Accepted, File, Val, Descr -->
  81. <xsl:text>r.addTest(XSTCInstanceTest("</xsl:text>
  82. <!-- group -->
  83. <xsl:value-of select="$group"/><xsl:text>", "</xsl:text>
  84. <!-- test-name -->
  85. <xsl:value-of select="@name"/><xsl:text>", </xsl:text>
  86. <!-- accepted -->
  87. <xsl:value-of select="number(ts:current/@status = 'accepted')"/><xsl:text>, "</xsl:text>
  88. <!-- filename -->
  89. <xsl:value-of select="ts:instanceDocument/@xl:href"/><xsl:text>", </xsl:text>
  90. <!-- validity -->
  91. <xsl:value-of select="number(ts:expected/@validity = 'valid')"/><xsl:text>, "</xsl:text>
  92. <!-- test-description -->
  93. <xsl:value-of select="ts:annotation/ts:documentation/text()"/><xsl:text>"))
  94. </xsl:text>
  95. </xsl:for-each>
  96. </xsl:template>
  97. </xsl:stylesheet>