"""Test the Neo4J parser.""" import json import pytest from neoparse import NeoMaxwells from neoparse import ParserError TEST_EVENTS_FILE = 'tests/test_events.json' TEST_INCORRECT_EVENTS_FILE = 'tests/incorrect_event.json' @pytest.fixture def test_events(): """Neo4J events list for test.""" with open(TEST_EVENTS_FILE, 'r') as test_file: events = json.load(test_file) yield events @pytest.fixture def incorrect_events(): """Neo4J incorrect events.""" with open(TEST_INCORRECT_EVENTS_FILE, 'r') as test_file: events = json.load(test_file) yield events @pytest.mark.parametrize('include_schema', [True, False]) def test_parse_neo4j_events(test_events, include_schema): """Test parsing neo4j events.""" parser = NeoMaxwells('test_neo4j', include_schema) for event in test_events['events']: expected_output = event['output'] output = parser.parse(event['input']) if include_schema: expected_output = { 'payload': event['output'], 'schema': parser.SCHEMA } assert output == expected_output def test_parse_incorrect_event(incorrect_events): """Test parsing incorrect event.""" parser = NeoMaxwells('test_neo4j') for event in incorrect_events['events']: with pytest.raises(ParserError): parser.parse(event)