views:

78

answers:

2

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 tests the file rather than parts(funtions, 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. Thanks

+2  A: 

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

Michael Aaron Safyan
But I am not sure how I would run this as a unittest. I want run as a test not run the code
Vincent
@Vincent, you'd have to run code to unit test, anyway, so why not simply add the "-3" option to ensure that it is Python3 compatible? What do you need it to do?
Michael Aaron Safyan
A: 

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.

stw_dev