Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badge for all templates #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions django_coverage/coverage_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

"""
import os
import sys

import django

Expand Down Expand Up @@ -114,10 +113,21 @@ def run_tests(self, test_labels, extra_tests=None, **kwargs):
if outdir:
outdir = os.path.abspath(outdir)
if settings.COVERAGE_CUSTOM_REPORTS:
html_report(outdir, modules, excludes, errors)
overall_covered = html_report(outdir, modules, excludes, errors)
else:
coverage._the_coverage.html_report(list(modules.values()), outdir)
overall_covered = coverage._the_coverage.html_report(list(modules.values()), outdir)
print("")
print("HTML reports were output to '%s'" %outdir)
print("HTML reports were output to '%s'" % outdir)

if settings.COVERAGE_BADGE_TYPE:
badge = open(os.path.join(
os.path.dirname(__file__),
'utils',
'coverage_report',
'badges',
settings.COVERAGE_BADGE_TYPE,
'%s.png' % int(overall_covered)), 'rb').read()
open(os.path.join(
outdir, 'coverage_status.png'), 'wb').write(badge)

return results
9 changes: 6 additions & 3 deletions django_coverage/utils/coverage_report/html_module_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
"""

import cgi, os
import os
try:
import html
except ImportError:
import cgi as html

from django_coverage.utils.coverage_report.data_storage import ModuleVars
from django_coverage.utils.coverage_report.templates import default_module_detail as module_detail
Expand Down Expand Up @@ -62,7 +65,7 @@ def html_module_detail(filename, module_name, nav=None):
m_vars.source_lines = source_lines = list()
i = 0
for i, source_line in enumerate(
[cgi.escape(l.rstrip()) for l in open(m_vars.source_file, 'r').readlines()]):
[html.escape(l.rstrip()) for l in open(m_vars.source_file, 'r').readlines()]):
line_status = 'ignored'
if i+1 in m_vars.executed: line_status = 'executed'
if i+1 in m_vars.excluded: line_status = 'excluded'
Expand Down
9 changes: 1 addition & 8 deletions django_coverage/utils/coverage_report/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,4 @@ def html_report(outdir, modules, excludes=None, errors=None):
fo.write(module_index.BOTTOM)
fo.close()

if settings.COVERAGE_BADGE_TYPE:
badge = open(os.path.join(
os.path.dirname(__file__),
'badges',
settings.COVERAGE_BADGE_TYPE,
'%s.png' % int(overall_covered)
), 'rb').read()
open(os.path.join(outdir, 'coverage_status.png'), 'wb').write(badge)
return overall_covered