Example #1
0
def gcd(x, y):
    """greatest common divisor of x and y"""
    x = abs(index(x))
    y = abs(index(y))
    while x > 0:
        x, y = y % x, x
    return y
 def test_index(self):
     import _operator as operator
     assert operator.index(42) == 42
     raises(TypeError, operator.index, "abc")
     exc = raises(TypeError, operator.index, "abc")
     assert str(
         exc.value) == "'str' object cannot be interpreted as an integer"
    def test_index_int_subclass(self):
        import operator

        class myint(int):
            def __index__(self):
                return 13289

        assert operator.index(myint(7)) == 7
def bin(x):
    """Return the binary representation of an integer.

    >>> bin(2796202)
    '0b1010101010101010101010'

    """
    value = _operator.index(x)
    return value.__format__("#b")
def hex(x):
    """Return the hexadecimal representation of an integer.

    >>> hex(12648430)
    '0xc0ffee'

    """
    x = _operator.index(x)
    return x.__format__("#x")
def oct(x):
    """Return the octal representation of an integer.

    >>> oct(342391)
    '0o1234567'

    """
    x = _operator.index(x)
    return x.__format__("#o")
Example #7
0
def calledFunc():

    #print(len(exampleList))
    """for x in exampleList:
        print(x)"""
    for x in range(0, 18):
        if (exampleList[x] % 2) == 0:
            print(x, exampleList[x])
            if index(exampleList[x]) == len(exampleList):
                break
Example #8
0
 def test_deprecation_warning_1(self):
     import warnings, _operator
     class BadInt:
         def __int__(self):
             return True
         def __index__(self):
             return False
     bad = BadInt()
     with warnings.catch_warnings(record=True) as log:
         warnings.simplefilter("always", DeprecationWarning)
         n = int(bad)
         m = _operator.index(bad)
     assert n == 1 and type(n) is int
     assert m is False
     assert len(log) == 2
Example #9
0
 def test_deprecation_warning_3(self):
     import warnings, _operator
     class BadInt(int):
         def __int__(self):
             return self
         def __index__(self):
             return self
     bad = BadInt(2**100)
     with warnings.catch_warnings(record=True) as log:
         warnings.simplefilter("always", DeprecationWarning)
         n = int(bad)
         m = _operator.index(bad)  # no warning
     assert n == bad and type(n) is int
     assert m is bad
     assert len(log) == 1
     assert log[0].message.args[0].startswith('__int__')