Navigation Menu

Skip to content

Commit

Permalink
fix passing of unrelated warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rutsky committed Feb 6, 2016
1 parent b249888 commit 4317fc2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions master/buildbot/test/unit/test_worker_transition.py
Expand Up @@ -31,6 +31,8 @@
from buildbot.worker_transition import define_old_worker_method
from buildbot.worker_transition import define_old_worker_property
from buildbot.worker_transition import deprecatedWorkerModuleAttribute
from twisted.python.deprecate import deprecatedModuleAttribute
from twisted.python.versions import Version


class CompatNameGeneration(unittest.TestCase):
Expand Down Expand Up @@ -81,6 +83,30 @@ def test_produces_warning(self):
S = buildbot_module.Slave
self.assertIdentical(S, Worker)

def test_not_catched_warning(self):
buildbot_module = new.module('buildbot_module')
buildbot_module.deprecated_attr = 1
with mock.patch.dict(sys.modules,
{'buildbot_module': buildbot_module}):
deprecatedModuleAttribute(Version("Buildbot", 0, 9, 0),
"test message",
"buildbot_module",
"deprecated_attr")

# Overwrite with Twisted's module wrapper.
import buildbot_module

warnings = self.flushWarnings([self.test_not_catched_warning])
self.assertEqual(len(warnings), 0)

# Should produce warning
buildbot_module.deprecated_attr

warnings = self.flushWarnings([self.test_not_catched_warning])
self.assertEqual(len(warnings), 1)
self.assertEqual(warnings[0]['category'], DeprecationWarning)
self.assertIn("test message", warnings[0]['message'])

def test_explicit_compat_name(self):
Worker = type("Worker", (object,), {})
buildbot_module = new.module('buildbot_module')
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/worker_transition.py
Expand Up @@ -157,12 +157,12 @@ def setupWorkerTransition():
default_warn_method = getWarningMethod()

def custom_warn_method(message, category, stacklevel):
if stacklevel is not None:
stacklevel += 1
if _WORKER_WARNING_MARK in message:
# Message contains our mark - it's Worker API Renaming warning,
# issue it appropriately.
message = message.replace(_WORKER_WARNING_MARK, "")
if stacklevel is not None:
stacklevel += 1
warnings.warn(
DeprecatedWorkerNameWarning(message), message, stacklevel)
else:
Expand Down

0 comments on commit 4317fc2

Please sign in to comment.