Re: [cherrypy-users] How to create "Fake File object" for Unit Testing?

241 views
Skip to first unread message

Vincent Le Goff

unread,
May 6, 2013, 3:07:00 PM5/6/13
to cherryp...@googlegroups.com
Hello,

I'm not sure of what you want to do, but you can create a file-like
object (with read and readlines method) using StringIO objects.
This class is defined in the StringIO module for Python 2.7 and io
module for Python 3.X. Here's an example using Python 3:

>>> stream = io.StringIO("that works")
>>> stream.read()
'that works'
>>>

Hope that helps,

Vincent

2013/5/6, Tyrone Schiff <sch...@google.com>:
> Hi there,
> I'm trying to write a unit test to verify that I've uploaded a file
> correctly via CherryPy. According to the CherryPy
> docs<http://docs.cherrypy.org/stable/progguide/files/uploading.html>,
> I access the uploaded attachment like this:
>
> attachment.file.read()
>
> Does anyone have any familiarity writing unit tests for file objects?
>
> Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups
> "cherrypy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cherrypy-user...@googlegroups.com.
> To post to this group, send email to cherryp...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cherrypy-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

Sylvain Hellegouarch

unread,
May 7, 2013, 4:55:57 AM5/7/13
to cherryp...@googlegroups.com


On Mon, May 6, 2013 at 8:06 PM, Tyrone Schiff <sch...@google.com> wrote:
Hi there,
I'm trying to write a unit test to verify that I've uploaded a file correctly via CherryPy. According to the CherryPy docs, I access the uploaded attachment like this:

attachment.file.read()

Does anyone have any familiarity writing unit tests for file objects?

Thank you!

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-user...@googlegroups.com.
To post to this group, send email to cherryp...@googlegroups.com.
Visit this group at http://groups.google.com/group/cherrypy-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages