python / cpython

The Python programming language
https://www.python.org
Other
62.14k stars 29.86k forks source link

test for request.urlretrieve #62917

Open d96ddaf6-a12c-4621-9d6c-b22394020ea3 opened 11 years ago

d96ddaf6-a12c-4621-9d6c-b22394020ea3 commented 11 years ago
BPO 18717
Nosy @ezio-melotti, @180909
PRs
  • python/cpython#29822
  • Files
  • issue18717.patch: test for urllib.request.urlcleanup
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['type-feature', 'tests'] title = 'test for request.urlretrieve' updated_at = user = 'https://bugs.python.org/mjehanzeb' ``` bugs.python.org fields: ```python activity = actor = 'wangjiahua' assignee = 'none' closed = False closed_date = None closer = None components = ['Tests'] creation = creator = 'mjehanzeb' dependencies = [] files = ['31256'] hgrepos = [] issue_num = 18717 keywords = ['patch'] message_count = 4.0 messages = ['194996', '194997', '194999', '195003'] nosy_count = 3.0 nosy_names = ['ezio.melotti', 'mjehanzeb', 'wangjiahua'] pr_nums = ['29822'] priority = 'normal' resolution = None stage = 'patch review' status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue18717' versions = ['Python 3.4'] ```

    d96ddaf6-a12c-4621-9d6c-b22394020ea3 commented 11 years ago

    As part of pyconca sprints, this is my first patch for urlcleanup test

    ezio-melotti commented 11 years ago

    Thanks for your contribution. Can you submit this as a diff?

    d96ddaf6-a12c-4621-9d6c-b22394020ea3 commented 11 years ago

    the patch fie

    d96ddaf6-a12c-4621-9d6c-b22394020ea3 commented 11 years ago

    included issue# in the patch file

    serhiy-storchaka commented 6 months ago

    It is better to test the side effect of urlcleanup() only using the public API. There are two side effects:

    1. Remove temporary files created by urlretrieve(). It can be tested by checking that the file exists before urlcleanup() and no longer exists after it. You should also test that urlcleanup() is an idempotent operation: if you create the file with the same name name, the repeated call of urlcleanup() should not delete it.
    2. Reset the cached opener. The opener can be installed explicitly by install_opener() and implicitly by urlopen(). You can explicitly install a non-standard opener (with a subset of standard handlers, or even with a mock handler), check that urlopen() only works with the specified handlers, call urlcleanup() and check that urlopen() now works with default handlers. And vice versa: test with explicitly non-standard opener after testing with the implicit opener. This may be pretty complicated.