Ejemplo n.º 1
0
    def test_properties(self):
        parser = Parser()

        with self.assertRaises(ValueError):
            parser.state_sizes = [1, 0, 2]
        with self.assertRaises(ValueError):
            parser.state_sizes = []
        self.assertEqual(parser.state_sizes, [1])
        self.assertEqual(parser.state_size, 1)

        parser.state_sizes = [2, 1]
        self.assertEqual(parser.state_sizes, [2, 1])
        self.assertEqual(parser.state_size, 2)
        self.assertEqual(parser.state.maxlen, 2)
        self.assertEqual(list(parser.state), ['', ''])

        parser.state.append('test')
        parser.state_size = parser.state_size
        self.assertEqual(list(parser.state), ['', 'test'])

        parser.state_sizes = [3]
        self.assertEqual(list(parser.state), ['', '', ''])
Ejemplo n.º 2
0
def test_parser_properties():
    parser = Parser()

    with pytest.raises(ValueError):
        parser.state_sizes = [1, 0, 2]
    with pytest.raises(ValueError):
        parser.state_sizes = []

    assert parser.state_sizes == [1]
    assert parser.state_size == 1

    parser.state_sizes = [2, 1]
    assert parser.state_sizes == [2, 1]
    assert parser.state_size == 2
    assert parser.state.maxlen == 2
    assert list(parser.state) == ['', '']

    parser.state.append('test')
    parser.state_size = parser.state_size
    assert list(parser.state) == ['', 'test']

    parser.state_sizes = [3]
    assert list(parser.state) == ['', '', '']