-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1232 from mbway/pickle_support
add support for pickling DXF entities
- Loading branch information
Showing
2 changed files
with
45 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,36 @@ | ||
import io | ||
import pickle | ||
from collections.abc import Iterator | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
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(monkeypatch: pytest.MonkeyPatch) -> None: | ||
monkeypatch.setattr(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) |