Changeset 16

Show
Ignore:
Timestamp:
05/18/06 12:12:32 (6 years ago)
Author:
mk
Message:

Improved URL download test.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mk/tests/test_index_url_download.py

    r15 r16  
    33         
    44import os 
    5 datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data")) 
    65 
    7 class TestIndexInstallability: 
     6 
     7class TestIndexInstallability(object): 
    88 
    99    def setUp(self): 
    1010        self.cheesecake = None 
    1111 
    12     def tearDown(self): 
    13         if not self.cheesecake: 
    14             return 
    15         self.cheesecake.cleanup() 
    16         os.unlink(self.cheesecake.logfile) 
     12    def _run_test(self, test_fun): 
     13        try: 
     14            test_fun() 
     15        finally: 
     16            if self.cheesecake: 
     17                self.cheesecake.cleanup() 
     18                os.unlink(self.cheesecake.logfile) 
    1719 
    1820    def test_index_url_download_valid_url(self): 
    19         try: 
    20             self.cheesecake = Cheesecake(url="http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz") 
    21             index = self.cheesecake.index_url_download() 
    22             assert index.name == "index_url_download" 
    23             assert index.value == self.cheesecake.INDEX_URL_DOWNLOAD 
    24             assert index.details == "downloaded package " + self.cheesecake.package + " from URL " + self.cheesecake.url 
    25         except CheesecakeError, e: 
    26             # it's OK if we get "connection refused" sometimes 
    27             msg = "[Errno socket error] (111, 'Connection refused')\n" 
    28             msg += pad_msg("CHEESECAKE INDEX", 0) 
    29             assert str(e) == msg 
     21        def test_fun(): 
     22            datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data")) 
     23 
     24            urls = [ 
     25                "http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz", 
     26                "file://%s" % os.path.join(datadir, "nose-0.8.3.tar.gz") 
     27            ] 
     28 
     29            for url in urls: 
     30                try: 
     31                    self.cheesecake = Cheesecake(url=url) 
     32                    index = self.cheesecake.index_url_download() 
     33                    assert index.name == "index_url_download" 
     34                    assert index.value == self.cheesecake.INDEX_URL_DOWNLOAD 
     35                    assert index.details == "downloaded package " + \ 
     36                           self.cheesecake.package + " from URL " + \ 
     37                           self.cheesecake.url 
     38                except CheesecakeError, e: 
     39                    # it's OK if we get "connection refused" sometimes 
     40                    msg = "[Errno socket error] (111, 'Connection refused')\n" 
     41                    msg += pad_msg("CHEESECAKE INDEX", 0) 
     42                    assert str(e) == msg 
     43 
     44        self._run_test(test_fun) 
    3045 
    3146    def test_index_url_download_invalid_url(self): 
    32         try: 
    33             self.cheesecake = Cheesecake(url="http://www.agilistas.org/cheesecake/not_there.tar.gz") 
    34             assert 0 # This statement should not be reached 
    35         except CheesecakeError, e: 
    36             msg = "Could not read tar file /tmp/cheesecake_sandbox/not_there.tar.gz ... exiting\n" 
    37             msg += pad_msg("CHEESECAKE INDEX", 0) 
    38             assert str(e) == msg 
     47        def test_fun(): 
     48            try: 
     49                self.cheesecake = Cheesecake(url="http://www.agilistas.org/cheesecake/not_there.tar.gz") 
     50                assert 0 # This statement should not be reached 
     51            except CheesecakeError, e: 
     52                msg = "Could not read tar file /tmp/cheesecake_sandbox/not_there.tar.gz ... exiting\n" 
     53                msg += pad_msg("CHEESECAKE INDEX", 0) 
     54                assert str(e) == msg 
     55 
     56        self._run_test(test_fun)