diff options
author | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2001-01-02 16:30:31 +0000 |
---|---|---|
committer | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2001-01-02 16:30:31 +0000 |
commit | fd288c7cd59cffcdb110d04dca1ba2e821aabac7 (patch) | |
tree | bd3453fa24800393d252b69ecf37233208ea5538 /Lib/test/test_compare.py | |
parent | 10e31cf82e5fa325e779013619d9e11bf8b56c28 (diff) | |
download | cpython-git-fd288c7cd59cffcdb110d04dca1ba2e821aabac7.tar.gz |
Add more tests for compare and coercion in preparation for the coercion
overhaul. Closes SF patch #102878.
Diffstat (limited to 'Lib/test/test_compare.py')
-rw-r--r-- | Lib/test/test_compare.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Lib/test/test_compare.py b/Lib/test/test_compare.py new file mode 100644 index 0000000000..d74f300f48 --- /dev/null +++ b/Lib/test/test_compare.py @@ -0,0 +1,57 @@ +import sys + +from test_support import * + +class Empty: + def __repr__(self): + return '<Empty>' + +class Coerce: + def __init__(self, arg): + self.arg = arg + + def __repr__(self): + return '<Coerce %s>' % self.arg + + def __coerce__(self, other): + if isinstance(other, Coerce): + return self.arg, other.arg + else: + return (self.arg, other) + +class Cmp: + def __init__(self,arg): + self.arg = arg + + def __repr__(self): + return '<Cmp %s>' % self.arg + + def __cmp__(self, other): + return cmp(self.arg, other) + +class RCmp: + def __init__(self,arg): + self.arg = arg + + def __repr__(self): + return '<RCmp %s>' % self.arg + + def __rcmp__(self, other): + return cmp(other, self.arg) + + +candidates = [2, 2.2, 2L, 2+4j, [1], (2,), None, Empty(), Coerce(3), + Cmp(4), RCmp(5)] + +def test(): + for a in candidates: + for b in candidates: + print "cmp(%s, %s)" % (a, b), + try: + x = cmp(a, b) + except: + print '... %s' % sys.exc_info(0) + else: + print '=', x + +test() |