Пример #1
0
def test_Exp(tester):
    sty = """\
<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:math="http://exslt.org/math"
  version="1.0"
>

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:value-of select="format-number(math:exp(1), '#.###')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number(math:exp(-1), '#.###')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number(math:exp(5), '#.###')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number(math:exp(10), '#.###')"/>
  </xsl:template>

</xsl:stylesheet>
"""
    source = test_harness.FileInfo(string=SOURCE)
    sheet = test_harness.FileInfo(string=sty)
    expected = "2.718 0.368 148.413 22026.466"
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected,
                          title='math:exp()')
    return
Пример #2
0
def Test(tester):
    source = test_harness.FileInfo(string=SOURCE_1)
    sty = test_harness.FileInfo(string=SHEET_1)
    test_harness.XsltTest(tester, source, [sty], EXPECTED_1,
                          title="ft:uri-to-element")

    return
Пример #3
0
def test_ATan2(tester):
    sty = """\
<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:math="http://exslt.org/math"
  version="1.0"
>

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:value-of select="format-number(math:atan2(0.5, 0.5), '#.###')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number(math:atan2(-0.5, -0.5), '#.###')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number(math:atan2(5, 5), '#.###')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number(math:atan2(10, 20), '#.###')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number(math:atan2(-5, -5), '#.###')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number(math:atan2(-10, 10), '#.###')"/>
  </xsl:template>

</xsl:stylesheet>
"""
    source = test_harness.FileInfo(string=SOURCE)
    sheet = test_harness.FileInfo(string=sty)
    expected = "0.785 -2.356 0.785 0.464 -2.356 -0.785"
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected,
                          title='math:atan2()')
    return
Пример #4
0
def test_ACos(tester):
    sty = """\
<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:math="http://exslt.org/math"
  version="1.0"
>

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:variable name='PI' select='math:constant("PI", 20)'/>
    <xsl:value-of select="format-number(math:acos(0), '#.###')"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="format-number(math:acos(-1), '#.###')"/>
  </xsl:template>

</xsl:stylesheet>
"""
    source = test_harness.FileInfo(string=SOURCE)
    sheet = test_harness.FileInfo(string=sty)
    expected = "1.571 3.142"
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected,
                          title='math:acos()')
    return
Пример #5
0
def test_Random(tester):
    sty = """\
<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:math="http://exslt.org/math"
  version="1.0"
>

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:variable name="n" select="math:random()"/>
    <xsl:value-of select='$n >= 0 and 1 > $n'/>
  </xsl:template>

</xsl:stylesheet>
"""
    source = test_harness.FileInfo(string=SOURCE)
    sheet = test_harness.FileInfo(string=sty)
    expected = "true"
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected,
                          title='math:random()')
    return
Пример #6
0
def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(uri='Xml/Xslt/Borrowed/dchudnov.xslt')
    test_harness.XsltTest(tester, source, [sheet], expected_1,
                          title='General XSLT features and processing time')

    return
Пример #7
0
def Test(tester):
    tester.startTest("Checking for BIG5 codec")
    try:
        import codecs
        big5_decoder = codecs.getdecoder('big5')
    except LookupError:
        try:
            from encodings import big5
        except ImportError:
            tester.warning(
                "No BIG5 encoding support for case 1.  You can install \n"
                "BIG5 by downloading and installing ChineseCodes from\n"
                "ftp://python-codecs.sourceforge.net/pub/python-codecs/")
            tester.testDone()
            return
        else:
            big5_decode = big5.decode
    else:
        big5_decode = lambda s: big5_decoder(s)[0]
    tester.testDone()

    b5 = big5_decode(source_1)
    utf8 = b5.encode("utf-8")

    source = test_harness.FileInfo(string=utf8)
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester, source, [sheet], expected_1)

    source = test_harness.FileInfo(string=source_2)
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester, source, [sheet], expected_2)
    return
Пример #8
0
def test_Lowest(tester):
    sty = """\
<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:math="http://exslt.org/math"
  xmlns:common="http://exslt.org/common"
  xmlns:x="http://uche.ogbuji.net/dummy"
  version="1.0"
>

  <xsl:output method="text"/>

  <x:spam>2</x:spam>
  <x:bread>100</x:bread>
  <x:eggs>12.0</x:eggs>

  <xsl:variable name='self' select='document("")/*'/>

  <xsl:template match="/">
    <xsl:variable name='result' select='math:lowest($self/x:*)'/>
    <xsl:value-of select='name($result)'/>
  </xsl:template>

</xsl:stylesheet>
"""
    source = test_harness.FileInfo(string=SOURCE)
    sheet = test_harness.FileInfo(string=sty)
    expected = "x:spam"
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected,
                          title='math:lowest()')
    return
