def test_match_default_values(): """An attribute query should match the default value if the attribute is not present. """ text = Text() assert text.dxf.hasattr("style") is False result = EntityQuery([text], "*[style=='Standard']") assert result.first is text
def test_safety_checks(circle): # invalid entities should be ignored silently upright(None) # ignore None values upright(DXFEntity()) # ignore invalid DXF entity types upright(Text()) # ignore unsupported DXF entity types circle.destroy() upright(circle) # ignore destroyed entities assert True is True
def test_virtual_text_entity(self): assert is_text_vertical_stacked(Text()) is False
def test_remove_supports_virtual_entities(): result = EntityQuery([Text(), Line(), Arc()]).remove("TEXT") assert len(result) == 2
def test_del_item_ignores_unsupported_attributes(self): query = EntityQuery([Line(), Text()]) query["layer"] = "MyLayer" del query["layer"] assert query[0].dxf.layer == "0", "expected the default value" assert query[1].dxf.layer == "0", "expected the default value"
def test_set_item_does_not_ignore_invalid_attribute_values(self): query = EntityQuery([Line(), Text()]) with pytest.raises(TypeError): query["start"] = "InvalidVertex" with pytest.raises(ValueError): query["color"] = "red"
def test_set_item_ignores_unsupported_attributes(self): query = EntityQuery([Line(), Text()]) query["text"] = "MyText" assert query.query("TEXT").first.dxf.text == "MyText"
def test_set_item_set_supported_dxf_attributes(self): query = EntityQuery([Line(), Circle(), Text()]) query["layer"] = "MyLayer" assert all(e.dxf.layer == "MyLayer" for e in query) is True
def test_purge_does_remove_destroyed_entities(): query = EntityQuery([Text(), Text(), Text()]) query[0].destroy() query.purge() assert len(query) == 2
def test_iter_does_not_remove_destroyed_entities(): query = EntityQuery([Text(), Text(), Text()]) query[0].destroy() assert len(query) == 3 assert len(list(query)) == 3