Exemplo n.º 1
0
    def test_deposit_invokes_private_deposit_method(self):
        obj = GrammarObject(label=None, keywords=['a'])
        mock_deposit = Mock()
        mock_expected = Mock()
        obj._deposit = mock_deposit
        obj._expected = mock_expected

        self.assertEqual(obj._ptr, 0)
        obj.deposit('a')

        self.assertTrue(mock_deposit.called)
        self.assertTrue(mock_expected.called)
        self.assertEqual(obj._ptr, 1)
Exemplo n.º 2
0
    def test_deposit_raises_exception_if_cannot_deposit_more(self):
        obj = GrammarObject(label=None, keywords=['a'])
        mock_deposit = Mock()
        mock_expected = Mock()
        obj._deposit = mock_deposit
        obj._expected = mock_expected

        self.assertEqual(obj._ptr, 0)
        obj.deposit('a')
        with self.assertRaises(Exception):
            obj.deposit('b')

        self.assertTrue(mock_deposit.call_count == 1)
        self.assertTrue(mock_expected.call_count == 1)
        self.assertEqual(obj._ptr, 1)
Exemplo n.º 3
0
 def test__expected__raises_exception_if_there_are_no_more_keywords(self):
     obj = GrammarObject(label=None, keywords=[])
     with self.assertRaisesRegex(Exception, 'no more keywords'):
         obj._expected()
Exemplo n.º 4
0
 def test__expected__returns_next_keyword(self):
     obj = GrammarObject(label=None, keywords=['a'])
     result = obj._expected()
     self.assertEqual(result, 'a')