ChannelIQ / jsoncompare

A simple python library for comparing json objects for equivalency and helping developers to quickly spot differences between complex json structures.
MIT License
55 stars 40 forks source link

Python 3 Support #10

Open theronic opened 7 years ago

theronic commented 7 years ago
    def _are_same(expected, actual, ignore_value_of_keys, ignore_missing_keys=False):
        # Check for None
        if expected is None:
            return expected == actual, Stack()

        # Ensure they are of same type
        if type(expected) != type(actual):
            return False, \
                   Stack().append(
                       StackItem('Type Mismatch: Expected Type: {0}, Actual Type: {1}'
                                    .format(type(expected), type(actual)),
                                 expected,
                                 actual))

        # Compare primitive types immediately
>       if type(expected) in (int, str, bool, long, float, unicode):
E       NameError: name 'long' is not defined

long is int in Python 3.

rwblair commented 7 years ago

I also had to remove unicode from the type list to get it to run in python 3.6.

vitorfragoso commented 7 years ago

I have the same issue.

CrashenX commented 6 years ago

I worked around this by adding the following to my code:

from jsoncompare import jsoncompare as json_comp
# Make json_comp work with Python 3
json_comp.long = int
json_comp.unicode = str
json_comp.xrange = range

EDIT: You'll also need to patch dict comparison, which I didn't bother doing. There is a fork of this in pypi called json_compare that supports python 3: https://pypi.python.org/pypi/json_compare

maurycyp commented 6 years ago

+1