Esempio n. 1
0
def test_poyline_with_xdata():
    xdata = XData(
        ExtendedTags(
            filter_invalid_xdata_group_codes(
                Tags.from_text(POLYLINE_WITH_INVALID_XDATA))).xdata)
    assert len(xdata) == 2
    assert len(xdata.get("AVE_ENTITY_MATERIAL")) == 27
Esempio n. 2
0
 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"
Esempio n. 3
0
    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, "}"),
        ]
Esempio n. 4
0
 def test_load_user_dict(self, user_dict):
     xdict = XDataUserDict(XData([user_dict]),
                           name="MyUserDict",
                           appid="MyAppID")
     assert len(xdict) == 2
     assert xdict["MyKey"] == "MyString"
     assert xdict["Int"] == 65535
Esempio n. 5
0
def test_safe_init():
    tags = ExtendedTags.from_text("""0
DXFENTITY
1001
MOZMAN
1000
DataStr1
1000
DataStr2
1007
XXX
1040
3.14
1001
ACAD
1000
AutoDesk
1000
Revit""")

    xdata = XData.safe_init(tags.xdata)
    data = xdata.get("MOZMAN")
    assert (any(tag.code == 1007 for tag in data) is
            False), "invalid group code 1007 should be removed"
    assert "ACAD" in xdata
Esempio n. 6
0
    def test_context_manager_interface(self):
        xdata = XData()
        with XDataUserDict(xdata) as xdict:
            xdict["Key1"] = 256
            xdict["Key2"] = "Value2"

        tags = xdata.get("EZDXF")
        assert tags == [
            dxftag(1001, "EZDXF"),
            dxftag(1000, "DefaultDict"),
            dxftag(1002, "{"),
            dxftag(1000, "Key1"),
            dxftag(1071, 256),
            dxftag(1000, "Key2"),
            dxftag(1000, "Value2"),
            dxftag(1002, "}"),
        ]
Esempio n. 7
0
 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, "}"),
     ]
Esempio n. 8
0
 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, "}"),
     ]
Esempio n. 9
0
 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, "}"),
     ]
Esempio n. 10
0
def xdata():
    xtags = ExtendedTags.from_text("""0
DXFENTITY
1001
MOZMAN
1000
DataStr1
1000
DataStr2
1040
3.14
1001
ACAD
1000
AutoDesk
1000
Revit""")
    return XData(xtags.xdata)
Esempio n. 11
0
 def test_dict_like_del_interface(self, dict1):
     xdict = XDataUserDict(XData([dict1]))
     del xdict["Key0"]
     assert len(xdict) == 1
     xdict.clear()
     assert len(xdict) == 0
Esempio n. 12
0
 def test_dict_like_interface(self, dict1):
     xdict = XDataUserDict(XData([dict1]))
     assert len(xdict) == 2
     assert "Key0" in xdict
     assert list(xdict.keys()) == ["Key0", "Float"]
     assert list(xdict.values()) == ["StringValue", 3.1415]
Esempio n. 13
0
 def test_load_existing_dict(self, dict1):
     xdict = XDataUserDict(XData([dict1]))
     assert len(xdict) == 2
     assert xdict["Key0"] == "StringValue"
     assert xdict["Float"] == 3.1415
Esempio n. 14
0
 def test_load_not_existing_dict(self):
     xdict = XDataUserDict(XData())
     assert len(xdict) == 0
Esempio n. 15
0
 def test_load_not_existing_list(self):
     xlist = XDataUserList(XData())
     assert len(xlist) == 0
Esempio n. 16
0
def test_empty_xdata():
    xdata = XData()
    assert len(xdata) == 0
    tagwriter = TagWriter()
    xdata.export_dxf(tagwriter)
    assert len(tagwriter.tags) == 0
Esempio n. 17
0
 def test_load_existing_list(self, list1):
     xlist = XDataUserList(XData([list1]))
     assert len(xlist) == 2
     assert xlist[0] == "VALUE"
     assert xlist[1] == "CONTENT"
Esempio n. 18
0
 def test_list_like_getitem_interface(self, list1):
     xlist = XDataUserList(XData([list1]))
     assert len(xlist) == 2
     assert xlist[-1] == "CONTENT"
     assert xlist[:] == ["VALUE", "CONTENT"]
Esempio n. 19
0
 def test_list_like_delitem_interface(self, list1):
     xlist = XDataUserList(XData([list1]))
     del xlist[0]
     assert len(xlist) == 1
     assert xlist[0] == "CONTENT"
Esempio n. 20
0
 def test_list_like_insert_interface(self, list1):
     xlist = XDataUserList(XData([list1]))
     xlist.insert(0, 17)
     assert xlist[0] == 17
     assert len(xlist) == 3
Esempio n. 21
0
 def test_list_like_setitem_interface(self, list1):
     xlist = XDataUserList(XData([list1]))
     xlist[0] = 15
     assert xlist[0] == 15
Esempio n. 22
0
def test_prevent_adding_invalid_data(group_code):
    xdata = XData()
    with pytest.raises(DXFValueError):
        xdata.add("INVALID", [(group_code, "String")])
    assert "INVALID" not in xdata
Esempio n. 23
0
def get_xdata(txt: str):
    tags = ExtendedTags.from_text(txt)
    return XData(tags.xdata)