def test_modify_existing_XDATA(self, list1): xlist = XDataUserList(XData([list1])) xlist[0] = 3.1415 xlist[1] = 256 xlist.commit() tags = xlist.xdata.get("EZDXF") assert tags == [ dxftag(1001, "EZDXF"), dxftag(1000, "DefaultList"), dxftag(1002, "{"), dxftag(1040, 3.1415), dxftag(1071, 256), dxftag(1002, "}"), ]
def test_modify_existing_user_list(self, user_list): xlist = XDataUserList(XData([user_list]), name="MyUserList", appid="MyAppID") xlist[0] = 3.1415 xlist[1] = 256 xlist.commit() tags = xlist.xdata.get("MyAppID") assert tags == [ dxftag(1001, "MyAppID"), dxftag(1000, "MyUserList"), dxftag(1002, "{"), dxftag(1040, 3.1415), dxftag(1071, 256), dxftag(1002, "}"), ]
def test_load_user_list(self, user_list): xlist = XDataUserList(XData([user_list]), name="MyUserList", appid="MyAppID") assert len(xlist) == 2 assert xlist[0] == "VALUE" assert xlist[1] == "CONTENT"
def test_commit_replaces_existing_XDATA(self, list1): xlist = XDataUserList(XData([list1])) xlist.clear() xlist.extend(["String", Vec3(1, 2, 3), 3.1415, 256]) xlist.commit() tags = xlist.xdata.get("EZDXF") assert tags == [ dxftag(1001, "EZDXF"), dxftag(1000, "DefaultList"), dxftag(1002, "{"), dxftag(1000, "String"), dxftag(1010, (1, 2, 3)), dxftag(1040, 3.1415), dxftag(1071, 256), dxftag(1002, "}"), ]
def test_context_manager_interface(self): xdata = XData() with XDataUserList(xdata) as xlist: xlist.extend(["String", Vec3(1, 2, 3), 3.1415, 256]) tags = xdata.get("EZDXF") assert tags == [ dxftag(1001, "EZDXF"), dxftag(1000, "DefaultList"), dxftag(1002, "{"), dxftag(1000, "String"), dxftag(1010, (1, 2, 3)), dxftag(1040, 3.1415), dxftag(1071, 256), dxftag(1002, "}"), ]
def test_commit_creates_valid_XDATA(self): xlist = XDataUserList() xlist.extend(["String", Vec3(1, 2, 3), 3.1415, 256]) xlist.commit() tags = xlist.xdata.get("EZDXF") assert tags == [ dxftag(1001, "EZDXF"), dxftag(1000, "DefaultList"), dxftag(1002, "{"), dxftag(1000, "String"), dxftag(1010, (1, 2, 3)), dxftag(1040, 3.1415), dxftag(1071, 256), dxftag(1002, "}"), ]
from ezdxf.entities.xdata import XDataUserDict, XDataUserList DIR = Path("~/Desktop/Outbox").expanduser() doc = ezdxf.new() msp = doc.modelspace() line = msp.add_line((0, 0), (1, 0)) with XDataUserDict.entity(line) as user_dict: user_dict["CreatedBy"] = "mozman" user_dict["Float"] = 3.1415 user_dict["Int"] = 4711 user_dict["Point"] = Vec3(1, 2, 3) with XDataUserDict.entity(line) as user_dict: print(user_dict) # acts like any other dict() storage = dict(user_dict) print(f"Copy of XDataUserDict: {storage}") with XDataUserList.entity(line, name="AppendedPoints") as user_list: user_list.append(Vec3(1, 0, 0)) user_list.append(Vec3(0, 1, 0)) user_list.append(Vec3(0, 0, 1)) with XDataUserList.entity(line, name="AppendedPoints") as user_list: print(user_list) storage = list(user_list) print(f"Copy of XDataUserList: {storage}")
def test_too_long_string_raise_exception(self): # The XDATA limit for group code 1000 is 255 characters xlist = XDataUserList() xlist.append("0123456789" * 26) with pytest.raises(DXFValueError): xlist.commit()
def test_invalid_line_break_characters_raise_exception(self, char): xlist = XDataUserList() xlist.append(char) with pytest.raises(DXFValueError): xlist.commit()
def test_list_like_delitem_interface(self, list1): xlist = XDataUserList(XData([list1])) del xlist[0] assert len(xlist) == 1 assert xlist[0] == "CONTENT"
def test_list_like_insert_interface(self, list1): xlist = XDataUserList(XData([list1])) xlist.insert(0, 17) assert xlist[0] == 17 assert len(xlist) == 3
def test_list_like_setitem_interface(self, list1): xlist = XDataUserList(XData([list1])) xlist[0] = 15 assert xlist[0] == 15
def test_list_like_getitem_interface(self, list1): xlist = XDataUserList(XData([list1])) assert len(xlist) == 2 assert xlist[-1] == "CONTENT" assert xlist[:] == ["VALUE", "CONTENT"]
def test_load_existing_list(self, list1): xlist = XDataUserList(XData([list1])) assert len(xlist) == 2 assert xlist[0] == "VALUE" assert xlist[1] == "CONTENT"
def test_load_not_existing_list(self): xlist = XDataUserList(XData()) assert len(xlist) == 0
# Int # 1071 # 4711 # 1000 # Point # 1010 # 1.0 # 1020 # 2.0 # 1030 # 3.0 # 1002 # } # default list name = "DefaultList" with XDataUserList.entity(gear, name="AppendedPoints") as user_list: # has a list-like interface user_list.append(Vec3(1, 0, 0)) user_list.append(Vec3(0, 1, 0)) user_list.append(Vec3(0, 0, 1)) # The XDATA structure looks like this: # 0 # LWPOLYLINE # ... # 1001 # EZDXF # 1000 # DefaultDict # ... # 1000