Re: Advice On Testing With XML

Tennis Smith <[email protected]> Thu, 9 Jul 2009 14:20:53 -0700
Newsgroups gmane.comp.python.xml
Message-ID <[email protected]>
--===============1995674055==
Content-Type: multipart/alternative; boundary=0016e64f918e71b08b046e4c6f81

--0016e64f918e71b08b046e4c6f81
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

On Thu, Jul 9, 2009 at 1:13 PM, Stefan Behnel <[email protected]> wrote:

> Hi,
>
> Tennis Smith wrote:
> > First, a little background.  My charter is to generate XML test messages
> to
> > make sure we process them correctly.  These messages are validated
> against a
> > schema.  I'm using generateDS to generate the test messages.  This
> ensures
> > the xml is correct.
>
> Hmm, I never (really) used generateDS. AFAIR, it generates Python objects
> that you work with. Does it validate their structure while you do so? Or
> did you refer to the schema validation that "ensures" the message
> correctness?


genDS ensures correctness because there are several layers of object types
cascaded in the schema.  Since genDS creates wrappers for all these, it
makes creating schema-compliant objects really easy.


>
>
> > Everything works great except for one problem that keeps cropping up.
>  Some
> > elements cannot be defined easily ahead of time when generating the final
> > test document.
> >
> > For example, a field of type "xs:date" will have to be modifed because
> tests
> > are based on a relative date, not an absolute one. That is, dates in
> tests
> > are based on things like "3 days before today".
> >
> > Therefore, I'd like to figure out some way to change certain fields like
> > date so that I can pass a string and _still validate_ it against the
> > schema.  Using the example, "-3" would be passed in the date field so
> that
> > the test harness will recognize it as "today - 3 days".
>
> Why can't you just write the corresponding date into the messages when you
> generate them?


The messages are generated long before they are actually transmitted.  There
are literally thousands of tests which are created this way.  After
generation, they're stored in svn and then used much later.

> Put another way, the goal is to make this:
> *  <xs:element maxOccurs="1" minOccurs="0" name="date" type="xs:date"/>*
> ...behave like this:
>  *<xs:element maxOccurs="1" minOccurs="0" name="date" type="xs:string"/>*
>
> Naturally, I can edit and copy/paste into a completely new schema file.
But
> I was hoping someone could tell me if I can do some kind of XSLT or
whatever
> to get the same effect.

I'd just change the schema on the way in. You didn't say what tool you use
> for validation, but at least in lxml, modifying the schema tree is pretty
> trivial. You can simply use XPath to find all date types and then fix their
> type attribute.


The tool I'm using is etree.  That's a great suggestion concerning xpath.
That sounds pretty easy.

Thanks, Stefan!


>
>
> Stefan
>
>

--0016e64f918e71b08b046e4c6f81
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><br><div class=3D"gmail_quote">On Thu, Jul 9, 2009 at 1:13 PM, Stefan B=
ehnel <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]">stefan_m=
[email protected]</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" styl=
e=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; =
padding-left: 1ex;">

Hi,<br>
<div class=3D"im"><br>
Tennis Smith wrote:<br>
&gt; First, a little background. =A0My charter is to generate XML test mess=
ages to<br>
&gt; make sure we process them correctly. =A0These messages are validated a=
gainst a<br>
&gt; schema. =A0I&#39;m using generateDS to generate the test messages. =A0=
This ensures<br>
&gt; the xml is correct.<br>
<br>
</div>Hmm, I never (really) used generateDS. AFAIR, it generates Python obj=
ects<br>
that you work with. Does it validate their structure while you do so? Or<br=
>
did you refer to the schema validation that &quot;ensures&quot; the message=
 correctness?</blockquote><div><br>genDS ensures correctness because there =
are several layers of object types cascaded in the schema.=A0 Since genDS c=
reates wrappers for all these, it makes creating schema-compliant objects r=
eally easy.<br>

<br></div><blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid=
 rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<div class=3D"im"><br>
<br>
&gt; Everything works great except for one problem that keeps cropping up. =
=A0Some<br>
&gt; elements cannot be defined easily ahead of time when generating the fi=
nal<br>
&gt; test document.<br>
&gt;<br>
&gt; For example, a field of type &quot;xs:date&quot; will have to be modif=
ed because tests<br>
&gt; are based on a relative date, not an absolute one. That is, dates in t=
ests<br>
&gt; are based on things like &quot;3 days before today&quot;.<br>
&gt;<br>
&gt; Therefore, I&#39;d like to figure out some way to change certain field=
s like<br>
&gt; date so that I can pass a string and _still validate_ it against the<b=
r>
&gt; schema. =A0Using the example, &quot;-3&quot; would be passed in the da=
te field so that<br>
&gt; the test harness will recognize it as &quot;today - 3 days&quot;.<br>
<br>
</div>Why can&#39;t you just write the corresponding date into the messages=
 when you<br>
generate them?</blockquote><div class=3D"im"><br>The messages are generated=
 long before they are actually transmitted.=A0 There are literally thousand=
s of tests which are created this way.=A0 After generation, they&#39;re sto=
red in svn and then used much later. <br>


<br>
&gt; Put another way, the goal is to make this:<br>
&gt; * =A0&lt;xs:element maxOccurs=3D&quot;1&quot; minOccurs=3D&quot;0&quot=
; name=3D&quot;date&quot; type=3D&quot;xs:date&quot;/&gt;*<br>
&gt; ...behave like this:<br>
&gt; =A0*&lt;xs:element maxOccurs=3D&quot;1&quot; minOccurs=3D&quot;0&quot;=
 name=3D&quot;date&quot; type=3D&quot;xs:string&quot;/&gt;*<br>
&gt;<br>
&gt; Naturally, I can edit and copy/paste into a completely new schema file=
. But<br>
&gt; I was hoping someone could tell me if I can do some kind of XSLT or wh=
atever<br>
&gt; to get the same effect.<br>
<br>
</div><blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb=
(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I&#39;d jus=
t change the schema on the way in. You didn&#39;t say what tool you use<br>


for validation, but at least in lxml, modifying the schema tree is pretty<b=
r>
trivial. You can simply use XPath to find all date types and then fix their=
<br>
type attribute.</blockquote><div><br>The tool I&#39;m using is etree.=A0 Th=
at&#39;s a great suggestion concerning xpath.=A0 That sounds pretty easy.<b=
r><br>Thanks, Stefan!<br>=A0<br></div><blockquote class=3D"gmail_quote" sty=
le=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex;=
 padding-left: 1ex;">

<br>
<font color=3D"#888888"><br>
Stefan<br>
<br>
</font></blockquote></div><br>

--0016e64f918e71b08b046e4c6f81--

--===============1995674055==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
XML-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/xml-sig

--===============1995674055==--