test_signal.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python3
  2. # Flexlay - A Generic 2D Game Editor
  3. # Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. import unittest
  18. import unittest.mock
  19. from flexlay.util.signal import Signal
  20. class SignalTestCase(unittest.TestCase):
  21. def setUp(self) -> None:
  22. pass
  23. def tearDown(self) -> None:
  24. pass
  25. def test_signal_args(self) -> None:
  26. signal = Signal()
  27. mock1 = unittest.mock.Mock()
  28. mock2 = unittest.mock.Mock()
  29. signal.connect(mock1)
  30. signal.connect(mock2)
  31. signal(9, 11, 13)
  32. mock1.assert_called_with(9, 11, 13)
  33. mock2.assert_called_with(9, 11, 13)
  34. self.assertEqual(mock1.call_count, 1)
  35. self.assertEqual(mock2.call_count, 1)
  36. def test_signal_connect(self) -> None:
  37. signal = Signal()
  38. mock1 = unittest.mock.Mock()
  39. mock2 = unittest.mock.Mock()
  40. signal.connect(mock1)
  41. signal.connect(mock2)
  42. signal()
  43. mock1.assert_called_with()
  44. mock2.assert_called_with()
  45. self.assertEqual(mock1.call_count, 1)
  46. self.assertEqual(mock2.call_count, 1)
  47. def test_signal_disconnect(self) -> None:
  48. signal = Signal()
  49. mock1 = unittest.mock.Mock()
  50. mock2 = unittest.mock.Mock()
  51. signal.connect(mock1)
  52. signal.connect(mock2)
  53. signal.disconnect(mock1)
  54. signal()
  55. self.assertEqual(mock1.call_count, 0)
  56. self.assertEqual(mock2.call_count, 1)
  57. if __name__ == '__main__':
  58. unittest.main()
  59. # EOF #