|
1 | 1 | import logging |
| 2 | +import os |
| 3 | +import pathlib |
2 | 4 | import re |
3 | 5 | from datetime import datetime |
4 | 6 |
|
5 | 7 | import pytest |
6 | 8 |
|
7 | | -from openeo.util import first_not_none, get_temporal_extent, TimingLogger, ensure_list |
| 9 | +from openeo.util import first_not_none, get_temporal_extent, TimingLogger, ensure_list, ensure_dir |
8 | 10 |
|
9 | 11 |
|
10 | 12 | @pytest.mark.parametrize(['input', 'expected'], [ |
@@ -43,6 +45,27 @@ def test_ensure_list(input, expected): |
43 | 45 | assert ensure_list(input) == expected |
44 | 46 |
|
45 | 47 |
|
| 48 | +def test_ensure_dir_str(tmp_path): |
| 49 | + work_dir = str(tmp_path / "work/data/foo") |
| 50 | + assert not os.path.exists(work_dir) |
| 51 | + p = ensure_dir(work_dir) |
| 52 | + assert os.path.exists(work_dir) |
| 53 | + assert isinstance(p, pathlib.Path) |
| 54 | + assert p.exists() |
| 55 | + assert str(p) == str(work_dir) |
| 56 | + |
| 57 | + |
| 58 | +def test_ensure_dir_pathlib(tmp_path): |
| 59 | + # Note: tmp_path might be pathlib2 |
| 60 | + work_dir = pathlib.Path(str(tmp_path / "work/data/foo")) |
| 61 | + assert not work_dir.exists() |
| 62 | + p = ensure_dir(work_dir) |
| 63 | + assert work_dir.exists() |
| 64 | + assert isinstance(p, pathlib.Path) |
| 65 | + assert p.exists() |
| 66 | + assert str(p) == str(work_dir) |
| 67 | + |
| 68 | + |
46 | 69 | def test_get_temporal_extent(): |
47 | 70 | assert get_temporal_extent("2019-03-15") == ("2019-03-15", None) |
48 | 71 | assert get_temporal_extent("2019-03-15", "2019-10-11") == ("2019-03-15", "2019-10-11") |
|
0 commit comments