import json from lxml import etree from server import validate_port_sizes def test_flexible_validation(): xml = """ """ parser = etree.XMLParser(remove_blank_text=True) tree = etree.fromstring(xml.encode('utf-8'), parser) errors = validate_port_sizes(tree) print(f"Flexible case errors: {json.dumps(errors, indent=2)}") # Should pass because B1's expected [-1,-2] matches [5,1] (wildcard) # And L1 link from [1,1] to [5,1] should honestly FAIL if they are strictly matched, # BUT in Scicos, if one end is -1, it usually "adapts". # Wait, in my server.py, I check src_size vs dst_size. # If P1 is [5,1] and P3 is [1,1], dims_match([1,1], [5,1]) is False. # UNLESS one of them is marked as wildcard in the XML itself. # In Xcos XML, if a port is inherited, it usually has dataLines="-1". assert len(errors) > 0 # Currently should fail due to link mismatch [1,1] != [5,1] def test_wildcards_in_xml(): xml = """ """ parser = etree.XMLParser(remove_blank_text=True) tree = etree.fromstring(xml.encode('utf-8'), parser) errors = validate_port_sizes(tree) print(f"Wildcard in XML errors: {json.dumps(errors, indent=2)}") assert len(errors) == 0 # Should pass because P1 is negative in XML if __name__ == "__main__": test_flexible_validation() test_wildcards_in_xml() print("Flexible tests passed!")