Features: polyglot

polyglot-002

Tests that the cx:python polyglot step returns a map.

Test is expected to pass.

The pipeline

<p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
                xmlns:err="http://www.w3.org/ns/xproc-error" xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:t="http://xproc.org/ns/testsuite/3.0" version="3.0">
   <p:import href="https://xmlcalabash.com/ext/library/polyglot.xpl"/>
   <p:output port="result"/>
   <cx:python parameters="map{'x': 7, 'y': 9, 'now': current-dateTime()}">
      <p:with-input>
         <doc>Test</doc>
      </p:with-input>
      <p:with-option name="args"
                     select="('a', 'b', 'c')"/>
      <p:with-input port="program">
         <p:inline content-type="text/plain"
                   expand-text="false">
import sys
{
  "arguments": sys.argv,
  "x": x,
  "y": y,
  "product": x * y,
  "time": now
}
          </p:inline>
      </p:with-input>
   </cx:python>
   <p:cast-content-type content-type="application/xml"/>
</p:declare-step>

Result

<map xmlns="http://www.w3.org/2005/xpath-functions"
     xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <string key="time">2025-06-19T18:02:33.871190154Z</string>
   <number key="product">63</number>
   <array key="arguments">
      <string>file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/tests/polyglot-002.xml</string>
      <string>a</string>
      <string>b</string>
      <string>c</string>
   </array>
   <number key="x">7</number>
   <number key="y">9</number>
</map>

Schematron checks

<s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron"
          xmlns:t="http://xproc.org/ns/testsuite/3.0" queryBinding="xslt2">
   <s:ns prefix="fn"
         uri="http://www.w3.org/2005/xpath-functions"/>
   <s:pattern>
      <s:rule context="/">
         <s:assert test="fn:map">The result isn’t a map.</s:assert>
      </s:rule>
   </s:pattern>
   <s:pattern>
      <s:rule context="/fn:map">
         <s:assert test="fn:number[@key='product']">No product reported.</s:assert>
         <s:assert test="fn:number[@key='product'] = '63'">The product is incorrect.</s:assert>
         <s:assert test="fn:array[@key='arguments']">The arguments were not reported.</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

03 Jan 2025, Norm Tovey-Walsh
Created test.