def test_parser_spam_value_success(data, value, score, threshold): p = Parser(data) result = p.spam_value() assert result['value'] is value assert result['score'] == pytest.approx(score) assert result['threshold'] == pytest.approx(threshold)
def test_parser_skip(func): p = Parser(b'data') p.test = func p.skip(p.test) assert p.test.called
def test_parser_headers(): p = Parser( b'Content-length : 42\r\nUser : username\r\nCustom : header\r\nInvalidHeader\r\n' ) result = p.headers() expected = (ContentLength, User, XHeader) for parsed_header, expected_header in zip(result, expected): assert isinstance(parsed_header, expected_header)
def test_parser_request(data): p = Parser(data) assert isinstance(p.request(), Request)
def test_parser_spamd_protocol(): p = Parser(b'SPAMD') assert p.spamd_protocol() == 'SPAMD'
def test_parser_consume_fail(): p = Parser(b'data') with pytest.raises(ParseError): p.consume(rb'invalid')
def test_parser_compress_value_fail(): p = Parser(b'invalid') with pytest.raises(ParseError): p.compress_value()
def test_parser_advance(): p = Parser(b'data') p.advance(3) assert p.index == 3
def test_parser_message_class_value_success(data, expected): p = Parser(data) result = p.message_class_value() assert result == expected
def test_parser_user_value_success(): p = Parser(b' user-name_123 ') assert p.user_value() == "user-name_123"
def test_parser_response(data): p = Parser(data) assert isinstance(p.response(), Response)
def test_parser_content_length_value_success(data, expected): p = Parser(data) result = p.content_length_value() assert result == expected
def test_parser_spam_value_fail(): p = Parser(b'invalid') with pytest.raises(ParseError): p.spam_value()
def test_parser_set_remove_value_fail(): p = Parser(b'invalid') with pytest.raises(ParseError): p.set_remove_value()
def test_parser_set_remove_value_success(data, expected): p = Parser(data) result = p.set_remove_value() assert isinstance(result, ActionOption) assert result == expected
def test_parser_message_class_value_fail(): p = Parser(b'invalid') with pytest.raises(ParseError): p.message_class_value()
def test_parser_status_code(data, expected): p = Parser(data) assert p.status_code() == expected
def test_parser_header(data, expected): p = Parser(data) result = p.header() assert isinstance(result, expected)
def test_parser_message(): p = Parser(b'This is a message\r\n') assert p.message() == 'This is a message'
def test_parser_end(index, expected): p = Parser(b'data') p.index = index assert p.end() == expected
def test_parser_instantiates_with_string(): p = Parser(b'data') assert 'p' in locals() assert p.string == b'data' assert p.index == 0
def test_parser_match_fail(): p = Parser(b'data') assert p.match(rb'invalid') is None
def test_parser_current(): p = Parser(b'data') assert p.current() == b'data'
def test_parser_content_length_value_fail(): p = Parser(b'abcdef') with pytest.raises(ParseError): p.content_length_value()
def test_parser_match_success(): p = Parser(b'data') assert p.match(rb'data').group() == b'data'
def test_parser_spamc_protocol(): p = Parser(b'SPAMC') assert p.spamc_protocol() == "SPAMC"
def test_parser_consume_success(): p = Parser(b'data') result = p.consume(rb'data') assert result assert p.index == 4
def test_parser_instantiates(): p = Parser() assert 'p' in locals() assert p.string == b'' assert p.index == 0
def test_parser_method(data, expected): p = Parser(data) assert p.method() == expected
def test_parser_compress_value_success(data): p = Parser(data) result = p.compress_value() assert result == "zlib"