Add tests.
This commit is contained in:
parent
e80f511155
commit
a7d4bc4ae9
10 changed files with 915 additions and 418 deletions
117
tests/test_filter.py
Normal file
117
tests/test_filter.py
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
"""Tests for TODO list filtering functions."""
|
||||
|
||||
import pytest
|
||||
|
||||
from debian_todo import filter_todo_list, summarize_sources
|
||||
|
||||
|
||||
class TestFilterTodoList:
|
||||
"""Tests for filter_todo_list function."""
|
||||
|
||||
def test_filters_non_upstream_items(self):
|
||||
todo_list = [
|
||||
{":shortname": "newupstream_foo", ":details": "1.0.0", ":source": "foo"},
|
||||
{":shortname": "rc_bug", ":details": "bug info", ":source": "bar"},
|
||||
{":shortname": "other_type", ":details": "other", ":source": "baz"},
|
||||
]
|
||||
result = filter_todo_list(todo_list)
|
||||
assert len(result) == 1
|
||||
assert result[0][":source"] == "foo"
|
||||
|
||||
def test_filters_prerelease_by_default(self):
|
||||
todo_list = [
|
||||
{":shortname": "newupstream_foo", ":details": "1.0.0", ":source": "foo"},
|
||||
{":shortname": "newupstream_bar", ":details": "2.0.0rc1", ":source": "bar"},
|
||||
]
|
||||
result = filter_todo_list(todo_list)
|
||||
assert len(result) == 1
|
||||
assert result[0][":source"] == "foo"
|
||||
|
||||
def test_includes_prerelease_when_requested(self):
|
||||
todo_list = [
|
||||
{":shortname": "newupstream_foo", ":details": "1.0.0", ":source": "foo"},
|
||||
{":shortname": "newupstream_bar", ":details": "2.0.0rc1", ":source": "bar"},
|
||||
]
|
||||
result = filter_todo_list(todo_list, include_prerelease=True)
|
||||
assert len(result) == 2
|
||||
|
||||
def test_filters_matching_versions(self):
|
||||
# When normalized versions match, the item should be filtered out
|
||||
todo_list = [
|
||||
{
|
||||
":shortname": "newupstream_foo",
|
||||
":details": "1.0.0 (currently in unstable: 1.0.0-1)",
|
||||
":source": "foo",
|
||||
},
|
||||
]
|
||||
result = filter_todo_list(todo_list)
|
||||
assert len(result) == 0
|
||||
|
||||
def test_keeps_different_versions(self):
|
||||
todo_list = [
|
||||
{
|
||||
":shortname": "newupstream_foo",
|
||||
":details": "1.1.0 (currently in unstable: 1.0.0-1)",
|
||||
":source": "foo",
|
||||
},
|
||||
]
|
||||
result = filter_todo_list(todo_list)
|
||||
assert len(result) == 1
|
||||
|
||||
def test_handles_epoch_in_current(self):
|
||||
# Epoch should be stripped for comparison
|
||||
todo_list = [
|
||||
{
|
||||
":shortname": "newupstream_foo",
|
||||
":details": "1.0.0 (currently in unstable: 1:1.0.0-1)",
|
||||
":source": "foo",
|
||||
},
|
||||
]
|
||||
result = filter_todo_list(todo_list)
|
||||
assert len(result) == 0
|
||||
|
||||
def test_skips_invalid_items(self):
|
||||
todo_list = [
|
||||
{":shortname": "newupstream_foo", ":source": "foo"}, # missing :details
|
||||
{":details": "1.0.0", ":source": "bar"}, # missing :shortname
|
||||
{":shortname": 123, ":details": "1.0.0", ":source": "baz"}, # wrong type
|
||||
]
|
||||
result = filter_todo_list(todo_list)
|
||||
assert len(result) == 0
|
||||
|
||||
def test_empty_list(self):
|
||||
assert filter_todo_list([]) == []
|
||||
|
||||
|
||||
class TestSummarizeSources:
|
||||
"""Tests for summarize_sources function."""
|
||||
|
||||
def test_extracts_sources(self):
|
||||
todo_list = [
|
||||
{":source": "foo", ":shortname": "newupstream_foo"},
|
||||
{":source": "bar", ":shortname": "newupstream_bar"},
|
||||
{":source": "baz", ":shortname": "rc_bug"},
|
||||
]
|
||||
result = summarize_sources(todo_list)
|
||||
assert result == {"foo", "bar", "baz"}
|
||||
|
||||
def test_deduplicates_sources(self):
|
||||
todo_list = [
|
||||
{":source": "foo", ":shortname": "type1"},
|
||||
{":source": "foo", ":shortname": "type2"},
|
||||
]
|
||||
result = summarize_sources(todo_list)
|
||||
assert result == {"foo"}
|
||||
|
||||
def test_skips_non_string_sources(self):
|
||||
todo_list = [
|
||||
{":source": "foo"},
|
||||
{":source": 123},
|
||||
{":source": None},
|
||||
{},
|
||||
]
|
||||
result = summarize_sources(todo_list)
|
||||
assert result == {"foo"}
|
||||
|
||||
def test_empty_list(self):
|
||||
assert summarize_sources([]) == set()
|
||||
Loading…
Add table
Add a link
Reference in a new issue