Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:10:39+00:00 2026-06-08T18:10:39+00:00

So I have installed pymox and I would like to test this method: class

  • 0

So I have installed pymox and I would like to test this method:

class HttpStorage():

    def download(self, input, output):
        try:
            file_to_download = urllib2.urlopen(input)
        except URLError:
            raise IOError("Opening input URL failed")

        f = open(output, "wb")
        f.write(file_to_download.read())
        f.close()
        return True

I am reading through the pymox documentation but I cannot figure out how to do it. Could you help me with some example code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:10:40+00:00Added an answer on June 8, 2026 at 6:10 pm
    import unittest
    import mox
    
    class HttpStorageTest(mox.MoxTestBase):
    
      def setUp(self):
        self.httpstorage = HttpStorage()
    
      def test_download(self):
        self.mox.StubOutWithMock(urllib2, "urlopen")
        test_file = open("testfile")
        urllib2.urlopen(mox.IgnoreArg()).AndReturn(test_file)
    
        self.mox.ReplayAll()
        feedback = self.httpstorage.download(test_input, test_output)
        self.assertEqual(feedback, True)
    

    You could try this format to test your download funciton, as the urllib2.openurl() has been mocked to do unit test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed the ODAC 11 and I would like to use it with
have installed Web Developer on Firefox 5.0 and personally found it redundant. would like
I have installed xampp on my Ubuntu machine, and would like to be able
I have installed yasnippet. I would like to add rails snippets to it. I
I have installed rvm (mutiuser option) and ruby using rvm install on my test
I have installed bootstrap to my Rails 3.2 app this way (through Gemfile): gem
I have installed RockMongo http://code.google.com/p/rock-php/ to manage my mongoDB database. This is installed in
I have installed Python 3k(C:\Python30) and Visual Studio Professional Edition 2008. I'm studying this
I have installed GIT for Windows right now. And when I am running this
I have installed cygwin and all the needed compilers like gcc, mingw ,etc. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.