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

Standalone #365

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Dump standalone changes
  • Loading branch information
kmmbvnr committed May 7, 2012
commit 537f6ef3711b474e91b076741dd1a61a069988d4
82 changes: 82 additions & 0 deletions django_jenkins/standalone/taskviews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8; mode: django -*-
"""
Store and view task results data in standalone ci
"""
import math
from pygooglechart import Axis, SimpleLineChart


class BaseView(object):
"""
Base class for standalone.ci view
"""
def get_build_data(self, tasks, runner):
"""
Extrats current build ci data
"""
return {}

def collect_build_data(self, build_data):
"""
Collect build data for view
"""

def build_chart(self, start_build_id, end_build_id):
"""
Returns pygooglechart instance with build data
"""


class TestView(BaseView):
def __init__(self):
self.successes = []
self.failures = []
self.errors = []

def get_build_data(self, tasks, runner):
test_result = self.test_runner.result

result = {}
result['tests-successes'] = len(test_result.successes)
result['tests-failures'] = len(test_result.failures)
result['tests-errors'] = len(test_result.errors)
return result

def collect_build_data(self, build_data):
self.successes.append(build_data['tests-successes'])
self.failures.append(build_data['tests-failures'])
self.errors.append(build_data['tests-errors'])

def build_chart(self, start_build_id, end_build_id):
tests_chart = SimpleLineChart(400, 250)
all_fails = [f+e for f,e in zip(self.failures, self.errors)]
all_results = [s+af for s,af in zip(self.successes, all_fails)]

# axis
max_tests = max(all_results)
step = round(max_tests/10, 1-len(str(max_tests/10)))
total_steps = math.ceil(1.0 * max_tests/step)
tests_chart.set_axis_labels(Axis.LEFT, xrange(0, step*(total_steps+1), step))
tests_chart.set_axis_labels(Axis.BOTTOM, xrange(start_build_id, end_build_id+1))
tests_chart.set_grid(0, step/2, 5, 5)

# First value - allowed maximum
tests_chart.add_data([step*total_steps] * 2)
# All tests, failures and errors, errors
tests_chart.add_data(all_results)
tests_chart.add_data(all_fails)
tests_chart.add_data(self.errors)
# Last value is the lowest in the Y axis.
tests_chart.add_data([0] * 2)

# Fill colors
tests_chart.set_colours(['FFFFFF', '00FF00', 'FF0000', '0000FF'])
tests_chart.add_fill_range('00FF00', 1, 2)
tests_chart.add_fill_range('FF0000', 2, 3)
tests_chart.add_fill_range('0000FF', 3, 4)

return tests_chart


class ViolationsView(BaseView):
pass
1 change: 1 addition & 0 deletions django_jenkins/standalone/views.py
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ def index(request):


tests_chart = SimpleLineChart(400, 250)
tests_chart.BASE_URL = 'http://chart.googleapis.com/chart?'
# axis
max_tests = max([s+f+e for s,f,e in zip(successes,failures,errors)])
step = round(max_tests/10, 1-len(str(max_tests/10)))
1 change: 1 addition & 0 deletions django_jenkins/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ class BaseTask(object):
"""
Base interface for ci tasks
"""
view = None
option_list = []

def __init__(self, test_labels, options):
2 changes: 2 additions & 0 deletions django_jenkins/tasks/django_tests.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@


class Task(BaseTask):
view = 'django_jenkins.standalone.taskviews.TestView'

def __init__(self, test_labels, options):
super(Task, self).__init__(test_labels, options)
if not self.test_labels: