Exemplo n.º 1
0
class CharacterStreamTest(TestCase):
    def setUp(self):
        self._text = "sample text"
        self._handler = MagicMock()
        self._stream = Stream(iter(self._text), self._handler)

    def test_returns_all_characters(self):
        self.assertEqual(self._text, "".join(self._stream.take_all()))

    def test_triggers_handler(self):
        self._stream.take_all()
        self.assertEqual(len(self._text), self._handler.call_count)

    def test_look_ahead_does_not_trigger_handler(self):
        self._stream.look_ahead()
        self._handler.assert_not_called()
Exemplo n.º 2
0
class ListStreamTest(TestCase):
    def setUp(self):
        self._text = "sample text"
        self._handler = MagicMock()
        self._stream = Stream([c for c in self._text], self._handler)

    def test_returns_all_characters(self):
        self.assertEqual(self._text, "".join(self._stream.take_all()))
Exemplo n.º 3
0
class CharacterStreamTest(TestCase):

    def setUp(self):
        self._text = "sample text"
        self._handler = MagicMock()
        self._stream = Stream(iter(self._text), self._handler)

    def test_returns_all_characters(self):
        self.assertEqual(self._text, "".join(self._stream.take_all()))

    def test_triggers_handler(self):
        self._stream.take_all()
        self.assertEqual(len(self._text), self._handler.call_count)

    def test_look_ahead_does_not_trigger_handler(self):
        self._stream.look_ahead()
        self._handler.assert_not_called()
Exemplo n.º 4
0
class ListStreamTest(TestCase):

    def setUp(self):
        self._text = "sample text"
        self._handler = MagicMock()
        self._stream = Stream([c for c in self._text], self._handler)

    def test_returns_all_characters(self):
        self.assertEqual(self._text, "".join(self._stream.take_all()))
Exemplo n.º 5
0
class ListStreamTest(TestCase):
    def setUp(self):
        self._text = "sample text"
        self._handler = MagicMock()
        self._stream = Stream([c for c in self._text], self._handler)

    def test_returns_all_characters(self):
        self._verify_stream_content_is(self._text)

    def test_push(self):
        self._stream.push("abcdef")
        self._verify_stream_content_is("abcdef" + self._text)

    def _verify_stream_content_is(self, expected):
        self.assertEqual(expected, "".join(self._stream.take_all()))