<s> from __future__ import unicode_literals , absolute_import <EOL> import datetime <EOL> from pytest import fixture , raises <EOL> from six import text_type <EOL> from openvpn_status . parser import LogParser , ParsingError <EOL> @ fixture <EOL> def openvpn_status ( datadir ) : <EOL> return datadir . join ( '<STR_LIT>' ) <EOL> @ fixture <EOL> def broken_status ( datadir ) : <EOL> return datadir . join ( '<STR_LIT>' ) <EOL> def test_parser ( openvpn_status ) : <EOL> parser = LogParser . fromstring ( openvpn_status . read ( ) ) <EOL> status = parser . parse ( ) <EOL> assert len ( status . client_list ) == <NUM_LIT:3> <EOL> assert len ( status . routing_table ) == <NUM_LIT:3> <EOL> assert status . global_stats . max_bcast_mcast_queue_len == <NUM_LIT:0> <EOL> assert status . updated_at == datetime . datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:15> ) <EOL> client = status . client_list [ '<STR_LIT>' ] <EOL> assert text_type ( client . real_address ) == '<STR_LIT>' <EOL> assert text_type ( client . real_address . host ) == '<STR_LIT>' <EOL> assert client . real_address . port == <NUM_LIT> <EOL> assert client . connected_since == datetime . datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT> , <NUM_LIT:3> ) <EOL> assert client . bytes_received == <NUM_LIT> <EOL> assert client . bytes_sent == <NUM_LIT> <EOL> def test_parser_with_syntax_errors ( broken_status ) : <EOL> def catch_syntax_error ( seq ) : <EOL> datafile = broken_status . join ( '<STR_LIT>' % seq ) <EOL> parser = LogParser . fromstring ( datafile . read ( ) ) <EOL> with raises ( ParsingError ) as error : <EOL> parser . parse ( ) <EOL> return error <EOL> error = catch_syntax_error ( <NUM_LIT:0> ) <EOL> assert not error . value . args [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) <EOL> assert not error . value . args [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) <EOL> assert error . value . args [ <NUM_LIT:0> ] . endswith ( '<STR_LIT>' ) <EOL> error = catch_syntax_error ( <NUM_LIT:1> ) <EOL> assert not error . value . args [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) <EOL> assert not error . value . args [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) <EOL> assert error . value . args [ <NUM_LIT:0> ] . endswith ( '<STR_LIT>' % u'<STR_LIT>' ) <EOL> error = catch_syntax_error ( <NUM_LIT:2> ) <EOL> assert error . value . args [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> error = catch_syntax_error ( <NUM_LIT:3> ) <EOL> assert error . value . args [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> error = catch_syntax_error ( <NUM_LIT:4> ) <EOL> assert error . value . args [ <NUM_LIT:0> ] == '<STR_LIT>' % u'<STR_LIT>' <EOL> error = catch_syntax_error ( <NUM_LIT:5> ) <EOL> assert error . value . args [ <NUM_LIT:0> ] == '<STR_LIT>' % u'<STR_LIT>' <EOL> error = catch_syntax_error ( <NUM_LIT:6> ) <EOL> assert error . value . args [ <NUM_LIT:0> ] == '<STR_LIT>' % u'<STR_LIT>' </s>
