This commit is contained in:
Andrej730
2026-04-01 10:29:27 +05:00
parent 86bef0a254
commit 9d78df392d
13 changed files with 96 additions and 55 deletions
+9 -3
View File
@@ -36,7 +36,9 @@ class TestRunForeach:
def test_rename_single(self, model):
items = self._items(model, "IfcWall")
result = run_foreach(model, "attribute", "edit_attributes", {"product": "{id}", "attributes": '{"Name": "R"}'}, items)
result = run_foreach(
model, "attribute", "edit_attributes", {"product": "{id}", "attributes": '{"Name": "R"}'}, items
)
assert result["ok"] is True
assert result["count"] == 1
assert result["errors"] == []
@@ -44,7 +46,9 @@ class TestRunForeach:
def test_rename_multiple(self, model):
items = self._items(model, "IfcElement")
result = run_foreach(model, "attribute", "edit_attributes", {"product": "{id}", "attributes": '{"Name": "X"}'}, items)
result = run_foreach(
model, "attribute", "edit_attributes", {"product": "{id}", "attributes": '{"Name": "X"}'}, items
)
assert result["ok"] is True
assert result["count"] == len(items)
@@ -73,7 +77,9 @@ class TestRunForeach:
{"id": wall_id, "type": "IfcWall", "name": "W"},
{"id": 999999, "type": "IfcWall", "name": "Bad"},
]
result = run_foreach(model, "attribute", "edit_attributes", {"product": "{id}", "attributes": '{"Name": "Ok"}'}, items)
result = run_foreach(
model, "attribute", "edit_attributes", {"product": "{id}", "attributes": '{"Name": "Ok"}'}, items
)
assert result["ok"] is False
assert result["count"] == 1
assert len(result["errors"]) == 1
+41 -11
View File
@@ -111,8 +111,13 @@ class TestForeachCommand:
def test_foreach_rename(self, model, model_file):
walls_json = self._select_json(model, "IfcWall")
stdout, stderr, rc = run_ifcedit(
"foreach", model_file, "attribute.edit_attributes",
"--product", "{id}", "--attributes", '{"Name": "Renamed"}',
"foreach",
model_file,
"attribute.edit_attributes",
"--product",
"{id}",
"--attributes",
'{"Name": "Renamed"}',
stdin=walls_json,
)
assert rc == 0, f"stderr: {stderr}"
@@ -129,8 +134,13 @@ class TestForeachCommand:
items = json.loads(elements_json)
assert len(items) >= 2
stdout, stderr, rc = run_ifcedit(
"foreach", model_file, "attribute.edit_attributes",
"--product", "{id}", "--attributes", '{"Name": "Bulk"}',
"foreach",
model_file,
"attribute.edit_attributes",
"--product",
"{id}",
"--attributes",
'{"Name": "Bulk"}',
stdin=elements_json,
)
assert rc == 0, f"stderr: {stderr}"
@@ -140,8 +150,13 @@ class TestForeachCommand:
def test_foreach_empty_list(self, model_file):
stdout, stderr, rc = run_ifcedit(
"foreach", model_file, "attribute.edit_attributes",
"--product", "{id}", "--attributes", '{"Name": "X"}',
"foreach",
model_file,
"attribute.edit_attributes",
"--product",
"{id}",
"--attributes",
'{"Name": "X"}',
stdin="[]",
)
assert rc == 0
@@ -151,7 +166,11 @@ class TestForeachCommand:
def test_foreach_invalid_json_stdin(self, model_file):
stdout, stderr, rc = run_ifcedit(
"foreach", model_file, "root.remove_product", "--product", "{id}",
"foreach",
model_file,
"root.remove_product",
"--product",
"{id}",
stdin="not json",
)
assert rc != 0
@@ -159,7 +178,11 @@ class TestForeachCommand:
def test_foreach_not_array_stdin(self, model_file):
stdout, stderr, rc = run_ifcedit(
"foreach", model_file, "root.remove_product", "--product", "{id}",
"foreach",
model_file,
"root.remove_product",
"--product",
"{id}",
stdin='{"id": 1}',
)
assert rc != 0
@@ -167,12 +190,19 @@ class TestForeachCommand:
def test_foreach_output_to_different_file(self, model, model_file, tmp_path):
import os
output = str(tmp_path / "out.ifc")
walls_json = self._select_json(model, "IfcWall")
stdout, stderr, rc = run_ifcedit(
"foreach", model_file, "attribute.edit_attributes",
"-o", output,
"--product", "{id}", "--attributes", '{"Name": "OutFile"}',
"foreach",
model_file,
"attribute.edit_attributes",
"-o",
output,
"--product",
"{id}",
"--attributes",
'{"Name": "OutFile"}',
stdin=walls_json,
)
assert rc == 0, f"stderr: {stderr}"