File: test_open_sharing.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 (41 lines) | stat: -rw-r--r-- 1,439 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
"""Tests of dataset connection sharing"""

import rasterio


def test_sharing_on(capfd, path_rgb_byte_tif):
    """Datasets are shared"""
    with rasterio.Env() as env:

        # Opens a new file.
        with rasterio.open(path_rgb_byte_tif) as srcx:
            env._dump_open_datasets()
            captured = capfd.readouterr()
            assert "1 N GTiff" in captured.err
            assert "1 S GTiff" not in captured.err

            # Does not open a new file.
            with rasterio.open(path_rgb_byte_tif, sharing=True) as srcy:
                env._dump_open_datasets()
                captured = capfd.readouterr()
                assert "1 N GTiff" in captured.err
                assert "1 S GTiff" in captured.err


def test_sharing_off(capfd, path_rgb_byte_tif):
    """Datasets are not shared"""
    with rasterio.Env() as env:

        # Opens a new file.
        with rasterio.open(path_rgb_byte_tif, sharing=False) as srcx:
            env._dump_open_datasets()
            captured = capfd.readouterr()
            assert "1 N GTiff" in captured.err
            assert "1 S GTiff" not in captured.err

            # Opens a new file.
            with rasterio.open(path_rgb_byte_tif, sharing=False) as srcy:
                env._dump_open_datasets()
                captured = capfd.readouterr()
                assert captured.err.count("1 N GTiff") == 2
                assert "1 S GTiff" not in captured.err