Commits

Lennart Regebro  committed c22c956

Stubbing urllib as well

  • Participants
  • Parent commits 5862476

Comments (0)

Files changed (14)

 0.9.3 (unreleased)
 ------------------
 
-- Nothing changed yet.
+- It's now using a ProxyStub for the PyPI xmlrpclib during tests.
+
+- Removed the dependency test.
 
 
 0.9.2 (2011-03-13)

File pyroma/testdata/complete/complete.egg-info/PKG-INFO

-Metadata-Version: 1.0
-Name: complete
-Version: 1.0dev
-Summary: This is a test package for pyroma.
-Home-page: http://colliberty.com
-Author: Lennart Regebro
-Author-email: regebro@gmail.com
-License: MIT
-Description: Complete
-        ========
-        
-        This is a test package for pyroma that is supposed to have a complete
-        set of metadata and also runnable tests. It should score the maximum possible
-        on package tests.
-        
-        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed porttitor, neque at
-        dignissim condimentum, libero est dictum dolor, sit amet tempor urna diam eget
-        velit. Suspendisse at odio quam, ut vestibulum ipsum. Nulla facilisi. Nullam
-        nunc dolor, tempus in vulputate id, fringilla eget metus. Pellentesque nulla
-        nisl, imperdiet ac vulputate non, commodo tincidunt purus. Aenean sollicitudin
-        orci eget diam dignissim scelerisque. Donec quis neque nisl, eu adipiscing
-        velit. Aenean convallis ante sapien. Etiam vitae viverra libero. Nullam ac
-        ligula erat. Aliquam pellentesque, est eget faucibus pharetra, urna orci rhoncus
-        nisi, adipiscing elementum libero lectus ut odio. Duis tincidunt mi quam, quis
-        interdum enim. Nunc sed urna urna, id lacinia turpis. Quisque malesuada, velit
-        ut tincidunt lacinia, dolor augue varius velit, in ultrices lectus enim et
-        dolor. Fusce augue eros, aliquet ac dapibus at, tincidunt vitae leo. Lorem ipsum
-        dolor sit amet, consectetur adipiscing elit. Vivamus sapien neque, fermentum sed
-        ultrices sit amet, fermentum nec est. Pellentesque imperdiet enim nec velit
-        posuere id dignissim massa molestie.
-        
-Keywords: pypi quality example
-Platform: UNKNOWN
-Classifier: Development Status :: 6 - Mature
-Classifier: Operating System :: OS Independent
-Classifier: Programming Language :: Python :: 2.6

File pyroma/testdata/complete/complete.egg-info/SOURCES.txt

-README.txt
-setup.cfg
-setup.py
-complete/__init__.py
-complete/tests.py
-complete.egg-info/PKG-INFO
-complete.egg-info/SOURCES.txt
-complete.egg-info/dependency_links.txt
-complete.egg-info/requires.txt
-complete.egg-info/top_level.txt
-complete.egg-info/zip-safe

File pyroma/testdata/complete/complete.egg-info/dependency_links.txt

-

File pyroma/testdata/complete/complete.egg-info/top_level.txt

-complete

File pyroma/testdata/complete/complete.egg-info/zip-safe

-

File pyroma/testdata/distributions/distribute-0.6.15.tar.gz

Binary file added.

File pyroma/testdata/minimal/minimal.egg-info/PKG-INFO

-Metadata-Version: 1.0
-Name: minimal
-Version: 0.0dev
-Summary: UNKNOWN
-Home-page: UNKNOWN
-Author: UNKNOWN
-Author-email: UNKNOWN
-License: UNKNOWN
-Description: UNKNOWN
-Platform: UNKNOWN

File pyroma/testdata/minimal/minimal.egg-info/SOURCES.txt

-setup.cfg
-setup.py
-minimal/__init__.py
-minimal.egg-info/PKG-INFO
-minimal.egg-info/SOURCES.txt
-minimal.egg-info/dependency_links.txt
-minimal.egg-info/entry_points.txt
-minimal.egg-info/not-zip-safe
-minimal.egg-info/top_level.txt

File pyroma/testdata/minimal/minimal.egg-info/dependency_links.txt

-

File pyroma/testdata/minimal/minimal.egg-info/entry_points.txt

-
-      # -*- Entry points: -*-
-      

File pyroma/testdata/minimal/minimal.egg-info/not-zip-safe

-

File pyroma/testdata/minimal/minimal.egg-info/top_level.txt

-minimal

File pyroma/tests.py

 import unittest
 import os
 import xmlrpclib
+import urlparse
+import urllib
+import sys
 
 from pyroma import projectdata, distributiondata, pypidata
 from pyroma.ratings import rate
             }
 
 
-_RECORD = True # Set this to true, and it will use the real 
+class FakeResponse(object):
+    def __init__(self, responsecode, filename=None):
+        self.filename = filename
+        if sys.version > '2.5':
+            # 2.5 and lower doesn't have the code attribute.
+            # The test should fail on Python 2.5.
+            self.code = responsecode
+            
+    def read(self):
+        return open(self.filename, 'rb').read()
 
-real_server_proxy = xmlrpclib.ServerProxy
-    
+def urlopenstub(url):
+    filename = [x for x in url.split('/') if x][-1]
+    if url.startswith('http://packages.python.org/'):
+        # Faking the docs:
+        if filename in ('distribute',):
+            return FakeResponse(200)
+        else:
+            # This package doesn't have docs on packages.python.org:
+            return FakeResponse(404)
+                
+    if url.startswith('http://pypi.python.org/'):
+        # Faking PyPI
+        filename = resource_filename(
+            __name__, os.path.join('testdata', 'distributions', filename))
+        return FakeResponse(200, filename)
+        
+    raise ValueError("Don't know how to stub " + url)
+
 class ProxyStub(object):
     def __init__(self, dataname, real_class, developmode):        
         filename = resource_filename(
         ]))
 
     def test_distribute(self):
+        real_urlopen = urllib.urlopen
+        real_server_proxy = xmlrpclib.ServerProxy
         try:
             xmlrpclib.ServerProxy = ProxyStub('distributedata.py',
                                               xmlrpclib.ServerProxy,
                                               False)
             
+            urllib.urlopen = urlopenstub
+            
             data = pypidata.get_data('distribute')
             rating = rate(data)
             
             ]))
         finally:
             xmlrpclib.ServerProxy = real_server_proxy
+            urllib.urlopen = real_urlopen
         
 class ProjectDataTest(unittest.TestCase):