def test_emit_keep_emits(self):
     """
     ``emit_keep`` emits a ``message`` event.
     """
     cleaner = Cleaner()
     mocked = mock.MagicMock()
     cleaner.ee.on("message", mocked)
     cleaner.emit_keep("Foo", "reason")
     self.assertEqual(mocked.call_count, 1)
     self.assertEqual(mocked.call_args[0], ("Kept Foo, because reason.", ))
Exemple #2
0
 def test_emit_keep_emits(self):
     """
     ``emit_keep`` emits a ``message`` event.
     """
     cleaner = Cleaner()
     mocked = mock.MagicMock()
     cleaner.ee.on("message", mocked)
     cleaner.emit_keep("Foo", "reason")
     self.assertEqual(mocked.call_count, 1)
     self.assertEqual(mocked.call_args[0], ("Kept Foo, because reason.", ))
 def test_emit_keep_emits_a_different_message_when_noop_True(self):
     """
     ``emit_keep`` emits a ``message`` event when ``noop`` is ``True``.
     """
     cleaner = Cleaner(noop=True)
     mocked = mock.MagicMock()
     cleaner.ee.on("message", mocked)
     cleaner.emit_keep("Foo", "reason")
     self.assertEqual(mocked.call_count, 1)
     self.assertEqual(mocked.call_args[0],
                      ("Would keep Foo, because reason.", ))
Exemple #4
0
 def test_emit_keep_emits_a_different_message_when_noop_True(self):
     """
     ``emit_keep`` emits a ``message`` event when ``noop`` is ``True``.
     """
     cleaner = Cleaner(noop=True)
     mocked = mock.MagicMock()
     cleaner.ee.on("message", mocked)
     cleaner.emit_keep("Foo", "reason")
     self.assertEqual(mocked.call_count, 1)
     self.assertEqual(mocked.call_args[0],
                      ("Would keep Foo, because reason.", ))
    def test_emit_keep_does_not_call_emit_message_if_no_listeners(self):
        """
        ``emit_keep`` does not call ``emit_message`` when there are
        no listeners.
        """
        cleaner = Cleaner()
        with mock.patch('lexicography.cleaning.Cleaner.emit_message') \
                as emit_message_mock:
            cleaner.emit_keep("Foo", "reason")
            self.assertEqual(emit_message_mock.call_count, 0)

            # Check that it is going to be called once listeners are added.
            cleaner.ee.on("message", mock.MagicMock())
            cleaner.emit_keep("Foo", "reason")
            self.assertEqual(emit_message_mock.call_count, 1)
Exemple #6
0
    def test_emit_keep_does_not_call_emit_message_if_no_listeners(self):
        """
        ``emit_keep`` does not call ``emit_message`` when there are
        no listeners.
        """
        cleaner = Cleaner()
        with mock.patch('lexicography.cleaning.Cleaner.emit_message') \
                as emit_message_mock:
            cleaner.emit_keep("Foo", "reason")
            self.assertEqual(emit_message_mock.call_count, 0)

            # Check that it is going to be called once listeners are added.
            cleaner.ee.on("message", mock.MagicMock())
            cleaner.emit_keep("Foo", "reason")
            self.assertEqual(emit_message_mock.call_count, 1)