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
142
143
144
145
146
147
148
"""
Phase 5a tests — Character encoding detection and handling.
Covers reading LAS files with UTF-8, UTF-8 BOM, and Latin-1 encodings,
auto-detection of the encoding attribute, explicit encoding overrides,
the autodetect_encoding flag, and pathlib.Path input.
All tests are marked xfail because the `las_rs` Rust extension has not yet
been implemented.
"""
=
return
# ---------------------------------------------------------------------------
# File path constants
# ---------------------------------------------------------------------------
=
=
=
# ---------------------------------------------------------------------------
# UTF-8 plain
# ---------------------------------------------------------------------------
"""A plain UTF-8 file containing non-ASCII characters (Ölbohrung GmbH in
COMP) is read without raising an exception and the non-ASCII text is
preserved in the well section."""
=
= .
assert in or in
# ---------------------------------------------------------------------------
# UTF-8 BOM
# ---------------------------------------------------------------------------
"""A UTF-8 file that begins with a BOM (byte-order mark) is parsed without
error; the well section contains the expected company name."""
=
= .
assert in
"""When a BOM is present the auto-detected encoding is reported as
'utf-8-sig' (Python's name for UTF-8 with BOM)."""
=
assert is not None
assert ==
# ---------------------------------------------------------------------------
# Latin-1 / ISO 8859-1
# ---------------------------------------------------------------------------
"""A Latin-1 encoded file containing accented characters in the COMP field
(Société Pétrolière) is read and the non-ASCII characters are present."""
=
= .
# The fixture encodes "Société Pétrolière"; at minimum the ASCII part
# should be there even if decoding is approximate.
assert is not None and > 0
# ---------------------------------------------------------------------------
# encoding attribute
# ---------------------------------------------------------------------------
"""After reading any LAS file the resulting LASFile has a non-None
`encoding` attribute that is a plain string."""
=
assert is not None
assert
# ---------------------------------------------------------------------------
# Explicit encoding override
# ---------------------------------------------------------------------------
"""Passing encoding='latin-1' explicitly causes the Latin-1 fixture to be
decoded correctly; the company field contains expected text."""
=
= .
# "Société Pétrolière" decoded from latin-1 should contain the accented chars
assert in and in
# ---------------------------------------------------------------------------
# autodetect_encoding=False
# ---------------------------------------------------------------------------
"""Passing autodetect_encoding=False disables charset sniffing; the file
is still readable using a default common encoding (UTF-8 or ASCII)."""
# The plain UTF-8 file is valid ASCII for the structural parts; it should
# parse without error even with auto-detection disabled.
=
assert
assert > 0
# ---------------------------------------------------------------------------
# pathlib.Path input
# ---------------------------------------------------------------------------
"""las_rs.read() accepts a pathlib.Path object in addition to plain
strings; the result is an equivalent LASFile."""
=
=
assert
= .
assert == 3
assert ==