Commits

David Schneider committed 83ae0f7

fix tests for ircbot

Comments (0)

Files changed (2)

bot2/pypybuildbot/ircbot.py

     return s
 
 
-def extract_username(build):
+def get_build_information(build):
     owner = build.getProperty("owner")
     reason = build.getProperty("reason")
     return ": ".join(k for k in (owner, reason) if k)
 def get_description_for_build(url, build):
     url = color(url, 'GRAY')  # in gray
     infos = []
-    username = extract_username(build)
-    if username:
-        infos.append(color(username, 'BLUE'))  # in blue
+    buildinfo = get_build_information(build)
+    if buildinfo:
+        infos.append(color(buildinfo, 'BLUE'))  # in blue
     #
     branch = build.getProperty('branch')
     if branch:

bot2/pypybuildbot/test/test_ircbot.py

 from pypybuildbot import ircbot
 
+
 def setup_module(mod):
     ircbot.USE_COLOR_CODES = False
 
+
 def teardown_module(mod):
     ircbot.USE_COLOR_CODES = True
 
+
 class FakeBuild(object):
 
-    def __init__(self, reason=None, source=None):
-        self.reason = reason
-        self.source = source
+    def __init__(self, reason=None, owner=None, branch=None):
+        self.properties = {'owner': owner, 'branch': branch, 'reason': reason}
 
-    def getReason(self):
-        return self.reason
+    def getProperty(self, name):
+        return self.properties.get(name, None)
 
-    def getSourceStamp(self):
-        return self.source
 
-class FakeSource(object):
-
-    def __init__(self, branch):
-        self.branch = branch
-
-def test_extract_username():
-    a = FakeBuild("The web-page 'force build' button was pressed by 'antocuni': foo")
+def test_get_build_information():
+    a = FakeBuild(owner='antocuni',
+            reason="The web-page 'force build' button was pressed")
     b = FakeBuild("The web-page 'force build' button was ...")
-    assert ircbot.extract_username(a) == 'antocuni'
-    assert ircbot.extract_username(b) is None
+    assert ircbot.get_build_information(a) == \
+            "antocuni: The web-page 'force build' button was pressed"
+    assert ircbot.get_build_information(b) == \
+            "The web-page 'force build' button was ..."
 
 
 def test_get_description_for_build():
-    a = FakeBuild('foobar', source=FakeSource(None))
+    a = FakeBuild()
     msg = ircbot.get_description_for_build("http://myurl", a)
     assert msg == "http://myurl"
 
-    a = FakeBuild("The web-page 'force build' button was pressed by 'antocuni': foo",
-                  source=FakeSource(None))
+    a = FakeBuild(owner='antocuni',
+            reason="The web-page 'force build' button was pressed")
     msg = ircbot.get_description_for_build("http://myurl", a)
-    assert msg == "http://myurl [antocuni]"
+    assert msg == "http://myurl [antocuni: " \
+                  + "The web-page 'force build' button was pressed]"
 
-    a = FakeBuild('foobar', source=FakeSource('mybranch'))
+    a = FakeBuild(branch='mybranch')
     msg = ircbot.get_description_for_build("http://myurl", a)
     assert msg == "http://myurl [mybranch]"
 
-    a = FakeBuild("The web-page 'force build' button was pressed by 'antocuni': foo",
-                  source=FakeSource('mybranch'))
+    a = FakeBuild(owner='antocuni', branch='mybranch')
     msg = ircbot.get_description_for_build("http://myurl", a)
     assert msg == "http://myurl [antocuni, mybranch]"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.