forked from mozman/ezdxf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_write_without_handles.py
52 lines (43 loc) · 1.71 KB
/
test_write_without_handles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright (c) 2020, Manfred Moitzi
# License: MIT License
import os
import pytest
import ezdxf
from ezdxf.lldxf.tagger import ascii_tags_loader
from ezdxf.lldxf.loader import load_dxf_structure
BASEDIR = os.path.dirname(__file__)
DATADIR = "data"
@pytest.fixture(params=["POLI-ALL210_12.DXF"])
def filename(request):
filename = os.path.join(BASEDIR, DATADIR, request.param)
if not os.path.exists(filename):
pytest.skip(f"File {filename} not found.")
return filename
def test_check_R12_has_handles(filename):
dwg = ezdxf.readfile(filename)
assert dwg.header["$HANDLING"] > 0
for entity in dwg.modelspace():
assert int(entity.dxf.handle, 16) > 0
def test_write_R12_without_handles(filename, tmpdir):
dwg = ezdxf.readfile(filename)
dwg.header["$HANDLING"] = 0
export_path = str(tmpdir.join("dxf_r12_without_handles.dxf"))
dwg.saveas(export_path)
# can't check with ezdxf.readfile(), because handles automatically enabled
with open(export_path) as f:
tagger = ascii_tags_loader(f)
sections = load_dxf_structure(tagger)
for entity in sections["ENTITIES"]:
with pytest.raises(ezdxf.DXFValueError): # has no handles
entity.get_handle()
for entity in sections["TABLES"]:
if entity[0] != (0, "DIMSTYLE"):
with pytest.raises(ezdxf.DXFValueError): # has no handles
entity.get_handle()
else: # special DIMSTYLE entity
assert (
len(entity.find_all(105)) == 0
), "remove handle group code 105"
assert (
len(entity.find_all(5)) == 1
), "do not remove group code 5"