Пример #9
0
def test_closure(tester):
    TRANSFORM = """<?xml version='1.0' encoding='UTF-8'?>
<xsl:transform
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dyn="http://exslt.org/dynamic"
  exclude-result-prefixes="dyn"
  version="1.0"
>

  <xsl:template match="doc">
    <result>
      <xsl:for-each select="dyn:closure(*, '*[@x]')">
        <node>
          <xsl:value-of select="@x"/>
        </node>
      </xsl:for-each>
    </result>
  </xsl:template>

</xsl:transform>
"""

    SOURCE2 = """<doc><a x='1'><e x='2'/></a><b x='3'><f/></b><c><g x='4'/></c><d x='5'><h x='6'/></d></doc>"""

    EXPECTED = '<?xml version="1.0" encoding="UTF-8"?>\n<result><node>2</node><node>4</node><node>6</node></result>'

    source = test_harness.FileInfo(string=SOURCE2)
    transform = test_harness.FileInfo(string=TRANSFORM)
    test_harness.XsltTest(tester,
                          source, [transform],
                          EXPECTED,
                          title='dyn:closure()')
    return
Пример #10
0
def test_map4(tester):

    TRANSFORM = """<?xml version='1.0' encoding='UTF-8'?>
<xsl:transform
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dyn="http://exslt.org/dynamic"
  exclude-result-prefixes="dyn"
  version="1.0"
>

  <xsl:template match="doc">
    <result>
      <xsl:for-each select="dyn:map(*, '. > 2')">
        <num>
          <xsl:copy-of select="."/>
        </num>
      </xsl:for-each>
    </result>
  </xsl:template>

</xsl:transform>
"""

    EXPECTED = '<?xml version="1.0" encoding="UTF-8"?>\n<result><num><exsl:boolean xmlns:exsl="http://exslt.org/common"/></num><num><exsl:boolean xmlns:exsl="http://exslt.org/common"/></num><num><exsl:boolean xmlns:exsl="http://exslt.org/common">true</exsl:boolean></num><num><exsl:boolean xmlns:exsl="http://exslt.org/common">true</exsl:boolean></num></result>'

    source = test_harness.FileInfo(string=SOURCE2)
    transform = test_harness.FileInfo(string=TRANSFORM)
    test_harness.XsltTest(tester,
                          source, [transform],
                          EXPECTED,
                          title='dyn:map() w/boolean expr')
    return
Пример #11
0
def test_map1(tester):
    TRANSFORM = """<?xml version='1.0' encoding='UTF-8'?>
<xsl:transform
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dyn="http://exslt.org/dynamic"
  exclude-result-prefixes="dyn"
  version="1.0"
>

  <xsl:template match="doc">
    <result>
      <xsl:for-each select="dyn:map(*, '@id')">
        <num>
          <xsl:value-of select="."/>
        </num>
      </xsl:for-each>
    </result>
  </xsl:template>

</xsl:transform>
"""

    EXPECTED = '<?xml version="1.0" encoding="UTF-8"?>\n<result><num>1</num><num>2</num><num>3</num><num>4</num></result>'

    source = test_harness.FileInfo(string=SOURCE)
    transform = test_harness.FileInfo(string=TRANSFORM)
    test_harness.XsltTest(tester,
                          source, [transform],
                          EXPECTED,
                          title='dyn:map()')
    return
Пример #12
0
def test_evaluate1(tester):
    TRANSFORM = """<?xml version='1.0' encoding='UTF-8'?>
<xsl:transform
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dyn="http://exslt.org/dynamic"
  exclude-result-prefixes="dyn"
  version="1.0"
>

  <xsl:template match="doc">
    <result>
      <xsl:for-each select="*">
        <num>
          <xsl:value-of select="dyn:evaluate(concat('name(/doc/*[', position(), '])'))"/>
        </num>
      </xsl:for-each>
    </result>
  </xsl:template>

</xsl:transform>
"""

    EXPECTED = '<?xml version="1.0" encoding="UTF-8"?>\n<result><num>otu</num><num>abuo</num><num>ato</num><num>ano</num></result>'

    source = test_harness.FileInfo(string=SOURCE)
    transform = test_harness.FileInfo(string=TRANSFORM)
    test_harness.XsltTest(tester,
                          source, [transform],
                          EXPECTED,
                          title='dyn:evaluate()')
    return
Пример #13
0
def Test(tester):
    source = test_harness.FileInfo(string=SOURCE_1)
    sty = test_harness.FileInfo(string=SHEET_1)
    test_harness.XsltTest(tester,
                          source, [sty],
                          EXPECTED_1,
                          title="f:decode, f:encode and f:raw-text-output")
Пример #14
0
def Test(tester):
    source = test_harness.FileInfo(string="<ignored/>")

    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected,
                          title='Import with variables')

    sheet = test_harness.FileInfo(string=sheet_2)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected,
                          title='Import with params')

    sheet = test_harness.FileInfo(string=error_sheet_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          "",
                          exceptionCode=Error.DUPLICATE_TOP_LEVEL_VAR,
                          title='Include with variables')

    sheet = test_harness.FileInfo(string=error_sheet_2)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          "",
                          exceptionCode=Error.DUPLICATE_TOP_LEVEL_VAR,
                          title='Include with params')
    return
