File: test_binary_field.py

package info (click to toggle)
fiona 1.10.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,632 kB
  • sloc: python: 12,616; makefile: 213; sh: 45
file content (43 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (3)
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
"""Binary BLOB field testing."""

import struct

import fiona
from fiona.model import Feature

from .conftest import requires_gpkg


@requires_gpkg
def test_binary_field(tmpdir):
    meta = {
        "driver": "GPKG",
        "schema": {
            "geometry": "Point",
            "properties": {"name": "str", "data": "bytes"},
        },
    }

    # create some binary data
    input_data = struct.pack("256B", *range(256))

    # write the binary data to a BLOB field
    filename = str(tmpdir.join("binary_test.gpkg"))
    with fiona.open(filename, "w", **meta) as dst:
        feature = Feature.from_dict(
            **{
                "geometry": {"type": "Point", "coordinates": ((0, 0))},
                "properties": {
                    "name": "test",
                    "data": input_data,
                },
            }
        )
        dst.write(feature)

    # read the data back and check consistency
    with fiona.open(filename, "r") as src:
        feature = next(iter(src))
        assert feature.properties["name"] == "test"
        output_data = feature.properties["data"]
        assert output_data == input_data