def setUp(self): # unregister the original plugin self.stackoverflow_regex, self.stackoverflow_function = registry.plugins['stackoverflow'] registry.unregister('stackoverflow') # register a mock, just to verify if the regex is working self.called = False self.tag = None self.limit = 50 def stackoverflow_mock(limit=None, tag=None): self.called = True self.tag = tag self.limit = int(limit) if limit else 50 registry.register('stackoverflow', self.stackoverflow_regex, stackoverflow_mock) self.protocol = EizzekProtocol()
class RegexTestCase(unittest.TestCase): def setUp(self): # unregister the original plugin self.stackoverflow_regex, self.stackoverflow_function = registry.plugins['stackoverflow'] registry.unregister('stackoverflow') # register a mock, just to verify if the regex is working self.called = False self.tag = None self.limit = 50 def stackoverflow_mock(limit=None, tag=None): self.called = True self.tag = tag self.limit = int(limit) if limit else 50 registry.register('stackoverflow', self.stackoverflow_regex, stackoverflow_mock) self.protocol = EizzekProtocol() def tearDown(self): # undo de mock registry.unregister('stackoverflow') registry.register('stackoverflow', self.stackoverflow_regex, self.stackoverflow_function) def test_simple(self): self.protocol.match('stackoverflow') assert self.called assert self.tag is None assert 50 == self.limit def test_tagged(self): self.protocol.match('stackoverflow python') assert self.called assert 'python' == self.tag assert 50 == self.limit def test_limit(self): self.protocol.match('stackoverflow 10') assert self.called assert self.tag is None assert 10 == self.limit def test_tagged_limit(self): self.protocol.match('stackoverflow 15 python') assert self.called assert 'python' == self.tag assert 15 == self.limit def test_different_tags(self): tags = ('c++', 'c#', 'regular-language', 'asp.net', '.net', 'actionscript-3') for tag in tags: self.protocol.match('stackoverflow ' + tag) assert self.called assert tag == self.tag self.called, self.tag = False, None