Пример #15
0
def test_Padding(tester):
    sty = """<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:str="http://exslt.org/strings"
  extension-element-prefixes="str"
>

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:copy-of select="str:padding(20, '---4567----23----890----------')"/>
    <xsl:text>&#10;</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>&#10;</xsl:text>
    <xsl:copy-of select="str:padding(10, '+-+')"/>
  </xsl:template>

</xsl:stylesheet>"""

    expected = """\
---4567----23----890
Is this EXSLT? No. no
+-++-++-++"""

    source = test_harness.FileInfo(string=SOURCE)
    sheet = test_harness.FileInfo(string=sty)
    test_harness.XsltTest(tester, source, [sheet], expected,
                          title='str:padding()')
    return
Пример #16
0
def test_Concat(tester):
    src = """\
<a>
  <c>Is this EXSLT? No. no</c>
  <c>Is this EXSLT? No. no</c>
  <c>Is this EXSLT? No. no</c>
</a>
"""
    sty = """\
<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:str="http://exslt.org/strings"
  version="1.0"
>

  <xsl:output method="text"/>

  <xsl:template match="/a">
    <xsl:value-of select="str:concat(c)"/>
  </xsl:template>

</xsl:stylesheet>
"""
    source = test_harness.FileInfo(string=src)
    sheet = test_harness.FileInfo(string=sty)
    expected = "Is this EXSLT? No. no" * 3
    test_harness.XsltTest(tester, source, [sheet], expected,
                          title='str:concat()')
    return
Пример #17
0
def test_Intersection(tester):
    sty = """\
<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:set="http://exslt.org/sets"
  xmlns:x="http://uche.ogbuji.net/dummy"
  version="1.0"
>

  <xsl:output method="text"/>

  <x:spam/>
  <x:eggs/>

  <xsl:variable name='self' select='document("")/*'/>
  <xsl:variable name='empty' select='/parent::*'/>

  <xsl:template match="/">
    <xsl:variable name='result' select='set:intersection($self/x:*, $self/x:spam)'/>
    <xsl:value-of select='count($result)'/>
    <xsl:text> </xsl:text>
    <xsl:value-of select='name($result)'/>
  </xsl:template>

</xsl:stylesheet>
"""
    source = test_harness.FileInfo(string=SOURCE)
    sheet = test_harness.FileInfo(string=sty)
    expected = "1 x:spam"
    test_harness.XsltTest(tester, source, [sheet], expected,
                          title='set:intersection()')
    return
Пример #18
0
def test_Power(tester):
    sty = """\
<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:math="http://exslt.org/math"
  version="1.0"
>

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:value-of select='math:power(2, 2)'/>
    <xsl:text> </xsl:text>
    <xsl:value-of select='math:power(2, -1)'/>
  </xsl:template>

</xsl:stylesheet>
"""
    source = test_harness.FileInfo(string=SOURCE)
    sheet = test_harness.FileInfo(string=sty)
    expected = "4 0.5"
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected,
                          title='math:power()')
    return
Пример #19
0
def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected_1,
                          title='RTF root nodes')
    return
Пример #20
0
def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected_1,
                          title='ordinary Muenchian grouping with keys')
    return
Пример #21
0
def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sty = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester,
                          source, [sty],
                          expected_1,
                          title='basic ft:assign')
    return
Пример #22
0
def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(uri='Xml/Xslt/Borrowed/eratosthenes.xslt')
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected_1,
                          topLevelParams={'bound': 1000})
    return
Пример #23
0
def Test(tester):
    source = test_harness.FileInfo(string=xml_source_1)
    sheet = test_harness.FileInfo(string=sheet_str_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected_1,
                          title="Disable Output Escaping")
    return
Пример #24
0
def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected_1,
                          title='text output method bug')
    return
Пример #25
0
def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected_1,
                          title='Multiple templates with modes')
    return
Пример #26
0
def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected_1,
                          title='namespace copy-through')
    return
Пример #27
0
def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected_1,
                          title='import/variable problems')
    return
Пример #28
0
def Test(tester):
    source = test_harness.FileInfo(string=SOURCE_1)
    sheet = test_harness.FileInfo(string=TRANSFORM_1)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          EXPECTED,
                          title='Simple dynamic map test')
    return
Пример #29
0
def Test(tester):
    source = test_harness.FileInfo(string=xml_source)
    sheet = test_harness.FileInfo(string=sheet_str)
    test_harness.XsltTest(tester,
                          source, [sheet],
                          expected,
                          title="xsl:processing-instruction")
    return
Пример #30
0
def Test(tester):
    tester.startGroup("basic ft:replace function and element")
    source = test_harness.FileInfo(string=source_1)
    sty = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester, source, [sty], expected_1)
    tester.groupDone()

    return