root/branches/mk/tests/functional/test_score.py

Revision 67, 2.6 kB (checked in by mk, 6 years ago)

Check that Cheesecake is computing score properly (closes ticket #30).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2 import os
3 import re
4
5 from math import ceil
6
7 from _helper_cheesecake import FunctionalTest, read_file_contents, DATA_PATH
8
9 from cheesecake.util import pad_msg
10
11
12 class TestScore(FunctionalTest):
13     def test_required_files(self):
14         self._run_cheesecake('-p %s' % os.path.join(DATA_PATH, 'required.tar.gz'))
15
16         self._assert_success()
17
18         stdout = read_file_contents(self.stdout_name)
19         # Files in package: INSTALL, Install.html, README and TODO.
20         assert '(2 files and 0 required directories found)' in stdout
21         # One not documented module with a single function with a docstring.
22         assert '(found 1/2=50.00% objects with docstrings)' in stdout
23         assert pad_msg('docstrings', 50) in stdout
24         assert '(found 0/2=0.00% objects with formatted docstrings)' in stdout
25
26     def test_sum(self):
27         installability_regex = r'INSTALLABILITY INDEX \(RELATIVE\) \.\.\.\.\.\.\.\.\s+(\d+)\s+\((\d+) out of a maximum of (\d+) points is (\d+)%\)'
28         documentation_regex = r'DOCUMENTATION INDEX \(RELATIVE\) \.\.\.\.\.\.\.\.\.\s+(\d+)\s+\((\d+) out of a maximum of (\d+) points is (\d+)%\)'
29         code_kwalitee_regex = r'CODE KWALITEE INDEX \(RELATIVE\) \.\.\.\.\.\.\.\.\.\s+(\d+)\s+\((\d+) out of a maximum of (\d+) points is (\d+)%\)'
30
31         self._run_cheesecake('-p %s' % os.path.join(DATA_PATH, 'required.tar.gz'))
32
33         self._assert_success()
34
35         # Check that scores are added up and scaled properly.
36         stdout = read_file_contents(self.stdout_name)
37
38         installability_match = re.search(installability_regex, stdout)
39         documentation_match = re.search(documentation_regex, stdout)
40         code_kwalitee_match = re.search(code_kwalitee_regex, stdout)
41
42         assert installability_match
43         assert documentation_match
44         assert code_kwalitee_match
45
46         overall_score = 0
47         overall_maximum = 0
48         for index in [installability_match, documentation_match, code_kwalitee_match]:
49             percent_one, current, maximum, percent_two = index.groups()
50             assert percent_one == percent_two
51             overall_score += int(current)
52             overall_maximum += int(maximum)
53             print "Score: %d/%d" % (int(current), int(maximum))
54
55         overall_percent = ceil(overall_score / float(overall_maximum))
56
57         print "Computed overall score: %d" % overall_score
58         assert 'OVERALL CHEESECAKE INDEX (ABSOLUTE) .... %3d' % overall_score in stdout
59         assert 'OVERALL CHEESECAKE INDEX (RELATIVE) .... %3d  (%d out of a maximum of %d points is %d%%)' % \
60                (overall_percent, overall_score, overall_maximum, overall_percent)
Note: See TracBrowser for help on using the browser.