-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path__init__.py
More file actions
41 lines (32 loc) · 1.14 KB
/
__init__.py
File metadata and controls
41 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
import random
from pipobot.lib.module_test import ModuleTest
from pipobot.lib.modules import SyncModule, defaultcmd
FAIL_MSG = u"On veut un entier quand même…"
OLA = ["\o/ .o. .o. .o.", ".o. \o/ .o. .o.",
".o. .o. \o/ .o.", ".o. .o. .o. \o/"]
OLA_REV = list(OLA)
OLA_REV.reverse()
class Ola(SyncModule):
def __init__(self, bot):
SyncModule.__init__(self,
bot,
desc="Fait la ola.",
name="ola")
@defaultcmd
def answer(self, sender, message):
if message == "":
message = str(random.randint(0, 1))
if not message.isdigit():
return FAIL_MSG
return OLA if int(message) % 2 == 0 else OLA_REV
class TestOla(ModuleTest):
def test_ola_fail(self):
rep = self.bot_answer("!ola qsdf")
self.assertEqual(rep, FAIL_MSG)
def test_ola_int(self):
rep = self.bot_answer("!ola 5")
self.assertEqual(rep, "\n".join(OLA_REV))
def test_ola_random(self):
rep = self.bot_answer("!ola")
self.assertIn(rep, ["\n".join(OLA), "\n".join(OLA_REV)])