开发者

use/run python's 2to3 as or like a unittest

开发者 https://www.devze.com 2022-12-30 05:02 出处:网络
I have used the 2to3 utility to convert code from the command line. What I would like to do is run it basically as a unittest. Even if it tes开发者_Go百科ts the file rather than parts(functions, metho

I have used the 2to3 utility to convert code from the command line. What I would like to do is run it basically as a unittest. Even if it tes开发者_Go百科ts the file rather than parts(functions, methods...) as would be normal for a unittest.

It does not need to be a unittest and I don't what to automatically convert the files I just want to monitor the py3 compliance of files in a unittest like manor. I can't seem to find any documentation or examples for this.

An example and/or documentation would be great.


Simply use the -3 option with python2.6+ to be informed of Python3 compliance.


If you are trying to verify the code will work in Python 3.x, I would suggest a script that copies the source files to a new directory, runs 2to3 on them, then copies the unit tests to the directory and runs them.

This may seem slightly inelegant, but is consistent with the spirit of unit testing. You are making a series of assertions that you believe ought to be true about the external behavior of the code, regardless of implementation. If the converted code passes your unit tests, you can consider your code to support Python 3.

0

精彩评论

暂无评论...
验证码 换一张
取 消