简体   繁体   English

使用/运行python的2to3或者像unittest一样

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

I have used the 2to3 utility to convert code from the command line. 我使用2to3实用程序从命令行转换代码。 What I would like to do is run it basically as a unittest. 我想做的是将它作为一个单元测试运行。 Even if it tests 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. 它不需要是一个单元测试,我不会自动转换文件,我只想监视单元测试中的文件的py3合规性,如庄园。 I can't seem to find any documentation or examples for this. 我似乎无法找到任何文档或示例。

An example and/or documentation would be great. 一个例子和/或文档会很棒。

只需使用python2.6 +的-3选项就可以了解Python3的合规性。

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. 如果您正在尝试验证代码是否可以在Python 3.x中运行,我建议使用一个脚本将源文件复制到新目录,在它们上运行2to3 ,然后将单元测试复制到目录并运行它们。

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. 如果转换后的代码通过了单元测试,则可以考虑使用代码来支持Python 3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM