File: test_io.py

package info (click to toggle)
stactools 0.5.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,796 kB
  • sloc: python: 4,498; xml: 554; sh: 395; makefile: 34
file content (37 lines) | stat: -rw-r--r-- 1,108 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
import io
from pathlib import Path
from unittest.mock import create_autospec, patch

import pystac
import stactools.core.io
from stactools.core import use_fsspec


def test_fsspec_io(tmp_path: Path):
    use_fsspec()

    catalog_url = (
        "https://raw.githubusercontent.com/stac-utils/pystac/v0.5.2/tests/data-files/"
        "catalogs/test-case-1/catalog.json"
    )

    cat = pystac.read_file(catalog_url)
    col = cat.get_child("country-1")
    assert len(list(col.get_children())) == 2

    cat.normalize_and_save(str(tmp_path), pystac.CatalogType.SELF_CONTAINED)

    cat2 = pystac.read_file(str(tmp_path / "catalog.json"))
    col2 = cat2.get_child("country-1")
    assert len(list(col2.get_children())) == 2


@patch("stactools.core.io.fsspec.open")
def test_fsspec_kwargs(mock_open):
    open_file = create_autospec(io.TextIOBase)
    open_file.read.return_value = "string"
    use_fsspec()
    url = "url"
    mock_open.return_value.__enter__.return_value = open_file
    stactools.core.io.read_text(url, requester_pays=True)
    mock_open.assert_called_with(url, "r", requester_pays=True)