Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
src/sage/misc/lazy_import.pyx: Fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jan 30, 2023
1 parent d1ca407 commit af823cc
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ cdef class LazyImport():
EXAMPLES::
sage: from sage.misc.lazy_import import LazyImport
sage: my_integer = LazyImport('sage.rings.integer_ring', 'Integer')
sage: my_integer = LazyImport('sage.rings.integer', 'Integer')
sage: my_integer(4)
4
sage: my_integer('101', base=2)
Expand Down Expand Up @@ -365,7 +365,7 @@ cdef class LazyImport():
EXAMPLES::
sage: from sage.misc.lazy_import import LazyImport
sage: my_integer = LazyImport('sage.rings.integer_ring', 'Integer')
sage: my_integer = LazyImport('sage.rings.integer', 'Integer')
sage: my_integer.sqrt is Integer.sqrt
True
"""
Expand Down Expand Up @@ -395,7 +395,7 @@ cdef class LazyImport():
EXAMPLES::
sage: from sage.misc.lazy_import import LazyImport
sage: my_isprime = LazyImport('sage.rings.integer_ring', 'is_prime')
sage: my_isprime = LazyImport('sage.arith.misc', 'is_prime')
sage: is_prime(12) == my_isprime(12)
True
sage: is_prime(13) == my_isprime(13)
Expand Down Expand Up @@ -485,6 +485,7 @@ cdef class LazyImport():
example, we add manually a function in :mod:`sage.all__sagemath_objects`::
sage: def my_method(self): return self
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.my_method = my_method
Now we lazy import it as a method of a new class ``Foo``::
Expand Down Expand Up @@ -568,6 +569,7 @@ cdef class LazyImport():
TESTS::
sage: from sage.misc.lazy_import import LazyImport
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = list(range(10))
sage: lazy_foo = LazyImport('sage.all__sagemath_objects', 'foo')
sage: lazy_foo[1] = 100
Expand All @@ -583,7 +585,8 @@ cdef class LazyImport():
TESTS::
sage: from sage.misc.lazy_import import LazyImport
sage: sage.all.foo = list(range(10))
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = list(range(10))
sage: lazy_foo = LazyImport('sage.all__sagemath_objects', 'foo')
sage: del lazy_foo[1]
sage: print(lazy_foo)
Expand Down Expand Up @@ -623,6 +626,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo + 1
Expand All @@ -634,6 +638,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo - 1
Expand All @@ -645,6 +650,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo * 2
Expand All @@ -657,6 +663,7 @@ cdef class LazyImport():
TESTS::
sage: from sympy import Matrix
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = Matrix([[1,1],[0,1]])
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo.__matmul__(foo)
Expand All @@ -670,6 +677,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo // 3
Expand All @@ -681,6 +689,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: operator.truediv(foo, 3)
Expand All @@ -692,6 +701,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo ** 2
Expand All @@ -703,6 +713,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo % 7
Expand All @@ -714,6 +725,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo << 3
Expand All @@ -725,6 +737,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo >> 2
Expand All @@ -736,6 +749,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo & 7
Expand All @@ -747,6 +761,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo | 7
Expand All @@ -758,6 +773,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: foo ^^ 7
Expand All @@ -769,6 +785,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: -foo
Expand All @@ -780,6 +797,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: +foo
Expand All @@ -791,6 +809,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = -1000
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: abs(foo)
Expand All @@ -802,6 +821,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: ~foo
Expand All @@ -813,6 +833,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: complex(foo)
Expand All @@ -824,6 +845,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: int(foo)
Expand All @@ -835,6 +857,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: float(foo)
Expand All @@ -846,6 +869,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: oct(foo)
Expand All @@ -857,6 +881,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: hex(foo)
Expand All @@ -868,6 +893,7 @@ cdef class LazyImport():
"""
TESTS::
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = 10
sage: lazy_import('sage.all__sagemath_objects', 'foo')
sage: list(range(100))[foo]
Expand All @@ -881,8 +907,8 @@ cdef class LazyImport():
TESTS::
sage: from sage.misc.lazy_import import LazyImport
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = [[1,2], 3]
sage: lazy_foo = LazyImport('sage.all__sagemath_objects', 'foo')
sage: a = copy(lazy_foo)
Expand All @@ -903,6 +929,7 @@ cdef class LazyImport():
TESTS::
sage: from sage.misc.lazy_import import LazyImport
sage: import sage.all__sagemath_objects
sage: sage.all__sagemath_objects.foo = [[1,2], 3]
sage: lazy_foo = LazyImport('sage.all__sagemath_objects', 'foo')
sage: a = deepcopy(lazy_foo)
Expand Down

0 comments on commit af823cc

Please sign in to comment.