File: test_layer.py

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

import pytest

import fiona
from .test_collection import TestReading


def test_index_selection(path_coutwildrnp_shp):
    with fiona.open(path_coutwildrnp_shp, 'r', layer=0) as c:
        assert len(c) == 67


class TestFileReading(TestReading):
    @pytest.fixture(autouse=True)
    def shapefile(self, path_coutwildrnp_shp):
        self.c = fiona.open(path_coutwildrnp_shp, 'r', layer='coutwildrnp')
        yield
        self.c.close()

    def test_open_repr(self, path_coutwildrnp_shp):
        assert repr(self.c) == (
            f"<open Collection '{path_coutwildrnp_shp}:coutwildrnp', "
            f"mode 'r' at {hex(id(self.c))}>"
        )

    def test_closed_repr(self, path_coutwildrnp_shp):
        self.c.close()
        assert repr(self.c) == (
            f"<closed Collection '{path_coutwildrnp_shp}:coutwildrnp', "
            f"mode 'r' at {hex(id(self.c))}>"
        )

    def test_name(self):
        assert self.c.name == 'coutwildrnp'


class TestDirReading(TestReading):
    @pytest.fixture(autouse=True)
    def shapefile(self, data_dir):
        self.c = fiona.open(data_dir, "r", layer="coutwildrnp")
        yield
        self.c.close()

    def test_open_repr(self, data_dir):
        assert repr(self.c) == (
            f"<open Collection '{data_dir}:coutwildrnp', "
            f"mode 'r' at {hex(id(self.c))}>"
        )

    def test_closed_repr(self, data_dir):
        self.c.close()
        assert repr(self.c) == (
            f"<closed Collection '{data_dir}:coutwildrnp', "
            f"mode 'r' at {hex(id(self.c))}>"
        )

    def test_name(self):
        assert self.c.name == 'coutwildrnp'

    def test_path(self, data_dir):
        assert self.c.path == data_dir


def test_invalid_layer(path_coutwildrnp_shp):
    with pytest.raises(ValueError):
        fiona.open(path_coutwildrnp_shp, layer="foo")


def test_write_invalid_numeric_layer(path_coutwildrnp_shp, tmpdir):
    with pytest.raises(ValueError):
        fiona.open(str(tmpdir.join("test-no-iter.shp")), mode='w', layer=0)