Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[future-0.18.0] test urllib2 failed with Python3.8 #508

Closed
sagitter opened this issue Oct 12, 2019 · 5 comments · Fixed by #516
Closed

[future-0.18.0] test urllib2 failed with Python3.8 #508

sagitter opened this issue Oct 12, 2019 · 5 comments · Fixed by #516

Comments

@sagitter
Copy link

Hi all.

I know that Python-3.8.0-rc1 is not supported yet but i wish to point out following error anyway:

____________________________ HandlerTests.test_ftp _____________________________
self = <test_future.test_urllib2.HandlerTests testMethod=test_ftp>
    def test_ftp(self):
        class MockFTPWrapper(object):
            def __init__(self, data): self.data = data
            def retrfile(self, filename, filetype):
                self.filename, self.filetype = filename, filetype
                return io.StringIO(self.data), len(self.data)
            def close(self): pass
    
        class NullFTPHandler(urllib_request.FTPHandler):
            def __init__(self, data): self.data = data
            def connect_ftp(self, user, passwd, host, port, dirs,
                            timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
                self.user, self.passwd = user, passwd
                self.host, self.port = host, port
                self.dirs = dirs
                self.ftpwrapper = MockFTPWrapper(self.data)
                return self.ftpwrapper
    
        import ftplib
        data = "rheum rhaponicum"
        h = NullFTPHandler(data)
        h.parent = MockOpener()
    
        for url, host, port, user, passwd, type_, dirs, filename, mimetype in [
            ("ftp://localhost/foo/bar/baz.html",
             "localhost", ftplib.FTP_PORT, "", "", "I",
             ["foo", "bar"], "baz.html", "text/html"),
            ("ftp://parrot@localhost/foo/bar/baz.html",
             "localhost", ftplib.FTP_PORT, "parrot", "", "I",
             ["foo", "bar"], "baz.html", "text/html"),
            ("ftp://%25parrot@localhost/foo/bar/baz.html",
             "localhost", ftplib.FTP_PORT, "%parrot", "", "I",
             ["foo", "bar"], "baz.html", "text/html"),
            ("ftp://%2542parrot@localhost/foo/bar/baz.html",
             "localhost", ftplib.FTP_PORT, "%42parrot", "", "I",
             ["foo", "bar"], "baz.html", "text/html"),
            ("ftp://localhost:80/foo/bar/",
             "localhost", 80, "", "", "D",
             ["foo", "bar"], "", None),
            ("ftp://localhost/baz.gif;type=a",
             "localhost", ftplib.FTP_PORT, "", "", "A",
             [], "baz.gif", None),  # XXX really this should guess image/gif
            ]:
            req = Request(url)
            req.timeout = None
            r = h.ftp_open(req)
            # ftp authentication not yet implemented by FTPHandler
            self.assertEqual(h.user, user)
            self.assertEqual(h.passwd, passwd)
            self.assertEqual(h.host, socket.gethostbyname(host))
            self.assertEqual(h.port, port)
            self.assertEqual(h.dirs, dirs)
            self.assertEqual(h.ftpwrapper.filename, filename)
            self.assertEqual(h.ftpwrapper.filetype, type_)
            headers = r.info()
>           self.assertEqual(headers.get("Content-type"), mimetype)
E           AssertionError: 'image/gif' != None
tests/test_future/test_urllib2.py:726: AssertionError
__________________________________ test_main ___________________________________
verbose = None
    def test_main(verbose=None):
        # support.run_doctest(test_urllib2, verbose)
        # support.run_doctest(urllib_request, verbose)
        tests = (TrivialTests,
                 OpenerDirectorTests,
                 HandlerTests,
                 MiscTests,
                 RequestTests,
                 RequestHdrsTests)
>       support.run_unittest(*tests)
tests/test_future/test_urllib2.py:1562: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
build/lib/future/backports/test/support.py:1665: in run_unittest
    _run_suite(suite)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
suite = <unittest.suite.TestSuite tests=[None, None, None, None, None, None]>
    def _run_suite(suite):
        """Run tests from a unittest.TestSuite-derived class."""
        if verbose:
            runner = unittest.TextTestRunner(sys.stdout, verbosity=2,
                                             failfast=failfast)
        else:
            runner = BasicTestRunner()
    
        result = runner.run(suite)
        if not result.wasSuccessful():
            if len(result.errors) == 1 and not result.failures:
                err = result.errors[0][1]
            elif len(result.failures) == 1 and not result.errors:
                err = result.failures[0][1]
            else:
                err = "multiple errors occurred"
                if not verbose: err += "; run in verbose mode for details"
>           raise TestFailed(err)
E           future.backports.test.support.TestFailed: Traceback (most recent call last):
E             File "/builddir/build/BUILD/python-future-23989c4d61a5e3b2308b107efc1402bc727e8fe6/python3/tests/test_future/test_urllib2.py", line 726, in test_ftp
E               self.assertEqual(headers.get("Content-type"), mimetype)
E           AssertionError: 'image/gif' != None
build/lib/future/backports/test/support.py:1640: TestFailed
----------------------------- Captured stdout call -----------------------------
@s-t-e-v-e-n-k
Copy link
Contributor

I have a patch for this which I'm happy to push up a PR for -- but it uses sys.hexversion, and personally I think that makes the patch rather messy.

@jmadler
Copy link
Contributor

jmadler commented Oct 17, 2019

Can you submit a bugfix please? I'll include it in a release in the next few days.

There are constants in future/__init__.py you can use in lieu of sys.hexversion if appropriate.

s-t-e-v-e-n-k added a commit to s-t-e-v-e-n-k/python-future that referenced this issue Oct 18, 2019
To continue to support other versions of Python, use sys.hexversion to
check if we're using 3.8 and set the MIME type appropriately.

Fixes PythonCharmers#508
@mgorny
Copy link
Contributor

mgorny commented Nov 15, 2019

@sagitter, could you check if it still works in 3.8.0? I've just tried enabling py3.8 on this package, and the updated test fails on py3.8.

@mgorny
Copy link
Contributor

mgorny commented Nov 15, 2019

(I mean 3.8.0 final)

@mcepl
Copy link

mcepl commented Dec 5, 2019

@mgorny @sagitter Yes, this patch is is breaking tests on Python 3.8. guessed_mime should be always None.

bmwiedemann added a commit to bmwiedemann/openSUSE that referenced this issue Dec 11, 2019
https://build.opensuse.org/request/show/754444
by user dimstar_suse
- Update to 0.18.2:
  - Fix min/max functions with generators, and 'None' default (PR #514)
  - Use BaseException in raise_() (PR #515)
  - Fix builtins.round() for Decimals (Issue #501)
  - Fix raise_from() to prevent failures with immutable classes (PR #518)
  - Make FixInput idempotent (Issue #427)
  - Fix type in newround (PR #521)
  - Support mimetype guessing in urllib2 for Py3.8+ (Issue #508)
  - fix for raise_() when passed an exception that's not an
    Exception (e.g. BaseException subclasses)
- Rebase future-correct-mimetype.patch to revert incorrect fix in
  gh#PythonCharmers/python-future#508
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants