forked from mozman/ezdxf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress.py
124 lines (110 loc) · 3.55 KB
/
stress.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Copyright (c) 2020-2022, Manfred Moitzi
# License: MIT License
import pytest
import sys
import argparse
import time
import ezdxf
from ezdxf import recover
from itertools import chain
DIRS = [
"AutodeskSamples",
"AutodeskProducts",
"CADKitSamples",
"",
]
files = list(
chain(*[(ezdxf.options.test_files_path / d).glob("*.dxf") for d in DIRS])
)
@pytest.mark.parametrize("filename", files)
def test_readfile(filename):
try:
recover.readfile(filename)
except ezdxf.DXFStructureError:
pytest.fail(f"{filename}: DXFStructureError in recover mode.")
else:
assert True
if __name__ == "__main__":
import logging
from ezdxf import bbox, print_config
from ezdxf.math import Vec3
import warnings
# Suppress Matplotlib font replacement warnings
warnings.filterwarnings("ignore")
parser = argparse.ArgumentParser("stress")
parser.add_argument(
"-v",
"--verbose",
action="store_true",
help="give more output",
)
parser.add_argument(
"-e",
"--extends",
action="store_true",
help="perform extends calculation",
)
parser.add_argument(
"-c",
"--cadkit",
action="store_true",
help="use only CADKit samples",
)
parser.add_argument(
"-l",
"--log",
action="store_true",
help="turn logging on",
)
args = parser.parse_args(sys.argv[1:])
print_config()
print("-" * 79)
if args.cadkit: # only CADKit samples
files = (ezdxf.options.test_files_path / "CADKitSamples").glob("*.dxf")
if args.log:
logging.basicConfig(level=logging.WARNING)
for name in files:
print(f'Loading file: "{name}"')
try:
t_start = time.perf_counter()
doc = ezdxf.readfile(name)
t_read = time.perf_counter()
auditor = doc.audit()
t_audit = time.perf_counter()
except ezdxf.DXFStructureError:
if args.verbose:
print("Regular loading function failed, using recover mode.")
t_start = time.perf_counter()
doc, auditor = recover.readfile(name)
t_read = time.perf_counter()
t_audit = t_read
if auditor.has_errors and args.verbose:
print(f"Found {len(auditor.errors)} unrecoverable error(s).")
if auditor.has_fixes and args.verbose:
print(f"Fixed {len(auditor.fixes)} error(s).")
ex_run = 0
if args.extends:
ex_start = time.perf_counter()
extends = bbox.extents(doc.modelspace())
ex_run = time.perf_counter() - t_start
if args.verbose:
extmin = doc.header.get("$EXTMIN")
extmax = doc.header.get("$EXTMAX")
if extmin is not None:
e1 = Vec3(extmin).round(3)
e2 = Vec3(extmax).round(3)
print(f"Header var $EXTMIN/$EXTMAX: {e1}; {e2}")
if extends.has_data:
e1 = extends.extmin.round(3)
e2 = extends.extmax.round(3)
print(f"Calculated $EXTMIN/$EXTMAX: {e1}; {e2}")
if args.verbose:
print("Timing: ", end="")
t_run = t_read - t_start
print(f" loading: {t_run:.3f}s", end="")
if t_read != t_audit:
print(f" audit: {t_audit - t_read:.3f}s", end="")
if ex_run:
print(f" extends: {ex_run:.3f}s", end="")
print()
print("-" * 79)