예제 #1
0
class ContextualExtensionTestCase(TestCase):

    def setUp(self):
        self.ext = ContextualExtension(mock_bot())

    def test_contextualize_not_found(self):
        self.ext.context = r'foo'
        msg = Mock(message='bar', response=None)
        self.ext.contextualize(msg)
        assert not msg.response

    def test_contextualize_returns_many(self):
        self.ext.allow_many = True
        self.ext.context = r'foo[\d]+'
        self.ext.response_fmt = '%(response)s'
        msg = Mock(message='two things: foo1 and foo2')

        self.ext.contextualize(msg)
        assert msg.response == 'foo1, foo2'

    def test_contextualize_returns_one(self):
        self.ext.allow_many = False
        self.ext.context = r'foo[\d]+'
        self.ext.response_fmt = '%(response)s'
        msg = Mock(message='two things: foo1 and foo2')

        self.ext.contextualize(msg)
        assert msg.response == 'foo1'
예제 #2
0
class ContextualExtensionTestCase(TestCase):

    def setUp(self):
        self.ext = ContextualExtension(mock_bot())

    def test_contextualize_not_found(self):
        self.ext.context = r'foo'
        msg = Mock(message='bar', response=None)
        self.ext.contextualize(msg)
        assert not msg.response

    def test_contextualize_returns_many(self):
        self.ext.allow_many = True
        self.ext.context = r'foo[\d]+'
        self.ext.response_fmt = '%(response)s'
        msg = Mock(message='two things: foo1 and foo2')

        self.ext.contextualize(msg)
        assert msg.response == 'foo1 foo2'

    def test_contextualize_returns_one(self):
        self.ext.allow_many = False
        self.ext.context = r'foo[\d]+'
        self.ext.response_fmt = '%(response)s'
        msg = Mock(message='two things: foo1 and foo2')

        self.ext.contextualize(msg)
        assert msg.response == 'foo1'

    def test_contextualize_no_duplicates(self):
        self.ext.allow_many = True
        self.ext.context = r'foo[\d]+'
        self.ext.response_fmt = '%(response)s'
        msg = Mock(message='foo1 foo1 foo1')

        self.ext.contextualize(msg)
        assert msg.response == 'foo1'
예제 #3
0
 def setUp(self):
     self.ext = ContextualExtension(mock_bot())
예제 #4
0
 def setUp(self):
     self.ext = ContextualExtension(mock_bot())