Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python / Jython 2.2 support for v0.5.0 #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

clach04
Copy link

@clach04 clach04 commented Apr 5, 2012

I've made some quick changes for Python 2.2 support (tested with http://code.google.com/p/movable-python/downloads/detail?name=movpy-2.0.0-py2.2.3.zip ) I've not yet tried Jython 2.2.

Test suite is now runnable but there are some failures in the test. Py2.2 does NOT include datetime, decimal, or simplejson so these are additional requirements for 2.2 users.

unknown and others added 3 commits April 5, 2012 09:15
@cjerdonek
Copy link
Collaborator

Also see issue #98 for comments regarding nose and running unit tests.

@cjerdonek
Copy link
Collaborator

It occurs to me that we can get around the absence of simplejson (at least for the spec tests) by storing or generating a version of the spec tests in native Python code (e.g. by using Python's repr() on the deserialized YAML/JSON).

@clach04
Copy link
Author

clach04 commented Apr 9, 2012

Its funny you mentioned repr(), I have this in a few of my projects where I deal with self generated json (i.e. it isn't coming from an untrusted user):

"""json support
TODO consider:
  * http://pypi.python.org/pypi/omnijson
  * http://opensource.xhaus.com/projects/show/jyson
"""
try:
    # Python 2.6+
    import json
except ImportError:
    try:
        # from http://code.google.com/p/simplejson
        import simplejson as json
    except ImportError:
        json = None
......
if json is None:
    warnings.warn('Using naive json handlers')

    def dump_json(x, indent=None):
        """dumb not safe!
        Works for the purposes of this specific script as quotes never
        appear in data set.

        Parameter indent ignored"""
        # could use pprint for the purposes of this specific script
        return repr(x).replace("'", '"')

    def load_json(x):
        """dumb not safe! Works for the purposes of this specific script"""
        x = x.replace('\r', '')
        try:
            result = eval(x)
        except Exception, e:
            logging.error('parsing json string data: %r', x)
            print ''
            print '** ERROR parsing json string data'
            print ''
            raise Exception(e)
        return result
else:
    dump_json = json.dumps
    load_json = json.loads

I've not tried this with pystache yet though.

Backported datetime/decimal work fine though.

I found an old article that talks about Nose py2.2 support so I'll try that out when I get chance but manually running the tests has worked out so far.

@cjerdonek
Copy link
Collaborator

With regard to unit tests, my current thinking is to move away from requiring nose. This is primarily because Distribute's test seems to provide better support for running 2to3 automatically when testing with Python 3, which I feel is important going forward:

python setup.py test

Using Distribute's test required me to write a manual test collector to collect the doctests from all packages. I used this approach in conjunction with the load_tests protocol introduced in Python 2.7.

To support Python 2.2, it probably wouldn't be too hard to write a modified test collector that works with Python 2.2 and grabs all unit tests and doctests. That would let us unit test in Python 2.2 more easily going forward and without all the manual updates. By the way, I'd like eventually to be able to run the tests across all versions of Python with a single command. I've made issue #107 for this. It would be too much work to support all versions of Python without this capability.

@clach04
Copy link
Author

clach04 commented Apr 10, 2012

I just spent a few hours attempting to backport Nose to Py 2.2 see https://github.com/clach04/nose/tree/python_2.2_support it seems to work for CPython 2.2 but not Jython (2.2). I'm not likely to pursue Nose further.

Basically Nose support under Jython 2.2 is a no go, I'm not sure if test (module) discovery is an option under Jython 2.2 :-(

The nice thing about the way you've setup the test suite is that it uses unittest and then any test discovery mechanisms work if available, with manual invocation as a backup option (the changes to the unittests in this pull request make sure vanilla unittest work). Tox looks interesting.

@cjerdonek
Copy link
Collaborator

Thanks for putting effort into seeing if nose would work. I wouldn't have had a problem with using nose for older versions and Distribute's test for newer versions. By the way, it looks like Distribute only works for Python 2.3 or later.

Test discovery and collection isn't impossible to implement on our own. Pretty much all you need is unittest and a programmatic way to import at runtime (e.g. Python's __import__()). I actually did something like this for WebKit when I was working on their Python scripts a couple years ago. I just found the relevant section of code here. The license is BSD.

In the meantime, a poor man's option (which we'd have to maintain by hand) would be to have a single test module, say, with a line that looks like from test_module import * for each unit test module in our code base. And then we could run unittest from that module because that module would have all the unittest.TestCase classes in it (as long as the class names are unique).

@cjerdonek
Copy link
Collaborator

For future reference, here is the simpler, original form of the manual test-collection code I referenced above (just ~100 lines). Also for future reference, unittest was new as of Python 2.1.

@cjerdonek
Copy link
Collaborator

FYI, I got tox working in the development branch and pushed it. Tests pass for Python 2.4 to 3.2 with one command. Tox's documentation says they support Jython by default.

@cjerdonek
Copy link
Collaborator

I'm more convinced not to use nose after seeing all the open issues they have. I just ran into this one myself.

@cjerdonek
Copy link
Collaborator

FYI, I changed the test harness in the development branch so that nose is no longer needed or used. Running tox now tests Python 2.4 through 3.2. Instructions are in the README. I wonder if this will get you any farther in including 2.2 into the test harness.

@stuaxo
Copy link

stuaxo commented Dec 11, 2017

Jython has come on a long way since 2012, with 2.7 compatibility being fairly good, it's worth seeing if pystache still needs this patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants