Skip to content

Commit

Permalink
autopep8
Browse files Browse the repository at this point in the history
  • Loading branch information
tardyp committed Jul 14, 2015
1 parent 53d08ef commit bd287ce
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion master/buildbot/plugins/__init__.py
Expand Up @@ -17,12 +17,12 @@
Buildbot plugin infrastructure
"""

from buildbot import statistics as stats
from buildbot.interfaces import IBuildSlave
from buildbot.interfaces import IBuildStep
from buildbot.interfaces import IChangeSource
from buildbot.interfaces import IScheduler
from buildbot.plugins.db import get_plugins
from buildbot import statistics as stats


__all__ = ['changes', 'schedulers', 'buildslave', 'steps', 'util', 'reporters', 'stats']
Expand Down
8 changes: 4 additions & 4 deletions master/buildbot/statistics/__init__.py
Expand Up @@ -13,13 +13,13 @@
#
# Copyright Buildbot Team Members

from buildbot.statistics.stats_service import StatsService
from buildbot.statistics.storage_backends import InfluxStorageService
from buildbot.statistics.capture import CaptureProperty
from buildbot.statistics.capture import CaptureBuildDuration
from buildbot.statistics.capture import CaptureBuildStartTime
from buildbot.statistics.capture import CaptureBuildEndTime
from buildbot.statistics.capture import CaptureBuildStartTime
from buildbot.statistics.capture import CaptureData
from buildbot.statistics.capture import CaptureProperty
from buildbot.statistics.stats_service import StatsService
from buildbot.statistics.storage_backends import InfluxStorageService

__all__ = [
'StatsService', 'InfluxStorageService', 'CaptureProperty', 'CaptureBuildDuration',
Expand Down
16 changes: 15 additions & 1 deletion master/buildbot/statistics/capture.py
Expand Up @@ -18,9 +18,11 @@


class Capture(object):

"""
Base class for all Capture* classes.
"""

def __init__(self, routingKey, callback):
self.routingKey = routingKey
self.callback = callback
Expand All @@ -39,10 +41,12 @@ def consumer(self, routingKey, msg):


class CaptureProperty(Capture):

"""
Convenience wrapper for getting statistics for filtering.
Filters out build properties specifies in the config file.
"""

def __init__(self, builder_name, property_name, callback=None):
self.builder_name = builder_name
self.property_name = property_name
Expand Down Expand Up @@ -81,9 +85,11 @@ def consumer(self, routingKey, msg):


class CaptureBuildTimes(Capture):

"""
Capture methods for capturing build start times.
"""

def __init__(self, builder_name, callback):
self.builder_name = builder_name
routingKey = ("builders", None, "builds", None, "finished")
Expand Down Expand Up @@ -111,9 +117,11 @@ def consumer(self, routingKey, msg):


class CaptureBuildStartTime(CaptureBuildTimes):

"""
Capture methods for capturing build start times.
"""

def __init__(self, builder_name, callback=None):
def default_callback(start_time):
return start_time.isoformat()
Expand All @@ -127,9 +135,11 @@ def retValParams(self, msg):


class CaptureBuildEndTime(CaptureBuildTimes):

"""
Capture methods for capturing build start times.
"""

def __init__(self, builder_name, callback=None):
def default_callback(end_time):
return end_time.isoformat()
Expand All @@ -143,9 +153,11 @@ def retValParams(self, msg):


class CaptureBuildDuration(CaptureBuildTimes):

"""
Capture methods for capturing build start times.
"""

def __init__(self, builder_name, report_in='seconds', callback=None):
def default_callback(start_time, end_time):
divisor = 1
Expand All @@ -157,7 +169,7 @@ def default_callback(start_time, end_time):
duration = end_time - start_time
# cannot use duration.total_seconds() on Python 2.6
duration = ((duration.microseconds + (duration.seconds +
duration.days * 24 * 3600) * 1e6) / 1e6)
duration.days * 24 * 3600) * 1e6) / 1e6)
return duration / divisor

if not callback:
Expand All @@ -170,9 +182,11 @@ def retValParams(self, msg):


class CaptureData(Capture):

"""
Capture methods for arbitraty data that may not be stored in the Buildbot database.
"""

def __init__(self, data_name, builder_name, callback=None):
self.data_name = data_name
self.builder_name = builder_name
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/statistics/stats_service.py
Expand Up @@ -16,14 +16,16 @@
from twisted.internet import defer
from twisted.python import log

from buildbot.util import service
from buildbot.statistics.storage_backends import StatsStorageBase
from buildbot.util import service


class StatsService(service.BuildbotService):

"""
A middleware for passing on statistics data to all storage backends.
"""

def checkConfig(self, storage_backends):
for sb in storage_backends:
if not isinstance(sb, StatsStorageBase):
Expand Down
4 changes: 4 additions & 0 deletions master/buildbot/statistics/storage_backends.py
Expand Up @@ -25,18 +25,22 @@


class StatsStorageBase(object):

"""
Base class for sub service responsible for passing on stats data to
a storage backend
"""

def postStatsValue(self, name, value, series_name, context={}):
return defer.succeed(None)


class InfluxStorageService(StatsStorageBase):

"""
Delegates data to InfluxDB
"""

def __init__(self, url, port, user, password, db, captures,
name="InfluxStorageService"):
if not InfluxDBClient:
Expand Down
12 changes: 10 additions & 2 deletions master/buildbot/test/fake/fakestats.py
Expand Up @@ -13,18 +13,20 @@
#
# Copyright Buildbot Team Members

from twisted.internet import defer
from buildbot.process import buildstep
from buildbot.statistics import capture
from buildbot.statistics import stats_service
from buildbot.statistics import storage_backends
from buildbot.statistics import capture
from buildbot.status.results import SUCCESS
from twisted.internet import defer


class FakeStatsStorageService(storage_backends.StatsStorageBase):

"""
Fake Storage service used in unit tests
"""

def __init__(self, stats=None, name='FakeStatsStorageService'):
self.stored_data = []
if not stats:
Expand All @@ -42,9 +44,11 @@ def postStatsValue(self, post_data, series_name, context={}):


class FakeBuildStep(buildstep.BuildStep):

"""
A fake build step to be used for testing.
"""

def doSomething(self):
self.setProperty("test", 10, "test")

Expand All @@ -54,9 +58,11 @@ def start(self):


class FakeStatsService(stats_service.StatsService):

"""
Fake StatsService for use in fakemaster
"""

def __init__(self, master=None, *args, **kwargs):
stats_service.StatsService.__init__(self, *args, **kwargs)
self.master = master
Expand All @@ -71,9 +77,11 @@ def master(self, value):


class FakeInfluxDBClient(object):

"""
Fake Influx module for testing on systems that don't have influxdb installed.
"""

def __init__(self, *args, **kwargs):
self.points = None

Expand Down
21 changes: 12 additions & 9 deletions master/buildbot/test/unit/test_stats_service.py
Expand Up @@ -22,8 +22,8 @@
from buildbot import config
from buildbot.statistics import capture
from buildbot.statistics import storage_backends
from buildbot.statistics.storage_backends import StatsStorageBase
from buildbot.statistics.storage_backends import InfluxStorageService
from buildbot.statistics.storage_backends import StatsStorageBase
from buildbot.test.fake import fakedb
from buildbot.test.fake import fakemaster
from buildbot.test.fake import fakestats
Expand All @@ -44,7 +44,7 @@ def setUp(self):
self.master.db.builders.addTestBuilder(builderid=builderid, name=name)

self.stats_service = fakestats.FakeStatsService(master=self.master,
storage_backends=[fakestats.FakeStatsStorageService()], name="FakeStatsService")
storage_backends=[fakestats.FakeStatsStorageService()], name="FakeStatsService")

self.stats_service.startService()

Expand Down Expand Up @@ -77,8 +77,8 @@ def test_bad_configuration(self):
def checkEqual(self, new_storage_backends):
# Check whether the new_storage_backends was set in reconfigService
registeredStorageServices = \
[s for s in self.stats_service.registeredStorageServices
if isinstance(s, StatsStorageBase)]
[s for s in self.stats_service.registeredStorageServices
if isinstance(s, StatsStorageBase)]
for s in new_storage_backends:
if s not in registeredStorageServices:
raise AssertionError("reconfigService failed."
Expand All @@ -88,6 +88,7 @@ def checkEqual(self, new_storage_backends):
class TestInfluxDB(TestStatsServicesBase, logging.LoggingMixin):
# Smooth test of influx db service. We don't want to force people to install influxdb, so we
# just disable this unit test if the influxdb module is not installed, using SkipTest

def test_influxdb_not_installed(self):
captures = [capture.CaptureProperty('test_builder', 'test')]
try:
Expand All @@ -97,10 +98,10 @@ def test_influxdb_not_installed(self):
[influxdb]
except ImportError:
self.assertRaises(config.ConfigErrors,
lambda: InfluxStorageService(
"fake_url", "fake_port", "fake_user", "fake_password", "fake_db", captures
)
)
lambda: InfluxStorageService(
"fake_url", "fake_port", "fake_user", "fake_password", "fake_db", captures
)
)

# if instead influxdb is installed, then intialize it - no errors should be reaised
else:
Expand Down Expand Up @@ -158,9 +159,11 @@ def test_storage_backend_base(self):


class TestStatsServicesConsumers(steps.BuildStepMixin, TestStatsServicesBase):

"""
Test the stats service from a fake step
"""

def setUp(self):
TestStatsServicesBase.setUp(self)
self.routingKey = ("builders", self.BUILDER_IDS[0], "builds", 1, "finished")
Expand Down Expand Up @@ -197,7 +200,7 @@ def end_build_call_consumers(self):
complete_at=build['complete_at'],
state_string=u'',
results=0,
))
))
yield defer.returnValue(None)

@staticmethod
Expand Down

0 comments on commit bd287ce

Please sign in to comment.