dmeranda / demjson

Python module for JSON data encoding, including jsonlint. See the project Wiki here on Github. Also read the README at the bottom of this page, or the project homepage at
http://deron.meranda.us/python/demjson/
Other
302 stars 76 forks source link

Run unit tests on Travis CI #17

Closed hugovk closed 4 years ago

hugovk commented 8 years ago

It's a good idea to use Travis CI to run the unit tests. These will run for every commit and also for every PR. It's free for open source projects.

You get a report like this: https://travis-ci.org/hugovk/demjson/builds/78413297

Right now, the Python 3 tests aren't passing, it looks like it's because of using non-Python 3 prints. So for now, I've put those in an allow_failures section. They can be removed once they pass.

TODO by the dmeranda repo owner: enable Travis for dmeranda/demjson here: https://travis-ci.org/profile/

dmeranda commented 8 years ago

I don't know how your tests are configured, but as for Python 3, are you sure that the 2to3 converter is being executed?

demjson already has rather thorough self-tests included, which use the Python "unittest" module. It includes several specific tests just for Python 3 operation. See the test scripts under the "test/" directory, or just run "make test". If you are using Python 3 and did not install in a normal manner (e.g., pip or using setup.py) then remember you must run the 2to3 converter on all the *.py files.

hugovk commented 8 years ago

I hadn't installed with python setup.py install and also hadn't called 2to3.

But now the PR does this:

 - python setup.py install
 - cd test
 - if [ ${TRAVIS_PYTHON_VERSION:0:1} == "3" ]; then 2to3 -w test_demjson.py; fi
 - PYTHONPATH=.. python test_demjson.py

And still fails on Python 3:

$ PYTHONPATH=.. python test_demjson.py
Traceback (most recent call last):
  File "test_demjson.py", line 25, in <module>
    import demjson
  File "../demjson.py", line 645
    class json_int( (1L).__class__ ):    # Have to specify base this way to satisfy 2to3
                      ^
SyntaxError: invalid syntax

https://travis-ci.org/hugovk/demjson/builds/83754575

I get the same thing locally with Python 3.4.2, after:

cd test
2to3 -w test_demjson.py 

I get:

[hugo:~/github/demjson/test] travis(+89/-91)* ± PYTHONPATH=.. python3 test_demjson.py
Traceback (most recent call last):
  File "test_demjson.py", line 25, in <module>
    import demjson
  File "../demjson.py", line 645
    class json_int( (1L).__class__ ):    # Have to specify base this way to satisfy 2to3
                      ^
SyntaxError: invalid syntax
dmeranda commented 8 years ago

You need to run 2to3 on all Python files. Try

2to3 -w demjson.py
cd test
2to3 -w test_demjson.py
hugovk commented 8 years ago

Aha, that was the problem!

All pass (except pypy3, but that's a bit of an edge case): https://travis-ci.org/hugovk/demjson/builds/83763109

hugovk commented 8 years ago

By the way, docs say:

If you have installed demjson with a standard PyPI package distribution mechanism; such as pip, easy_install, or just typing "python3 setup.py install"; then the 2to3 conversion will be performed automatically as part of the installation process.

https://github.com/dmeranda/demjson/blob/master/docs/PYTHON3.txt#L19-L22

But I was calling python setup.py install at one point but it didn't do 2to3.

jayvdb commented 8 years ago

I've approached this same problem slightly differently; see #19 .

hugovk commented 6 years ago

@dmeranda Any thoughts about this and #19? Thank you.