A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

40 lignes
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. import unittest
  3. import support
  4. from commands.calc import Command
  5. class TestCalc(support.CommandTestCase):
  6. def setUp(self):
  7. super(TestCalc, self).setUp(Command)
  8. def test_check(self):
  9. self.assertFalse(self.command.check(self.make_msg("bloop")))
  10. self.assertFalse(self.command.check(self.make_join()))
  11. self.assertTrue(self.command.check(self.make_msg("calc")))
  12. self.assertTrue(self.command.check(self.make_msg("CALC", "foo")))
  13. def test_ignore_empty(self):
  14. self.command.process(self.make_msg("calc"))
  15. self.assertReply("what do you want me to calculate?")
  16. def test_maths(self):
  17. tests = [
  18. ("2 + 2", "2 + 2 = 4"),
  19. ("13 * 5", "13 * 5 = 65"),
  20. ("80 / 42", "80 / 42 = 40/21 (approx. 1.9047619047619047)"),
  21. ("2/0", "2/0 = undef"),
  22. ("π", "π = 3.141592653589793238"),
  23. ]
  24. for test in tests:
  25. q = test[0].strip().split()
  26. self.command.process(self.make_msg("calc", *q))
  27. self.assertReply(test[1])
  28. if __name__ == "__main__":
  29. unittest.main(verbosity=2)