On Wed, Jun 24, 2009 at 6:07 PM, Chris Withers<[email protected]> wrote: > Benji York wrote: >> >> --- begin quote --- >> >> Contents of myfile.zcml:: >> >> <configure xmlns="http://namespaces.zope.org/zope"> >> blah blah blah >> </configure> >> >> .. -> config >> >> >>> import tmpfile >> >>> f = tmpfile.mkstemp() >> >>> f.write(config) >> >>> f.close() > > Okay, but this looks like I'd have to write the above every time I wanted to > save a file
As given, you are correct. A helper function could be written to shorten it to something like this: --- begin quote --- Contents of myfile.zcml:: <configure xmlns="http://namespaces.zope.org/zope"> blah blah blah </configure> .. -> config >>> file_name = temp_file_helper(config) >>> zope.configuration.xmlconfig.file(file_name) --- end quote --- > *and* the saving code would show in the docs, or am I missing > something? No, the code wouldn't be visible. The four lines of code after ".. -> config" are in a reST comment (".." introduces a comment block). > In fact, thinking about it, it'd be great if there were two plugins: > > - one to write files that code being tested could access from disk I think the version above with the helper does a reasonable job for this use case. > - one to read files that code being tested had output and check their > contents were as expected. I'd do that with something like this: --- begin quote --- Contents of myfile.zcml:: <configure xmlns="http://namespaces.zope.org/zope"> blah blah blah </configure> .. -> config >>> file, file_name = make_a_named_temp_file() >>> generate_a_file(fn) >>> file.read() == config True --- end quote --- Alternatively, you might make a purpose-built Manuel plug-in to do exactly what you want. Maybe with syntax like... --- begin quote --- Contents of myfile.zcml:: <configure xmlns="http://namespaces.zope.org/zope"> blah blah blah </configure> .. verify-file: name_of_function_to_do_verification --- end quote --- Where "name_of_function_to_do_verification" would be passed the file name (extracted from the line before the literal block) and the contents of the literal block. Your plug-in could provide a formatter that would show you a nice diff if there is a discrepancy. The code in manuel.capture would be a good starting point for something like that. -- Benji York Senior Software Engineer Zope Corporation _______________________________________________ Zope-Dev maillist - [email protected] http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
