import math import struct import pytest from app.parser.geometry import point,coordinate,transform_point,color from app.models.schematic import Point from app.parser.record_decoder import detect_format,binary_records,properties,ParseError from app.parser.schdoc_parser import parse_schdoc from app.parser.ole_reader import read_document @pytest.mark.parametrize('data,expected',[(b'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1','ole'),(b'|HEADER=x','ascii'),(b'\xef\xbb\xbf|HEADER=x','ascii')]) def test_detect(data,expected): assert detect_format(data)==expected @pytest.mark.parametrize('data',[b'',b'
',b'PK\x03\x04',b'\0'*1024]) def test_unknown_format(data): with pytest.raises(ParseError): detect_format(data) def test_length_prefix_and_indexing(): payloads=[b'|HEADER=Example\0',b'|RECORD=31\0',b'|RECORD=27|X1=42\0'] stream=b''.join(struct.pack('=10 and obj.bounds.x+obj.bounds.width<=60 assert obj.bounds.y>=-40 and obj.bounds.y+obj.bounds.height<=-10 assert any(p.clip for p in d.primitives if p.object_id==obj.id) def test_invalid_record_type_is_preserved(ascii_schematic): d=parse_schdoc(ascii_schematic+b'|RECORD=abc|OriginalField=value\n','test.SchDoc','test') assert d.objects[-1].properties['ORIGINALFIELD']=='value' assert any(w.code=='malformed_record' for w in d.diagnostics) def test_implementation_parameter_is_not_drawn(ascii_schematic): data=ascii_schematic+b'|RECORD=48|OwnerIndex=1\n|RECORD=41|OwnerIndex=9|Name=ModelParam|Text=must-not-render\n' d=parse_schdoc(data,'test.SchDoc','test') assert not d.objects[-1].visible assert not any(p.text=='must-not-render' for p in d.primitives)