File: test_missing_block_names.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 (40 lines) | stat: -rw-r--r-- 1,317 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
# Copyright (c) 2024, Manfred Moitzi
# License: MIT License
import pytest

from pathlib import Path
import ezdxf

DATA = Path(__file__).parent / "data"


def test_load_r12_blocks_with_no_name():
    """DXF R12 has no BLOCK_RECORD and therefore the block name cannot be recovered."""
    doc = ezdxf.readfile(DATA / "r12_blocks_with_no_names.dxf")
    assert len(doc.blocks) == 2


def test_load_r2000_blocks_with_recovered_names():
    """DXF R2000 requires a BLOCK_RECORD for each block definition and therefore the
    block name can be recovered from the BLOCK_RECORD.
    """
    doc = ezdxf.readfile(DATA / "r2000_blocks_with_no_names.dxf")
    assert len(doc.blocks) == 4
    for name in ("Test", "Test2"):
        block = doc.blocks.get(name)
        assert block.name == name
        assert block.block.dxf.name == name
        assert block.block_record.dxf.name == name


def test_load_r2000_blocks_with_no_name_and_no_block_record():
    """The block name cannot be recovered without an associated block record."""
    doc = ezdxf.readfile(DATA / "r2000_blocks_with_no_name_and_no_block_record.dxf")
    assert len(doc.blocks) == 2
    for name in ("Test", "Test2"):
        assert name not in doc.blocks
        assert name not in doc.block_records


if __name__ == "__main__":
    pytest.main([__file__])