Anonymous avatar Anonymous committed 81f35a9

renamed Rational to Normalized

Comments (0)

Files changed (3)

test_pypi_versions.py

 ##
 ##  A very simple test to see what percentage of the current pypi packages
 ##  have versions that can be converted automatically by distutils' new
-##  suggest_rational_version() into PEP-386 compatible versions.
+##  suggest_normalized_version() into PEP-386 compatible versions.
 ##
 ##  Requires : Python 2.5+
 #
 import xmlrpclib
 import os.path
 
-from verlib import suggest_rational_version
+from verlib import suggest_normalized_version
 
 INDEX_PICKLE_FILE = 'pypi-index.pkl'
 VERSION_PICKLE_FILE = 'pypi-version.pkl'
 have_sugg = 0.00
 
 for ver in versions:
-    sugg = suggest_rational_version(ver)
+    sugg = suggest_normalized_version(ver)
     if sugg == ver:
         matches += 1
     elif sugg == None:
 import doctest
 import os
 
-from verlib import RationalVersion as V
+from verlib import NormalizedVersion as V
 from verlib import IrrationalVersionError
-from verlib import suggest_rational_version as suggest
+from verlib import suggest_normalized_version as suggest
 
 class VersionTestCase(unittest.TestCase):
 
         >>> V('1.2.0') == '1.2'
         Traceback (most recent call last):
         ...
-        TypeError: cannot compare RationalVersion and str
+        TypeError: cannot compare NormalizedVersion and str
 
         >>> V('1.2.0') == V('1.2')
         True
         doctest.run_docstring_examples(self.test_comparison, globals(),
                                        name='test_comparison')
 
-    def test_suggest_rational_version(self):
+    def test_suggest_normalized_version(self):
 
         self.assertEquals(suggest('1.0'), '1.0')
         self.assertEquals(suggest('1.0-alpha1'), '1.0a1')
         self.assertEquals(suggest('2.1-rc2'), '2.1c2')
 
 def test_suite():
-    README = os.path.join(os.path.dirname(__file__), 'README.txt')
-    suite = [doctest.DocFileSuite(README), unittest.makeSuite(VersionTestCase)]
+    #README = os.path.join(os.path.dirname(__file__), 'README.txt')
+    #suite = [doctest.DocFileSuite(README), unittest.makeSuite(VersionTestCase)]
+    suite = [unittest.makeSuite(VersionTestCase)]
     return unittest.TestSuite(suite)
 
 if __name__ == "__main__":
     """An irrational version because the major version number is huge
     (often because a year or date was used).
 
-    See `error_on_huge_major_num` option in `RationalVersion` for details.
+    See `error_on_huge_major_num` option in `NormalizedVersion` for details.
     This guard can be disabled by setting that option False.
     """
     pass
     (?P<postdev>(\.post(?P<post>\d+))?(\.dev(?P<dev>\d+))?)?
     $''', re.VERBOSE)
 
-class RationalVersion(object):
+class NormalizedVersion(object):
     """A rational version.
 
     Good:
         1.2.3b
     """
     def __init__(self, s, error_on_huge_major_num=True):
-        """Create a RationalVersion instance from a version string.
+        """Create a NormalizedVersion instance from a version string.
 
         @param s {str} The version string.
         @param error_on_huge_major_num {bool} Whether to consider an
             apparent use of a year or full date as the major version number
             an error. Default True. One of the observed patterns on PyPI before
-            the introduction of `RationalVersion` was version numbers like this:
+            the introduction of `NormalizedVersion` was version numbers like this:
                 2009.01.03
                 20040603
                 2005.01
                 % (type(self).__name__, type(other).__name__))
 
     def __eq__(self, other):
-        if not isinstance(other, RationalVersion):
+        if not isinstance(other, NormalizedVersion):
             self._cannot_compare(other)
         return self.parts == other.parts
 
     def __lt__(self, other):
-        if not isinstance(other, RationalVersion):
+        if not isinstance(other, NormalizedVersion):
             self._cannot_compare(other)
         return self.parts < other.parts
 
     def __ge__(self, other):
         return self.__eq__(other) or self.__gt__(other)
 
-def suggest_rational_version(s):
-    """Suggest a rational version close to the given version string.
+def suggest_normalized_version(s):
+    """Suggest a normalized version close to the given version string.
 
-    If you have a version string that isn't rational (i.e. RationalVersion
+    If you have a version string that isn't rational (i.e. NormalizedVersion
     doesn't like it) then you might be able to get an equivalent (or close)
     rational version from this function.
 
     This does a number of simple normalizations to the given string, based
     on observation of versions currently in use on PyPI. Given a dump of
     those version during PyCon 2009, 4287 of them:
-    - 2312 (53.93%) match RationalVersion without change
+    - 2312 (53.93%) match NormalizedVersion without change
     - with the automatic suggestion
     - 3474 (81.04%) match when using this suggestion method
 
     @returns A rational version string, or None, if couldn't determine one.
     """
     try:
-        RationalVersion(s)
+        NormalizedVersion(s)
         return s   # already rational
     except IrrationalVersionError:
         pass
     rs = re.sub(r"\.?(pre|preview|-c)(\d+)$", r"c\g<2>", rs)
 
     try:
-        RationalVersion(rs)
+        NormalizedVersion(rs)
         return rs   # already rational
     except IrrationalVersionError:
         pass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.