コード例 #1
0
def test_safety_checks(circle):
    # invalid entities should be ignored silently
    upright(None)  # ignore None values
    upright(DXFEntity())  # ignore invalid DXF entity types
    upright(Text())  # ignore unsupported DXF entity types
    circle.destroy()
    upright(circle)  # ignore destroyed entities
    assert True is True
コード例 #2
0
def test_match_default_values():
    """An attribute query should match the default value if the attribute is
    not present.
    """
    text = Text()
    assert text.dxf.hasattr("style") is False
    result = EntityQuery([text], "*[style=='Standard']")
    assert result.first is text
コード例 #3
0
ファイル: test_814_text2path.py プロジェクト: yanbin-ha/ezdxf
def make_text(text, location, alignment, height=1.0, rotation=0):
    text = Text.new(dxfattribs={
        'text': text,
        'height': height,
        'rotation': rotation,
    })
    text.set_pos(location, align=alignment)
    return text
コード例 #4
0
def make_text(text, location, alignment, height=1.0, rotation=0):
    text = Text.new(dxfattribs={
        "text": text,
        "height": height,
        "rotation": rotation,
    })
    text.set_placement(location, align=alignment)
    return text
コード例 #5
0
 def query(self):
     return EntityQuery([
         Line.new(dxfattribs={
             "layer": "Lay1",
             "color": 1
         }),
         Text.new(dxfattribs={
             "layer": "Lay2",
             "color": 2
         }),
     ])
コード例 #6
0
 def base(self):
     return EntityQuery([
         Line.new(dxfattribs={
             "layer": "Lay_line",
             "color": 1
         }),
         Circle.new(dxfattribs={
             "layer": "lAy_circle",
             "center": Vec3(0, 0)
         }),
         Text.new(dxfattribs={"layer": "laY_text"}),
     ])
コード例 #7
0
ファイル: test_514_text.py プロジェクト: yening2020/ezdxf
def test_plain_text():
    assert plain_text('%%d') == '°'
    # underline
    assert plain_text('%%u') == ''
    assert plain_text('%%utext%%u') == 'text'
    # single %
    assert plain_text('%u%d%') == '%u%d%'
    t = Text.new(dxfattribs={'text': '45%%d'})
    assert t.plain_text() == '45°'

    assert plain_text('abc^a') == 'abc!'
    assert plain_text('abc^Jdef') == 'abcdef'
    assert plain_text('abc^@def') == 'abc\0def'
コード例 #8
0
 def base(self):
     return EntityQuery([
         Line.new(dxfattribs={
             "layer": "line",
             "color": 1
         }),
         Circle.new(dxfattribs={
             "layer": "circle",
             "color": 2
         }),
         Text.new(dxfattribs={
             "layer": "text",
             "color": 3
         }),
     ])
コード例 #9
0
 def test_union(self, base: EntityQuery):
     other = EntityQuery([
         Line.new(dxfattribs={
             "layer": "line",
             "color": 1
         }),
         Circle.new(dxfattribs={
             "layer": "circle",
             "color": 2
         }),
         Text.new(dxfattribs={
             "layer": "text",
             "color": 3
         }),
     ])
     assert len(base | other) == 6
コード例 #10
0
ファイル: test_514_text.py プロジェクト: Rahulghuge94/ezdxf
def test_plain_text():
    assert plain_text("%%C") == "Ø"  # alt-0216
    assert plain_text("%%D") == "°"  # alt-0176
    assert plain_text("%%P") == "±"  # alt-0177
    # underline
    assert plain_text("%%u") == ""
    assert plain_text("%%utext%%u") == "text"
    # overline
    assert plain_text("%%o") == ""
    # strike through
    assert plain_text("%%k") == ""

    # single %
    assert plain_text("%u%d%") == "%u%d%"
    t = Text.new(dxfattribs={"text": "45%%d"})
    assert t.plain_text() == "45°"

    assert plain_text("abc^a") == "abc!"
    assert plain_text("abc^Jdef") == "abcdef"
    assert plain_text("abc^@def") == "abc\0def"
