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.
54 lines
1.5 KiB
54 lines
1.5 KiB
import pytest |
|
import main |
|
|
|
|
|
@pytest.fixture(autouse=True) |
|
def patch_log(monkeypatch): |
|
monkeypatch.setattr(main, "log", lambda msg: None) |
|
monkeypatch.setattr(main, "logvv", lambda msg: None) |
|
|
|
|
|
def test_read_csv_to_dict_basic(tmp_path): |
|
content = ( |
|
"img1\t12.34 56.78\tfoo\tbar\n" |
|
"img2\t90.12 34.56\tbaz\tqux\n" |
|
) |
|
file_path = tmp_path / "test.csv" |
|
file_path.write_text(content, encoding="utf-8") |
|
|
|
result = main.read_csv_to_dict(str(file_path)) |
|
expected = [ |
|
[1, 'img1', (12.34, 56.78), 'foo', 'bar', None], |
|
[2, 'img2', (90.12, 34.56), 'baz', 'qux', None], |
|
] |
|
assert result == expected |
|
|
|
|
|
def test_read_csv_to_dict_empty_file(tmp_path): |
|
file_path = tmp_path / "empty.csv" |
|
file_path.write_text("", encoding="utf-8") |
|
|
|
assert main.read_csv_to_dict(str(file_path)) == None |
|
|
|
|
|
def test_read_csv_to_dict_extra_spaces(tmp_path): |
|
content = ( |
|
"img3\t 3.23 4.56 \tfoo\tbar\n" |
|
) |
|
file_path = tmp_path / "extra_spaces.csv" |
|
file_path.write_text(content, encoding="utf-8") |
|
|
|
result = main.read_csv_to_dict(str(file_path)) |
|
expected = [[1, 'img3', (3.23, 4.56), 'foo', 'bar', None]] |
|
assert result == expected |
|
|
|
|
|
def test_read_csv_to_dict_incorrect_format(tmp_path): |
|
content = ( |
|
"img4\t44.34\tfoo\tbar\n" # missing lat in second column |
|
) |
|
file_path = tmp_path / "incorrect.csv" |
|
file_path.write_text(content, encoding="utf-8") |
|
|
|
assert main.read_csv_to_dict(str(file_path)) == None |
|
|
|
|