Files
IfcOpenShell/src/ifcquery/tests/test_validate.py
T
Bruno Postle 7cd40bf8cb Add ifcquery CLI tool for IFC model interrogation (#7845)
ifcquery is a new command-line tool for querying and inspecting IFC models. All output is JSON.

Subcommands:

    summary — schema version, entity counts, project metadata
    tree — full spatial hierarchy (Project → Site → Building → Storeys → Spaces → Elements)
    info <id> — deep inspection of any entity by step ID (attributes, psets, placement matrix, type, material)
    select <query> — filter elements using ifcopenshell selector syntax
    relations <id> — relationships for an element; --traverse up walks to IfcProject
    clash <id> — geometric intersection and clearance detection
    validate — schema/constraint validation; --rules adds EXPRESS checks
    schedule — work schedules with nested task trees
    cost — cost schedules with nested cost item trees
    schema <class> — IFC class documentation from the model's schema version
    plot — SVG plan drawing
    render — 3D geometry rendering
    contexts — geometric representation contexts
    materials — material assignments

Usage:

python3 -m ifcquery <file.ifc> <subcommand> [args]

Generated with the assistance of an AI coding tool.
2026-03-23 23:29:32 +00:00

48 lines
1.7 KiB
Python

# This file was generated with the assistance of an AI coding tool.
from __future__ import annotations
import ifcopenshell
import ifcopenshell.api.project
import pytest
from ifcquery.validate import validate
class TestValidate:
def test_valid_model_returns_valid_true(self, model):
result = validate(model)
assert result["valid"] is True
assert isinstance(result["issues"], list)
def test_valid_model_has_no_issues(self, model):
result = validate(model)
assert result["issues"] == []
def test_empty_model_is_valid(self):
f = ifcopenshell.api.project.create_file()
result = validate(f)
assert result["valid"] is True
assert result["issues"] == []
def test_result_has_expected_keys(self, model):
result = validate(model)
assert "valid" in result
assert "issues" in result
def test_express_rules_flag_accepted(self, model):
# Just verify it runs without error; express rules may add/not add issues
result = validate(model, express_rules=True)
assert "valid" in result
assert isinstance(result["issues"], list)
def test_issue_has_level_and_message(self, model):
# Force an issue by manually breaking the model (invalid IfcWall attribute)
f = ifcopenshell.file()
# Create a raw IfcWall with deliberately wrong type for GlobalId (use int)
# We just check structure if any issues appear; on well-formed models there are none.
result = validate(model)
# Even if no issues, the structure contract must hold for any issues present
for issue in result["issues"]:
assert "level" in issue
assert "message" in issue