Ticket #9222: trac_9222.patch

File trac_9222.patch, 4.5 KB (added by AlexGhitza, 13 years ago)
  • sage/databases/conway.py

    # HG changeset patch
    # User Alexandru Ghitza <aghitza@alum.mit.edu>
    # Date 1276330065 -36000
    # Node ID 405498e153fdb628e8e85e7d088d8baace8b2543
    # Parent  2cffe66bd64266c6a64d31ca37ad81d8d5390af8
    trac #9222: improve doctest coverage of databases/conway.py
    
    diff -r 2cffe66bd642 -r 405498e153fd sage/databases/conway.py
    a b  
    7575       
    7676        INPUT:
    7777       
    78        
    7978        -  ``read_only`` - bool (default: True), if True, then
    8079           the database is read_only and changes cannot be committed to
    8180           disk.
     81
     82        TESTS::
     83
     84            sage: c = ConwayPolynomials()
     85            sage: c
     86            Frank Luebeck's database of Conway polynomials
     87            sage: c.read_only
     88            True
    8289        """
    8390        sage.databases.db.Database.__init__(self,
    8491             name="conway_polynomials", read_only=read_only)
     
    101108        self.commit()
    102109
    103110    def __repr__(self):
     111        """
     112        Return a description of this database.
     113
     114        TESTS:
     115
     116            sage: c = ConwayPolynomials()
     117            sage: c.__repr__()
     118            "Frank Luebeck's database of Conway polynomials"
     119        """
    104120        return "Frank Luebeck's database of Conway polynomials"
    105121
    106122
    107123    def polynomial(self, p, n):
     124        """
     125        Return the Conway polynomial of degree ``n`` over ``GF(p)``,
     126        or raise a RuntimeError if this polynomial is not in the
     127        database.
     128
     129        .. NOTE::
     130
     131            See also the global function ``conway_polynomial`` for
     132            a more user-friendly way of accessing the polynomial.
     133
     134        INPUT:
     135
     136        - ``p`` -- prime number
     137
     138        - ``n`` -- positive integer
     139
     140        OUTPUT:
     141
     142        List of Python int's giving the coefficients of the corresponding
     143        Conway polynomial in ascending order of degree.
     144
     145        EXAMPLES::
     146
     147            sage: c = ConwayPolynomials()
     148            sage: c.polynomial(3, 21)
     149            [1, 2, 0, 2, 0, 1, 2, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
     150            sage: c.polynomial(97, 128)
     151            Traceback (most recent call last):
     152            ...
     153            RuntimeError: Conway polynomial over F_97 of degree 128 not in database.
     154        """
    108155        try:
    109156            return self[int(p)][int(n)]
    110157        except KeyError:
    111158            raise RuntimeError, "Conway polynomial over F_%s of degree %s not in database."%(p,n)
    112159
    113160    def has_polynomial(self, p, n):
     161        """
     162        Return True if the database of Conway polynomials contains the
     163        polynomial of degree ``n`` over ``GF(p)``.
     164
     165        INPUT:
     166
     167        - ``p`` -- prime number
     168
     169        - ``n`` -- positive integer
     170
     171        EXAMPLES::
     172
     173            sage: c = ConwayPolynomials()
     174            sage: c.has_polynomial(97, 12)
     175            True
     176            sage: c.has_polynomial(60821, 5)
     177            False
     178        """
    114179        return self.has_key(int(p)) and self[int(p)].has_key(int(n))
    115180
    116181    def primes(self):
    117         return self.keys()
     182        """
     183        Return the list of prime numbers ``p`` for which the database of
     184        Conway polynomials contains polynomials over ``GF(p)``.
     185
     186        EXAMPLES::
     187
     188            sage: c = ConwayPolynomials()
     189            sage: P = c.primes()
     190            sage: 2 in P
     191            True
     192            sage: next_prime(10^7) in P
     193            False
     194        """
     195        return list(self.keys())
    118196
    119197    def degrees(self, p):
     198        """
     199        Return the list of integers ``n`` for which the database of Conway
     200        polynomials contains the polynomial of degree ``n`` over ``GF(p)``.
     201
     202        EXAMPLES::
     203
     204            sage: c = ConwayPolynomials()
     205            sage: c.degrees(60821)
     206            [1, 2, 3, 4]
     207            sage: c.degrees(next_prime(10^7))
     208            []
     209        """
    120210        p = int(p)
    121211        if not p in self.primes():
    122212            return []
  • sage/databases/db.py

    diff -r 2cffe66bd642 -r 405498e153fd sage/databases/db.py
    a b  
    9595import sage.databases.compressed_storage
    9696import sage.misc.misc
    9797
    98 # The following effectively turns of the ZODB logger, which is OK for us.
     98# The following effectively turns off the ZODB logger, which is OK for us.
    9999# Without this, one gets this annoying error message a lot:
    100100#       No handlers could be found for logger "ZODB.FileStorage"
    101101import logging