You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.3 KiB
111 lines
3.3 KiB
#!/usr/bin/env python |
|
# -*- coding: utf-8 -*- |
|
|
|
"""Tests for `s2rename` package.""" |
|
|
|
import pytest |
|
|
|
from pathlib import Path |
|
|
|
|
|
sensovation_source_list = [ |
|
Path("some prefix thing_A1_1.tif"), |
|
Path("some prefix thing_A02_2.tif"), |
|
Path("A03_3.tif"), |
|
Path("some prefix thing_A10_4"), |
|
Path("some prefix thing_A11_5.csv"), |
|
Path("some prefix thing_A12_6.xml"), |
|
Path("some prefix thing_B01_1.tif"), |
|
Path("some prefix thing_C01_1.tif"), |
|
Path("some prefix thing_D01_1.tif"), |
|
Path("some prefix thing_E01_1.tif"), |
|
Path("some prefix thing_F01_1.tif"), |
|
Path("some prefix thing_G01_1.tif"), |
|
Path("some prefix thing_H01_1.tif"), |
|
Path("some prefix thing_I01_1.tif"), |
|
Path("some prefix thing_FF01_1.tif"), |
|
Path("some prefix thing_F21_1.tif"), |
|
Path("some prefix thing_F00_1.tif"), |
|
Path("some prefix thing_F0_1.tif"), |
|
Path("some prefix thing_F13_1.tif"), |
|
Path("some prefix thing_F08.tif"), |
|
Path(".some prefix thing_F09_1.tif"), |
|
] |
|
|
|
scienion_source_list = [ |
|
Path("A1_1_some suffix thing.tif"), |
|
Path("A02_2_some suffix thing.tif"), |
|
Path("A03_3.tif"), |
|
Path("A10_3_some suffix thing"), |
|
Path("A11_4_some suffix thing.csv"), |
|
Path("A12_5_some suffix thing.xml"), |
|
Path("B01_1_some suffix thing.tif"), |
|
Path("C01_1_some suffix thing.tif"), |
|
Path("D01_1_some suffix thing.tif"), |
|
Path("E01_1_some suffix thing.tif"), |
|
Path("F01_1_some suffix thing.tif"), |
|
Path("G01_1_some suffix thing.tif"), |
|
Path("H01_1_some suffix thing.tif"), |
|
Path("I01_1_some suffix thing.tif"), |
|
Path("FF01_1_some suffix thing.tif"), |
|
Path("F21_1_some suffix thing.tif"), |
|
Path("F00_1_some suffix thing.tif"), |
|
Path("F0_1_some suffix thing.tif"), |
|
Path("F13_1_some suffix thing.tif"), |
|
Path("F08_some suffix thing.tif"), |
|
Path(".F09_1_some suffix thing.tif"), |
|
] |
|
|
|
|
|
@pytest.mark.parametrize("sources", [sensovation_source_list, scienion_source_list]) |
|
def test_parse_source_list_sensovation(sources): |
|
from s2rename import s2rename |
|
|
|
if sources == sensovation_source_list: |
|
regex = s2rename.RE_SENSOVATION |
|
else: |
|
regex = s2rename.RE_SCIENION |
|
|
|
result = list(s2rename.parse_source_list(sensovation_source_list, regex)) |
|
assert len(result) == 14 |
|
assert {r.row for r in result} == set("ABCDEFGH") |
|
assert {r.col for r in result} == set([1, 2, 3, 9, 10, 11, 12]) |
|
|
|
|
|
def test_get_source_list(): |
|
from s2rename import s2rename |
|
|
|
result = list(s2rename.get_source_list(".")) |
|
assert {p.name for p in result} == { |
|
"LICENSE", |
|
"Pipfile", |
|
"requirements_dev.txt", |
|
"setup.cfg", |
|
"Makefile", |
|
"README.md", |
|
"setup.py", |
|
} |
|
|
|
|
|
@pytest.mark.parametrize("path", ["/i/hope/this/doesnt/exist", "setup.py"]) |
|
def test_get_source_list_raises_error(path): |
|
from s2rename import s2rename |
|
|
|
with pytest.raises(s2rename.S2IOError): |
|
result = s2rename.get_source_list(path) |
|
|
|
|
|
def test_get_source_list_with_type(): |
|
from s2rename import s2rename |
|
|
|
result = s2rename.get_source_list(".", ".txt") |
|
assert {p.name for p in result} == {"requirements_dev.txt"} |
|
|
|
|
|
def test_filter_source_list_type(): |
|
from s2rename import s2rename |
|
|
|
result = list(s2rename.filter_source_list(sensovation_source_list, ".csv")) |
|
assert len(result) == 1 |
|
assert result[0].name == "some prefix thing_A11_5.csv" |
|
|
|
|