def test_set_values(entity, processor): attribs = DXFNamespace(processor, entity) attribs.handle = 'CDEF' assert attribs.handle == 'CDEF' attribs.set('owner', 'DADA') assert attribs.owner == 'DADA' # set new attribute attribs.color = 7 assert attribs.color == 7 attribs.set('linetype', 'DOT') assert attribs.linetype == 'DOT' # attribute has to a valid DXF attribute with pytest.raises(DXFAttributeError): attribs.hallo = 0 with pytest.raises(DXFAttributeError): attribs.set('hallo', 0)
def test_value_types(entity, processor): attribs = DXFNamespace(processor, entity) attribs.handle = None # None is always accepted, attribute is ignored at export assert attribs.handle is None attribs.handle = 'XYZ' assert attribs.handle == 'XYZ', 'handle is just a string' attribs.handle = 123 assert attribs.handle == '123', 'handle is just a string' with pytest.raises(ValueError): attribs.color = 'xxx' attribs.start = (1, 2, 3) # type: Vector assert attribs.start == (1, 2, 3) assert attribs.start.x == 1 assert attribs.start.y == 2 assert attribs.start.z == 3
def test_set_values(entity, processor): attribs = DXFNamespace(processor, entity) attribs.handle = "CDEF" assert attribs.handle == "CDEF" attribs.set("owner", "DADA") assert attribs.owner == "DADA" # set new attribute attribs.color = 7 assert attribs.color == 7 attribs.set("linetype", "DOT") assert attribs.linetype == "DOT" # attribute has to a valid DXF attribute with pytest.raises(DXFAttributeError): attribs.hallo = 0 with pytest.raises(DXFAttributeError): attribs.set("hallo", 0)
def test_cloning(entity, processor): attribs = DXFNamespace(processor, entity) attribs.color = 77 attribs2 = attribs.copy(entity) # clone everything assert attribs2._entity is attribs._entity assert attribs2.handle is attribs.handle assert attribs2.owner is attribs.owner assert attribs2.color == 77 # do not harm original entity assert attribs._entity is entity assert attribs.handle == 'FFFF' assert attribs.owner == 'ABBA' # change clone attribs2.color = 13 assert attribs.color == 77 assert attribs2.color == 13
def test_value_types(entity, processor): attribs = DXFNamespace(processor, entity) attribs.handle = ( None # None is always accepted, attribute is ignored at export ) assert attribs.handle is None attribs.handle = "XYZ" assert attribs.handle == "XYZ", "handle is just a string" attribs.handle = 123 assert attribs.handle == "123", "handle is just a string" with pytest.raises(ValueError): attribs.color = "xxx" attribs.start = (1, 2, 3) # type: Vec3 assert attribs.start == (1, 2, 3) assert attribs.start.x == 1 assert attribs.start.y == 2 assert attribs.start.z == 3
def test_deepcopy_usage(entity, processor): attribs = DXFNamespace(processor, entity) attribs.color = 77 attribs2 = deepcopy(attribs) # clone everything assert attribs2._entity is attribs._entity assert attribs2.handle is attribs.handle assert attribs2.owner is attribs.owner assert attribs2.color == 77 # do not harm original entity assert attribs._entity is entity assert attribs.handle == "FFFF" assert attribs.owner == "ABBA" # change clone attribs2.color = 13 assert attribs.color == 77 assert attribs2.color == 13
def dxf(self, processor, entity): ns = DXFNamespace(processor, entity) ns.color = 7 ns.handle = "ABBA" ns.owner = "FEFE" return ns