File: test_open.py

package info (click to toggle)
rasterio 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,732 kB
  • sloc: python: 23,119; sh: 947; makefile: 275; xml: 29
file content (43 lines) | stat: -rw-r--r-- 1,075 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
import pytest
import rasterio
from pathlib import Path


def test_open_bad_path():
    with pytest.raises(TypeError):
        rasterio.open(3.14)


def test_open_bad_path_2(path_rgb_byte_tif):
    with rasterio.open(path_rgb_byte_tif) as dst:
        with pytest.raises(TypeError):
            rasterio.open(dst)


def test_open_bad_mode_1():
    with pytest.raises(TypeError):
        rasterio.open("tests/data/RGB.byte.tif", mode=3.14)


def test_open_bad_mode_2():
    with pytest.raises(ValueError):
        rasterio.open("tests/data/RGB.byte.tif", mode="foo")


def test_open_bad_driver():
    with pytest.raises(TypeError):
        rasterio.open("tests/data/RGB.byte.tif", mode="r", driver=3.14)


def test_open_pathlib_path():
    tif = Path.cwd() / 'tests' / 'data' / 'RGB.byte.tif'
    with rasterio.open(tif) as src:
        assert src.count == 3


def test_open_pathlike():
    class MyPath:
        def __fspath__(self):
            return str(Path.cwd() / 'tests' / 'data' / 'RGB.byte.tif')
    with rasterio.open(MyPath()) as src:
        assert src.count == 3