Skip to content

Commit

Permalink
Merge pull request #2630 from tardyp/warnings
Browse files Browse the repository at this point in the history
remove all warnings from the unit tests
  • Loading branch information
tardyp committed Jan 24, 2017
2 parents 1e84c6f + 97392f3 commit 4ccba96
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 119 deletions.
1 change: 1 addition & 0 deletions common/code_spelling_ignore_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ builbot
buildable
buildbot
buildbots
buildbotNetUsageData
buildbot's
buildbotting
builddir
Expand Down
24 changes: 15 additions & 9 deletions master/buildbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def warnDeprecated(version, msg):
category=ConfigWarning,
)

_in_unit_tests = False


def loadConfigDict(basedir, configFileName):
if not os.path.isdir(basedir):
Expand Down Expand Up @@ -392,15 +394,19 @@ def copy_str_or_callable_param(name, alt_key=None):
check_type=string_types, check_type_name='a string or callable', can_be_callable=True)

if "buildbotNetUsageData" not in config_dict:
warnDeprecated(
'0.9.0',
'`buildbotNetUsageData` is not configured and defaults to basic\n'
'This parameter helps the buildbot development team to understand the installation base\n'
'No personal information is collected.\n'
'Only installation software version info and plugin usage is sent\n'
'You can `opt-out` by setting this variable to None\n'
'Or `opt-in` for more information by setting it to "full"\n'
)
if _in_unit_tests:
self.buildbotNetUsageData = None
else:
warnDeprecated(
'0.9.0',
'`buildbotNetUsageData` is not configured and defaults to basic.\n'
'This parameter helps the buildbot development team to understand'
' the installation base.\n'
'No personal information is collected.\n'
'Only installation software version info and plugin usage is sent.\n'
'You can `opt-out` by setting this variable to None.\n'
'Or `opt-in` for more information by setting it to "full".\n'
)
copy_str_or_callable_param('buildbotNetUsageData')

copy_int_param('changeHorizon')
Expand Down
5 changes: 3 additions & 2 deletions master/buildbot/data/resultspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from __future__ import print_function
from future.utils import iteritems

import sqlalchemy as sa

from twisted.python import log

from buildbot.data import base
Expand Down Expand Up @@ -251,8 +253,7 @@ def applyToSQLQuery(self, query):
self.filters = unmatched_filters
self.order = unmatched_order
return query, None

count_query = query.alias('q').count()
count_query = sa.select([sa.func.count()]).select_from(query.alias('query'))
self.order = None
self.filters = []
# finally, slice out the limit/offset
Expand Down
33 changes: 23 additions & 10 deletions master/buildbot/monkeypatches/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ def patch_python14653():


@onlyOnce
def patch_servicechecks():
from buildbot.monkeypatches import servicechecks
servicechecks.patch()
def patch_testcase_timeout():
import unittest
import os
# any test that should take more than 5 second should be annotated so.
unittest.TestCase.timeout = 5

# but we know that the DB tests are very slow, so we increase a bit that value for
# real database tests
if os.environ.get("BUILDBOT_TEST_DB_URL", None) is not None:
unittest.TestCase.timeout = 120


@onlyOnce
def patch_testcase_assert_raises_regexp():
# pythons before 2.7 does not have TestCase.assertRaisesRegexp() method
# add our local implementation if needed
if sys.version_info[:2] < (2, 7):
from buildbot.monkeypatches import testcase_assert
testcase_assert.patch()
def patch_servicechecks():
from buildbot.monkeypatches import servicechecks
servicechecks.patch()


@onlyOnce
Expand Down Expand Up @@ -83,11 +87,20 @@ def patch_decorators():
decorators.patch()


@onlyOnce
def patch_config_for_unit_tests():
from buildbot import config
# by default, buildbot.config warns about not configured buildbotNetUsageData.
# its important for users to not leak information, but unneeded and painful for tests
config._in_unit_tests = True


def patch_all(for_tests=False):
if for_tests:
patch_servicechecks()
patch_testcase_assert_raises_regexp()
patch_testcase_timeout()
patch_decorators()
patch_mysqlclient_warnings()
patch_config_for_unit_tests()

patch_python14653()
68 changes: 0 additions & 68 deletions master/buildbot/monkeypatches/testcase_assert.py

This file was deleted.

18 changes: 13 additions & 5 deletions master/buildbot/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,16 @@
message_pattern=r"'buildbot\.buildslave\.openstack' module is deprecated"):
import buildbot.buildslave.openstack as _ # noqa

