import operator
import unittest
import inspect

from test import test_support

class Seq1:
    def __init__(self, lst):
        self.lst = lst
    def __len__(self):
        return len(self.lst)
    def __getitem__(self, i):
        return self.lst[i]
    def __add__(self, other):
        return self.lst + other.lst
    def __mul__(self, other):
        return self.lst * other
    def __rmul__(self, other):
        return other * self.lst

class Seq2(object):
    def __init__(self, lst):
        self.lst = lst
    def __len__(self):
        return len(self.lst)
    def __getitem__(self, i):
        return self.lst[i]
    def __add__(self, other):
        return self.lst + other.lst
    def __mul__(self, other):
        return self.lst * other
    def __rmul__(self, other):
        return other * self.lst


class OperatorTestCase(unittest.TestCase):
    def test_missing_module_attribute(self):
        skip = {'__subclasshook__', '__new__'}

        def _predicate(member):
            return inspect.isbuiltin(member) and member.__name__ not in skip

        objects = inspect.getmembers(operator, predicate=_predicate)
        for _, value in objects:
            self.assertEqual(value.__module__, "operator", value)

    def test_lt(self):
        self.failUnlessRaises(TypeError, operator.lt)
        self.failUnlessRaises(TypeError, operator.lt, 1j, 2j)
        self.failIf(operator.lt(1, 0))
        self.failIf(operator.lt(1, 0.0))
        self.failIf(operator.lt(1, 1))
        self.failIf(operator.lt(1, 1.0))
        self.failUnless(operator.lt(1, 2))
        self.failUnless(operator.lt(1, 2.0))

    def test_le(self):
        self.failUnlessRaises(TypeError, operator.le)
        self.failUnlessRaises(TypeError, operator.le, 1j, 2j)
        self.failIf(operator.le(1, 0))
        self.failIf(operator.le(1, 0.0))
        self.failUnless(operator.le(1, 1))
        self.failUnless(operator.le(1, 1.0))
        self.failUnless(operator.le(1, 2))
        self.failUnless(operator.le(1, 2.0))

    def test_eq(self):
        class C(object):