Changeset 18 for branches/mk/tests

Show
Ignore:
Timestamp:
05/18/06 15:46:14 (7 years ago)
Author:
mk
Message:

Enhanced init/cleanup tests and written code for custom logging file option.

Files:

Legend:

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

    r2 r18  
    22from cheesecake.cheesecake_index import Cheesecake 
    33import os 
     4import shutil 
     5import tempfile 
     6 
    47datadir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data")) 
    58 
    6 class TestInitCleanup: 
     9class TestInitCleanup(object): 
     10 
     11    def tearDown(self): 
     12        if hasattr(self, 'cheesecake'): 
     13            if os.path.isdir(self.cheesecake.sandbox): 
     14                shutil.rmtree(self.cheesecake.sandbox) 
     15        if hasattr(self, 'logfile'): 
     16            if os.path.isfile(self.logfile): 
     17                os.unlink(self.logfile) 
    718 
    819    def test_init(self): 
    920        self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.tar.gz")) 
    10         self.logfile = os.path.join(self.cheesecake.sandbox, self.cheesecake.logfile) 
     21        assert os.path.isdir(self.cheesecake.sandbox_pkg_dir) 
     22        assert os.path.isfile(self.cheesecake.sandbox_pkg_file) 
     23        self.logfile = self.cheesecake.logfile 
     24        assert os.path.isfile(self.logfile) 
     25 
     26    def test_init_custom_logfile(self): 
     27        self.logfile = tempfile.mktemp() 
     28        self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.tar.gz"), 
     29                                     logfile=self.logfile) 
    1130        assert os.path.isdir(self.cheesecake.sandbox_pkg_dir) 
    1231        assert os.path.isfile(self.cheesecake.sandbox_pkg_file) 
     
    1534    def test_cleanup(self): 
    1635        self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.tar.gz")) 
    17         self.logfile = os.path.join(self.cheesecake.sandbox, self.cheesecake.logfile) 
    1836        self.cheesecake.cleanup() 
    1937        assert not os.path.exists(self.cheesecake.sandbox_pkg_dir) 
    2038        assert not os.path.exists(self.cheesecake.sandbox_pkg_file) 
     39        assert not os.path.exists(self.cheesecake.sandbox) 
    2140        # Log file should not have been deleted 
     41        self.logfile = self.cheesecake.logfile 
    2242        assert os.path.isfile(self.logfile) 
    2343 
     
    2545        self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.tar.gz")) 
    2646        self.cheesecake.index_install() 
    27         self.logfile = os.path.join(self.cheesecake.sandbox, self.cheesecake.logfile) 
    2847        self.cheesecake.cleanup() 
    2948        assert not os.path.exists(self.cheesecake.sandbox_pkg_dir) 
    3049        assert not os.path.exists(self.cheesecake.sandbox_pkg_file) 
    3150        assert not os.path.exists(self.cheesecake.sandbox_install_dir) 
     51        assert not os.path.exists(self.cheesecake.sandbox) 
    3252        # Log file should not have been deleted 
     53        self.logfile = self.cheesecake.logfile 
    3354        assert os.path.isfile(self.logfile) 
    34