File: test_229a_hatch_dxf_interface.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (141 lines) | stat: -rw-r--r-- 2,554 bytes parent folder | download
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright (c) 2019-2021 Manfred Moitzi
# License: MIT License
import pytest

from ezdxf.entities.hatch import Hatch
from ezdxf.lldxf.tagwriter import TagCollector, basic_tags_from_text
from ezdxf.lldxf import const
from ezdxf.math import Vec3


HATCH = """0
HATCH
5
0
330
0
100
AcDbEntity
8
0
62
1
100
AcDbHatch
10
0.0
20
0.0
30
0.0
210
0.0
220
0.0
230
1.0
2
SOLID
70
1
71
0
91
0
75
1
76
1
98
1
10
0.0
20
0.0
"""


@pytest.fixture
def entity() -> Hatch:
    return Hatch.from_text(HATCH)


def test_if_registered():
    from ezdxf.entities.factory import ENTITY_CLASSES

    assert "HATCH" in ENTITY_CLASSES


def test_default_init():
    entity = Hatch()
    assert entity.dxftype() == "HATCH"
    assert entity.dxf.handle is None
    assert entity.dxf.owner is None


def test_default_new():
    entity = Hatch.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "color": 7,
        },
    )
    assert entity.dxf.layer == "0"
    assert entity.dxf.color == 7


def test_load_from_text(entity):
    assert entity.dxf.layer == "0"
    assert entity.dxf.color == 1, "default color is 1"


def test_seeds(entity: Hatch):
    # seeds is a list of (x, y) tuples
    assert entity.seeds == [(0, 0)]


def test_write_dxf():
    entity = Hatch.from_text(HATCH)
    result = TagCollector.dxftags(entity)
    expected = basic_tags_from_text(HATCH)
    assert result == expected


def test_write_correct_polyline_path_tag_order(entity):
    entity = Hatch.from_text(HATCH)
    entity.paths.add_polyline_path(
        [(0, 0), (1, 0), (1, 1)],
        is_closed=True,
    )
    result = TagCollector.dxftags(entity)
    tags = list(result.pop_tags([92, 72, 73]))
    # 92 = path type 3: external polyline path
    # 72 = has_bulge
    # 73 = is_closed
    # The group codes 72 and 73 are swapped in comparison to MPOLYGON
    assert tags == [(92, 3), (72, 0), (73, 1)]


def test_hatch_boundary_state():
    state = const.BoundaryPathState.from_flags(
        const.BOUNDARY_PATH_EXTERNAL
        + const.BOUNDARY_PATH_DERIVED
        + const.BOUNDARY_PATH_TEXTBOX
        + const.BOUNDARY_PATH_OUTERMOST
    )
    assert state.external is True
    assert state.derived is True
    assert state.textbox is True
    assert state.outermost is True
    assert state.default is False


def test_hatch_boundary_default_state():
    state = const.BoundaryPathState()
    assert state.external is False
    assert state.derived is False
    assert state.textbox is False
    assert state.outermost is False
    assert state.default is True