From 39fd0082efda8f726dc0959b99c2627892925d57 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Wed, 4 Mar 2015 13:52:25 +0000 Subject: [PATCH] Initial fix. --- master/buildbot/status/builder.py | 2 +- .../buildbot/test/unit/test_status_builder.py | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 master/buildbot/test/unit/test_status_builder.py diff --git a/master/buildbot/status/builder.py b/master/buildbot/status/builder.py index bd4a94b308ed..47881964b5e5 100644 --- a/master/buildbot/status/builder.py +++ b/master/buildbot/status/builder.py @@ -337,7 +337,7 @@ def setTags(self, tags): def matchesAnyTag(self, tags): # Need to guard against None with the "or []". - return set(self.tags or []).isdisjoint(tags) + return not set(self.tags or []).isdisjoint(tags) def matchesAllTags(self, tags): # Need to guard against None with the "or []". diff --git a/master/buildbot/test/unit/test_status_builder.py b/master/buildbot/test/unit/test_status_builder.py new file mode 100644 index 000000000000..552bd564f9a2 --- /dev/null +++ b/master/buildbot/test/unit/test_status_builder.py @@ -0,0 +1,67 @@ +# This file is part of Buildbot. Buildbot is free software: you can +# redistribute it and/or modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation, version 2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright Buildbot Team Members +""" +Tests for buildbot.status.builder module. +""" +from buildbot.status import builder +from buildbot.test.fake import fakemaster +from twisted.trial import unittest + + +class TestBuilderStatus(unittest.TestCase): + """ + Unit tests for BuilderStatus + """ + + def makeBuilderStatus(self): + """ + Return a new BuilderStatus. + """ + + return builder.BuilderStatus( + buildername='testing-builder', + tags=None, + master=fakemaster.make_master(), + description=None) + + def test_matchesAnyTag_no_tags(self): + """ + Return False when builder has no tags. + """ + sut = self.makeBuilderStatus() + + self.assertFalse(sut.matchesAnyTag(set())) + self.assertFalse(sut.matchesAnyTag({'any-tag', 'tag'})) + + def test_matchesAnyTag_no_match(self): + """ + Return False when requested tags don't match. + """ + sut = self.makeBuilderStatus() + sut.tags = {'one'} + + self.assertFalse(sut.matchesAnyTag(set())) + self.assertFalse(sut.matchesAnyTag({'no-such-tag'})) + self.assertFalse(sut.matchesAnyTag({'other-tag', 'tag'})) + + def test_matchesAnyTag_with_match(self): + """ + Return True when at least one of the requested tags match. + """ + sut = self.makeBuilderStatus() + sut.tags = {'one', 'two'} + + self.assertTrue(sut.matchesAnyTag({'two'})) + self.assertTrue(sut.matchesAnyTag({'two', 'one'}))