コード例 #11
0
def test_plain_text():
    assert plain_text('%%C') == 'Ø'  # alt-0216
    assert plain_text('%%D') == '°'  # alt-0176
    assert plain_text('%%P') == '±'  # alt-0177
    # underline
    assert plain_text('%%u') == ''
    assert plain_text('%%utext%%u') == 'text'
    # overline
    assert plain_text('%%o') == ''
    # strike through
    assert plain_text('%%k') == ''

    # single %
    assert plain_text('%u%d%') == '%u%d%'
    t = Text.new(dxfattribs={'text': '45%%d'})
    assert t.plain_text() == '45°'

    assert plain_text('abc^a') == 'abc!'
    assert plain_text('abc^Jdef') == 'abcdef'
    assert plain_text('abc^@def') == 'abc\0def'
コード例 #12
0
    def text(num):
        height = 1.0
        width = 1.0
        p1 = Vector(0, 0, 0)

        t = Text.new(
            dxfattribs={
                'text':
                content.format(num),  # should easily show reflexion errors
                'height': height,
                'width': width,
                'rotation': 0,
                'layer': 'text',
            },
            doc=doc)
        t.set_pos(p1, align='LEFT')
        tlen = height * len(t.dxf.text) * width
        p2 = p1.replace(x=tlen)
        p3 = p2.replace(y=height)
        p4 = p1.replace(y=height)
        v = [p1, p2, p3, p4, p3.lerp(p4), p2.lerp(p3)]
        return t, v
コード例 #13
0
    def text(num):
        height = 1.0
        width = 1.0
        p1 = Vec3(0, 0, 0)

        t = Text.new(
            dxfattribs={
                "text":
                content.format(num),  # should easily show reflexion errors
                "height": height,
                "width": width,
                "rotation": 0,
                "layer": "text",
            },
            doc=doc,
        )
        t.set_pos(p1, align="LEFT")
        tlen = height * len(t.dxf.text) * width
        p2 = p1.replace(x=tlen)
        p3 = p2.replace(y=height)
        p4 = p1.replace(y=height)
        v = [p1, p2, p3, p4, p3.lerp(p4), p2.lerp(p3)]
        return t, v
コード例 #14
0
 def entities(self):
     return EntityQuery([
         MText.new(
             dxfattribs={"text": "content"}),  # virtual text attribute
         Text.new(dxfattribs={"text": "content"})
     ])
コード例 #15
0
ファイル: test_514_text.py プロジェクト: yening2020/ezdxf
 def test_virtual_text_entity(self):
     assert is_text_vertical_stacked(Text()) is False
コード例 #16
0
def test_iter_does_not_remove_destroyed_entities():
    query = EntityQuery([Text(), Text(), Text()])
    query[0].destroy()
    assert len(query) == 3
    assert len(list(query)) == 3
コード例 #17
0
def test_purge_does_remove_destroyed_entities():
    query = EntityQuery([Text(), Text(), Text()])
    query[0].destroy()
    query.purge()
    assert len(query) == 2
コード例 #18
0
 def test_set_item_set_supported_dxf_attributes(self):
     query = EntityQuery([Line(), Circle(), Text()])
     query["layer"] = "MyLayer"
     assert all(e.dxf.layer == "MyLayer" for e in query) is True
コード例 #19
0
 def test_set_item_ignores_unsupported_attributes(self):
     query = EntityQuery([Line(), Text()])
     query["text"] = "MyText"
     assert query.query("TEXT").first.dxf.text == "MyText"
コード例 #20
0
 def test_set_item_does_not_ignore_invalid_attribute_values(self):
     query = EntityQuery([Line(), Text()])
     with pytest.raises(TypeError):
         query["start"] = "InvalidVertex"
     with pytest.raises(ValueError):
         query["color"] = "red"
コード例 #21
0
 def test_del_item_ignores_unsupported_attributes(self):
     query = EntityQuery([Line(), Text()])
     query["layer"] = "MyLayer"
     del query["layer"]
     assert query[0].dxf.layer == "0", "expected the default value"
     assert query[1].dxf.layer == "0", "expected the default value"
コード例 #22
0
 def test_greater_equal_raises_type_error_for_vector_attributes(self):
     query = EntityQuery([Text.new(dxfattribs={"insert": Vec3(0, 0)})])
     with pytest.raises(TypeError):
         _ = query["insert"] >= (1, 0)
コード例 #23
0
def test_remove_supports_virtual_entities():
    result = EntityQuery([Text(), Line(), Arc()]).remove("TEXT")
    assert len(result) == 2