File: test_412_rename_layer.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 (43 lines) | stat: -rw-r--r-- 1,015 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
# Copyright (c) 2019 Manfred Moitzi
# License: MIT License
import pytest
import ezdxf

LAYER = "test"


@pytest.fixture
def dxf():
    doc = ezdxf.new("R2000")
    doc.layers.new(LAYER)
    msp = doc.modelspace()
    msp.add_text("A", dxfattribs={"layer": LAYER})
    blk = doc.blocks.new("TEST")
    blk.add_text("A", dxfattribs={"layer": LAYER})
    return doc


def test_rename_layer(dxf):
    NEW_LAYER = "XYZ"
    layer = dxf.layers.get(LAYER)
    layer.rename(NEW_LAYER)

    assert dxf.layers.has_entry(NEW_LAYER)

    msp = dxf.modelspace()
    assert msp[0].dxf.layer == NEW_LAYER

    blk = dxf.blocks.get("TEST")
    assert blk[0].dxf.layer == NEW_LAYER


def test_rename_layer_errors(dxf):
    layer = dxf.layers.get(LAYER)
    pytest.raises(ValueError, layer.rename, "XXX*")
    pytest.raises(ValueError, layer.rename, LAYER)

    layer = dxf.layers.get("0")
    pytest.raises(ValueError, layer.rename, LAYER)

    layer = dxf.layers.get("DEFPOINTS")
    pytest.raises(ValueError, layer.rename, LAYER)