Changeset 22

Show
Ignore:
Timestamp:
05/27/06 16:16:09 (7 years ago)
Author:
mk
Message:

Use random temporary directory for sandbox by default.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mk/cheesecake/cheesecake_index.py

    r21 r22  
    132132        self.url = url 
    133133        self.package_path = path 
     134 
    134135        if not self.name and not self.url and not self.package_path: 
    135136            self.raise_exception("No package name, URL or path specified ... exiting") 
    136         self.sandbox = sandbox or default_temp_directory 
     137 
     138        self.sandbox = sandbox or tempfile.mkdtemp(prefix='cheesecake') 
    137139        if not os.path.isdir(self.sandbox): 
    138140            os.mkdir(self.sandbox) 
     141 
    139142        self.config = config 
    140143        self.verbose = verbose 
     
    977980                      default="", help="package path on local file system") 
    978981    parser.add_option("-s", "--sandbox", dest="sandbox", 
    979                       default=default_temp_directory, 
    980                       help="directory where package will be unpacked (default=%s)" % default_temp_directory) 
     982                      default=None, 
     983                      help="directory where package will be unpacked "\ 
     984                           "(default is to use random directory inside %s)" % tempfile.gettempdir()) 
    981985    parser.add_option("-c", "--config", dest="config", 
    982986                      default=None, 
  • branches/mk/tests/test_index_unpack.py

    r21 r22  
    1919        os.unlink(self.cheesecake.logfile) 
    2020 
    21     def test_index_unpack_valid_tar_gz(self): 
    22         self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.tar.gz")) 
     21    def _run_valid(self, package_file, message): 
     22        self.cheesecake = Cheesecake(path=os.path.join(datadir, package_file)) 
    2323        index = self.cheesecake.index_unpack() 
    2424        assert index.name == "index_unpack" 
    2525        assert index.value == self.cheesecake.INDEX_UNPACK 
    26         assert index.details == "package untar-ed successfully" 
     26        assert index.details == message 
     27 
     28    def test_index_unpack_valid_tar_gz(self): 
     29        self._run_valid("package1.tar.gz", "package untar-ed successfully") 
    2730 
    2831    def test_index_unpack_valid_tgz(self): 
    29         self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.tgz")) 
    30         index = self.cheesecake.index_unpack() 
    31         assert index.name == "index_unpack" 
    32         assert index.value == self.cheesecake.INDEX_UNPACK 
    33         assert index.details == "package untar-ed successfully" 
     32        self._run_valid("package1.tgz", "package untar-ed successfully") 
    3433 
    3534    def test_index_unpack_valid_zip(self): 
    36         self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.zip")) 
    37         index = self.cheesecake.index_unpack() 
    38         assert index.name == "index_unpack" 
    39         assert index.value == self.cheesecake.INDEX_UNPACK 
    40         assert index.details == "package unzipped successfully" 
     35        self._run_valid("package1.zip", "package unzipped successfully") 
    4136 
    42     def test_index_unpack_invalid_tar_gz(self): 
     37    def _run_invalid(self, package_file, message): 
    4338        try: 
    44             self.cheesecake = Cheesecake(path=os.path.join(datadir, "invalid_package.tar.gz")) 
     39            self.cheesecake = Cheesecake(path=os.path.join(datadir, package_file), 
     40                                         sandbox=default_temp_directory) 
    4541            assert 0 # This statement should not be reached 
    4642        except CheesecakeError, e: 
    47             msg = "Could not read tar file %s ... exiting\n" % \ 
    48                   os.path.join(default_temp_directory, 'invalid_package.tar.gz') 
     43            msg = message % os.path.join(default_temp_directory, package_file) 
    4944            msg += pad_msg("CHEESECAKE INDEX", 0) 
    5045            assert str(e) == msg 
    5146 
     47    def test_index_unpack_invalid_tar_gz(self): 
     48        self._run_invalid("invalid_package.tar.gz", 
     49                          "Could not read tar file %s ... exiting\n") 
     50 
    5251    def test_index_unpack_invalid_tgz(self): 
    53         try: 
    54             self.cheesecake = Cheesecake(path=os.path.join(datadir, "invalid_package.tgz")) 
    55             assert 0 # This statement should not be reached 
    56         except CheesecakeError, e: 
    57             msg = "Could not read tar file %s ... exiting\n" % \ 
    58                   os.path.join(default_temp_directory, 'invalid_package.tgz') 
    59             msg += pad_msg("CHEESECAKE INDEX", 0) 
    60             assert str(e) == msg 
     52        self._run_invalid("invalid_package.tgz", 
     53                          "Could not read tar file %s ... exiting\n") 
    6154 
    6255    def test_index_unpack_invalid_zip(self): 
    63         try: 
    64             self.cheesecake = Cheesecake(path=os.path.join(datadir, "invalid_package.zip")) 
    65             assert 0 # This statement should not be reached 
    66         except CheesecakeError, e: 
    67             msg = "Error unzipping file %s ... exiting\n" % \ 
    68                   os.path.join(default_temp_directory, 'invalid_package.zip') 
    69             msg += pad_msg("CHEESECAKE INDEX", 0) 
    70             assert str(e) == msg 
     56        self._run_invalid("invalid_package.zip", 
     57                          "Error unzipping file %s ... exiting\n") 
  • branches/mk/tests/test_index_url_download.py

    r21 r22  
    2222 
    2323    def test_index_url_download_valid_url(self): 
    24         def test_fun(): 
    25             datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data")) 
     24        datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data")) 
    2625 
    27             urls = [ 
    28                 "http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz", 
    29                 "file://%s" % os.path.join(datadir, "nose-0.8.3.tar.gz") 
    30            
     26        urls = [ 
     27            "http://www.agilistas.org/cheesecake/nose-0.8.3.tar.gz", 
     28            "file://%s" % os.path.join(datadir, "nose-0.8.3.tar.gz") 
     29       
    3130 
    32             for url in urls: 
     31        for url in urls: 
     32            def test_fun(): 
    3333                try: 
    3434                    self.cheesecake = Cheesecake(url=url) 
     
    4545                    assert str(e) == msg 
    4646 
    47         self._run_it(test_fun) 
     47            self._run_it(test_fun) 
    4848 
    4949    def test_index_url_download_invalid_url(self): 
    5050        def test_fun(): 
    5151            try: 
    52                 self.cheesecake = Cheesecake(url="http://www.agilistas.org/cheesecake/not_there.tar.gz") 
     52                self.cheesecake = Cheesecake(url="http://www.agilistas.org/cheesecake/not_there.tar.gz", 
     53                                             sandbox=default_temp_directory) 
    5354                assert 0 # This statement should not be reached 
    5455            except CheesecakeError, e: