-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for pickling DXF entities
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import io | ||
import pickle | ||
from collections.abc import Iterator | ||
from pathlib import Path | ||
|
||
import ezdxf | ||
from ezdxf.document import Drawing | ||
|
||
EXAMPLES = Path(__file__).parent.parent.parent / "examples_dxf" | ||
|
||
|
||
def example_dxfs() -> Iterator[Path]: | ||
for item in EXAMPLES.iterdir(): | ||
if item.suffix.lower() == ".dxf": | ||
yield item | ||
|
||
|
||
def _to_dxf_str(doc: Drawing) -> str: | ||
stream = io.StringIO() | ||
doc.write(stream) | ||
return stream.getvalue() | ||
|
||
|
||
def test_document_pickle() -> None: | ||
ezdxf.options.write_fixed_meta_data_for_testing = True | ||
|
||
for item in example_dxfs(): | ||
print(f"testing pickling of {item}") | ||
|
||
doc = ezdxf.readfile(item) | ||
doc_serialized = pickle.dumps(doc) | ||
doc_loaded = pickle.loads(doc_serialized) | ||
|
||
assert _to_dxf_str(doc) == _to_dxf_str(doc_loaded) |