# All deprecated modules should be loaded, consider future
# DeprecatedWorkerModuleWarning in tests as errors.
# All DeprecatedWorkerNameWarning warnings should be explicitly caught too,
# so fail on any DeprecatedWorkerAPIWarning.
warnings.filterwarnings('error', category=DeprecatedWorkerAPIWarning)
# All deprecated modules should be loaded, consider future warnings in tests as errors.
# In order to not pollute the test outputs,
# warnings in tests shall be forcefully tested with assertProducesWarning,
# or shutdown using the warning module
warnings.filterwarnings('error')
# if buildbot_worker is installed in pip install -e mode, then the docker directory will
# match "import docker", and produce a warning.
# We just suppress this warning instead of doing silly workaround.
warnings.filterwarnings('ignore', "Not importing directory.*docker': missing __init__.py",
category=ImportWarning)

# FIXME: needs to be sorted out (#3666)
warnings.filterwarnings('ignore', "Invalid utf8 character string")
1 change: 1 addition & 0 deletions master/buildbot/test/integration/test_stop_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def nextBuild(*args, **kwargs):


class TriggeringMaster(RunMasterBase):
timeout = 120
change = dict(branch="master",
files=["foo.c"],
author="me@foo.com",
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/integration/test_www.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def setUp(self):
master.www.setServiceParent(master)
yield master.www.startService()
yield master.www.reconfigServiceWithBuildbotConfig(master.config)
master.www.site.sessionFactory = mock.Mock(return_value=mock.Mock())
session = mock.Mock()
session.uid = "0"
master.www.site.sessionFactory = mock.Mock(return_value=session)

# now that we have a port, construct the real URL and insert it into
# the config. The second reconfig isn't really required, but doesn't
Expand Down
13 changes: 11 additions & 2 deletions master/buildbot/test/unit/test_buildbot_net_usage_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
from twisted.trial import unittest

import buildbot.buildbot_net_usage_data
from buildbot import config
from buildbot.buildbot_net_usage_data import _sendBuildbotNetUsageData
from buildbot.buildbot_net_usage_data import computeUsageData
from buildbot.config import BuilderConfig
from buildbot.config import ConfigWarning
from buildbot.master import BuildMaster
from buildbot.plugins import steps
from buildbot.process.factory import BuildFactory
from buildbot.schedulers.forcesched import ForceScheduler
from buildbot.test.util.integration import DictLoader
from buildbot.test.util.warnings import assertProducesWarning
from buildbot.worker.base import Worker


Expand Down Expand Up @@ -68,7 +71,11 @@ def getBaseConfig(self):
}

def test_basic(self):
master = self.getMaster(self.getBaseConfig())
self.patch(config, "_in_unit_tests", False)
with assertProducesWarning(
ConfigWarning,
message_pattern=r"`buildbotNetUsageData` is not configured and defaults to basic."):
master = self.getMaster(self.getBaseConfig())
data = computeUsageData(master)
self.assertEqual(sorted(data.keys()),
sorted(['versions', 'db', 'platform', 'installid', 'mq', 'plugins', 'www_plugins']))
Expand Down Expand Up @@ -101,13 +108,15 @@ def test_urllib(self):
self.patch(buildbot.buildbot_net_usage_data, '_sendWithRequests', lambda _, __: None)

class FakeRequest(object):

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

open_url = []

class urlopen(object):

def __init__(self, r):
self.request = r
open_url.append(self)
Expand All @@ -124,7 +133,7 @@ def close(self):
self.assertEqual(len(open_url), 1)
self.assertEqual(open_url[0].request.args,
('https://events.buildbot.net/events/phone_home',
'{"foo": "bar"}', {'Content-Length': 14, 'Content-Type': 'application/json'}))
'{"foo": "bar"}', {'Content-Length': 14, 'Content-Type': 'application/json'}))

def test_real(self):
if "TEST_BUILDBOTNET_USAGEDATA" not in os.environ:
Expand Down
2 changes: 2 additions & 0 deletions master/buildbot/test/unit/test_changes_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


class TestChangeSource(changesource.ChangeSourceMixin, unittest.TestCase):
timeout = 120

class Subclass(base.ChangeSource):
pass
Expand Down Expand Up @@ -77,6 +78,7 @@ def test_activation(self):


class TestPollingChangeSource(changesource.ChangeSourceMixin, unittest.TestCase):
timeout = 120

class Subclass(base.PollingChangeSource):
pass
Expand Down
Loading

0 comments on commit 4ccba96

Please sign in to comment.