Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '"""': 0.07; 'false.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:c 10': 0.09; 'python': 0.11; 'def': 0.12; 'doctests': 0.16; 'python3.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:python': 0.16; 'trying': 0.19; '>>>': 0.22; 'tests': 0.22; 'header:User-Agent:1': 0.23; 'byte': 0.24; 'unicode': 0.24; 'header:X-Complaints-To:1': 0.27; 'converting': 0.30; 'code': 0.31; 'compatible': 0.32; 'quite': 0.32; 'actual': 0.34; 'problem': 0.35; 'convert': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'whilst': 0.36; 'changing': 0.37; 'expected': 0.38; 'problems': 0.38; 'to:addr :python-list': 0.38; 'aside': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'easy': 0.60; 'making': 0.63; 'our': 0.64; 'subject: & ': 0.68; 'received:109': 0.72; 'internally.': 0.84; 'outcome': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robin Becker Subject: doctests compatibility for python 2 & python 3 Date: Fri, 17 Jan 2014 11:16:17 +0000 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 109.174.168.73 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389957389 news.xs4all.nl 2872 [2001:888:2000:d::a6]:46445 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64154 I have some problems making some doctests for python2 code compatible with python3. The problem is that as part of our approach we are converting the code to use unicode internally. So we allow eihter byte strings or unicode in inputs, but we are trying to convert to unicode outputs. That makes doctests quite hard as def func(a): """ >>> func(u'aaa') 'aaa' """ return a fails in python2 whilst def func(a): """ >>> func(u'aaa') u'aaa' """ return a fails in python3. Aside from changing the tests so they look like """ >>> func(u'aaa')==u'aaa' True """ which make the test utility harder. If the test fails I don't see the actual outcome and expected I see expected True got False. Is there an easy way to make these kinds of tests work in python 2 & 3? -- Robin Becker