Changeset 61

Show
Ignore:
Timestamp:
06/15/06 13:07:26 (6 years ago)
Author:
mk
Message:

Check that Cheesecake is handling its command line options properly (closes ticket #31).
Writen working --quiet implementation.

Files:

Legend:

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

    r60 r61  
    279279            yield index.compute_with(self.cheesecake) 
    280280            # Print index info after computing. 
    281             index.print_info() 
     281            if not self.cheesecake.quiet: 
     282                index.print_info() 
    282283 
    283284    def compute_with(self, cheesecake): 
     
    11361137 
    11371138        # Print summary. 
    1138         print 
    1139         print pad_line("=") 
    1140         print pad_msg("OVERALL CHEESECAKE INDEX (ABSOLUTE)", cheesecake_index) 
    1141         print "%s  (%d out of a maximum of %d points is %d%%)" % \ 
    1142               (pad_msg("OVERALL CHEESECAKE INDEX (RELATIVE)", percentage), 
    1143                cheesecake_index, 
    1144                max_cheesecake_index, 
    1145                percentage) 
     1139        if self.quiet: 
     1140            print "Cheesecake index: %d (%d / %d)" % (percentage, 
     1141                                                      cheesecake_index, 
     1142                                                      max_cheesecake_index) 
     1143        else: 
     1144            print 
     1145            print pad_line("=") 
     1146            print pad_msg("OVERALL CHEESECAKE INDEX (ABSOLUTE)", cheesecake_index) 
     1147            print "%s  (%d out of a maximum of %d points is %d%%)" % \ 
     1148                  (pad_msg("OVERALL CHEESECAKE INDEX (RELATIVE)", percentage), 
     1149                   cheesecake_index, 
     1150                   max_cheesecake_index, 
     1151                   percentage) 
    11461152 
    11471153        return cheesecake_index 
  • branches/mk/tests/functional/_helper_cheesecake.py

    r60 r61  
     1import os 
     2import sys 
     3import tempfile 
     4 
     5current_dir = os.path.dirname(__file__) 
     6sys.path.insert(0, os.path.join(current_dir, '../../')) 
     7 
     8try: 
     9    import subprocess 
     10except ImportError, ex: 
     11    from cheesecake import subprocess 
     12 
     13 
     14CHEESECAKE_PATH = os.path.abspath(os.path.join(current_dir, 
     15                                               '../../cheesecake_index')) 
     16DATA_PATH = os.path.abspath(os.path.join(current_dir, '../unit/data/')) 
     17NOSE_PATH = os.path.join(DATA_PATH, 'nose-0.8.3.tar.gz') 
     18PACKAGE_PATH = os.path.join(DATA_PATH, 'package2.tar.gz') 
     19 
     20 
     21class FunctionalTest(object): 
     22    def _run_cheesecake(self, arguments): 
     23        self.stdout_fd, self.stdout_name = tempfile.mkstemp(prefix='functional')  
     24        self.stderr_fd, self.stderr_name = tempfile.mkstemp(prefix='functional') 
     25        self.process = subprocess.Popen('%s %s' % (CHEESECAKE_PATH, arguments), 
     26                         stdout=self.stdout_fd, 
     27                         stderr=self.stderr_fd, 
     28                         shell=True) 
     29        self.return_code = self.process.wait() 
     30 
     31    def _assert_success(self): 
     32        # Check that Cheesecake exited sucessfully. 
     33        assert self.return_code == 0 
     34 
     35        # Check that Cheesecake didn't wrote anything into stderr. 
     36        assert read_file_contents(self.stderr_name) == '' 
     37 
     38    def tearDown(self): 
     39        os.unlink(self.stdout_name) 
     40        os.unlink(self.stderr_name) 
     41 
    142 
    243def read_file_contents(filename): 
  • branches/mk/tests/functional/test_cleaning_up.py

    r60 r61  
    22import os 
    33import tempfile 
    4 from StringIO import StringIO 
    54 
    6 from _path_cheesecake import CHEESECAKE_PATH 
    7 from _helper_cheesecake import read_file_contents 
    8  
    9 try: 
    10     import subprocess 
    11 except ImportError, ex: 
    12     from cheesecake import subprocess 
     5from _helper_cheesecake import FunctionalTest, read_file_contents, NOSE_PATH 
    136 
    147 
    15 class TestCleaningUp(object): 
     8class TestCleaningUp(FunctionalTest): 
    169    def setUp(self): 
    17         self.stdout_fd, self.stdout_name = tempfile.mkstemp(prefix='functional')  
    18         self.stderr_fd, self.stderr_name = tempfile.mkstemp(prefix='functional') 
    1910        self.sandbox = tempfile.mkdtemp() 
    20         self.process = subprocess.Popen('%s -n ftputil -s %s' % \ 
    21                                         (CHEESECAKE_PATH, self.sandbox), 
    22                          stdout=self.stdout_fd, 
    23                          stderr=self.stderr_fd, 
    24                          shell=True) 
    25         self.return_code = self.process.wait() 
    26  
    27     def tearDown(self): 
    28         os.unlink(self.stdout_name) 
    29         os.unlink(self.stderr_name) 
     11        self.logfile = tempfile.mktemp(prefix='log') 
     12        self._run_cheesecake('-p %s -s %s -l %s' % (NOSE_PATH, self.sandbox, self.logfile)) 
    3013 
    3114    def test_no_tmp(self): 
    3215        "Check that no files are left in temp by Cheesecake." 
    33         print file(self.stdout_name).read() 
    34         print file(self.stderr_name).read() 
    35  
    36         # Check that Cheesecake exited sucessfully. 
    37         assert self.return_code == 0 
    38  
    39         # Check that Cheesecake didn't wrote anything into stderr. 
    40         assert read_file_contents(self.stderr_name) == '' 
     16        self._assert_success() 
    4117 
    4218        # Check that Cheesecake didn't left sandbox. 
    4319        assert not os.path.exists(self.sandbox) 
    4420 
     21        # Check that log file has been removed. 
     22        assert not os.path.exists(self.logfile) 
     23 
    4524        # Check that Cheesecake didn't left any cheesecake* files. 
    4625        assert glob(os.path.join(tempfile.gettempdir(), "cheesecake*")) == [] 
    4726 
    48         # Check that Cheesecake didn't left any tmp* files 
     27        # Check that Cheesecake didn't left any tmp* files. 
    4928        assert glob(os.path.join(tempfile.gettempdir(), tempfile.gettempprefix() + "*")) == []