summaryrefslogtreecommitdiff
path: root/xstc/xstc-to-python.xsl
blob: 78d55cd664dc5916ee5d2fda49da923ae95dff6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:ts="TestSuite" version="1.0"
	xmlns:xl="http://www.w3.org/1999/xlink">
	<xsl:param name="vendor" select="'NIST'"/>
    <xsl:output method="text"/>   

    <xsl:template match="/">
        <xsl:text>#!/usr/bin/python -u
# -*- coding: UTF-8 -*-
#
# This file is generated from the W3C test suite description file.
#

import xstc
from xstc import XSTCTestRunner, XSTCTestGroup, XSTCSchemaTest, XSTCInstanceTest

xstc.vendor = "</xsl:text><xsl:value-of select="$vendor"/><xsl:text>"

r = XSTCTestRunner()

# Group definitions.
                                 
</xsl:text>
		      
        <xsl:apply-templates select="ts:testSet/ts:testGroup" mode="group-def"/>
<xsl:text>

# Test definitions.

</xsl:text>
		<xsl:apply-templates select="ts:testSet/ts:testGroup" mode="test-def"/>
        <xsl:text>
           
r.run()    

</xsl:text>
            
    </xsl:template>       

	<!-- groupName, descr -->
    <xsl:template match="ts:testGroup" mode="group-def">
		<xsl:text>r.addGroup(XSTCTestGroup("</xsl:text>
		<!-- group -->
		<xsl:value-of select="@name"/><xsl:text>", "</xsl:text>
		<!-- main schema -->
		<xsl:value-of select="ts:schemaTest[1]/ts:schemaDocument/@xl:href"/><xsl:text>", """</xsl:text>
		<!-- group-description -->
		<xsl:call-template name="str">
			<xsl:with-param name="str" select="ts:annotation/ts:documentation/text()"/>
		</xsl:call-template>
		<xsl:text>"""))
</xsl:text>
	</xsl:template>
	
	<xsl:template name="str">
		<xsl:param name="str"/>
		<xsl:choose>
			<xsl:when test="contains($str, '&quot;')">
				<xsl:call-template name="str">
					<xsl:with-param name="str" select="substring-before($str, '&quot;')"/>
				</xsl:call-template>
				<xsl:text>'</xsl:text>
				<xsl:call-template name="str">
					<xsl:with-param name="str" select="substring-after($str, '&quot;')"/>
				</xsl:call-template>
			
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$str"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="ts:testGroup" mode="test-def">	    
		<xsl:param name="group" select="@name"/>
		<xsl:for-each select="ts:schemaTest">
			<!-- groupName, isSchema, Name, Accepted, File, Val, Descr -->
			<xsl:text>r.addTest(XSTCSchemaTest("</xsl:text>
			<!-- group -->
			<xsl:value-of select="$group"/><xsl:text>", "</xsl:text>
			<!-- test-name -->
			<xsl:value-of select="@name"/><xsl:text>", </xsl:text>
			<!-- accepted -->
			<xsl:value-of select="number(ts:current/@status = 'accepted')"/><xsl:text>, "</xsl:text>
			<!-- filename -->			
			<xsl:value-of select="ts:schemaDocument/@xl:href"/><xsl:text>", </xsl:text>
			<!-- validity -->
			<xsl:value-of select="number(ts:expected/@validity = 'valid')"/><xsl:text>, "</xsl:text>
			<!-- test-description -->
			<xsl:value-of select="ts:annotation/ts:documentation/text()"/><xsl:text>"))
</xsl:text>
		</xsl:for-each>
		<xsl:for-each select="ts:instanceTest">
			<!-- groupName, isSchema, Name, Accepted, File, Val, Descr -->
			<xsl:text>r.addTest(XSTCInstanceTest("</xsl:text>
			<!-- group -->
			<xsl:value-of select="$group"/><xsl:text>", "</xsl:text>
			<!-- test-name -->
			<xsl:value-of select="@name"/><xsl:text>", </xsl:text>
			<!-- accepted -->
			<xsl:value-of select="number(ts:current/@status = 'accepted')"/><xsl:text>, "</xsl:text>
			<!-- filename -->			
			<xsl:value-of select="ts:instanceDocument/@xl:href"/><xsl:text>", </xsl:text>
			<!-- validity -->
			<xsl:value-of select="number(ts:expected/@validity = 'valid')"/><xsl:text>, "</xsl:text>
			<!-- test-description -->
			<xsl:value-of select="ts:annotation/ts:documentation/text()"/><xsl:text>"))
</xsl:text>
		</xsl:for-each>
	</xsl:template>                     
        
</xsl:stylesheet>