Add test suite for all modules
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / type-check (push) Has been cancelled
CI / build (push) Has been cancelled
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / type-check (push) Has been cancelled
CI / build (push) Has been cancelled
This commit is contained in:
116
tests/test_pattern_merger.py
Normal file
116
tests/test_pattern_merger.py
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
"""Tests for pattern merger module."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from gitignore_cli.pattern_merger import PatternMerger, merge_templates, deduplicate_patterns
|
||||||
|
|
||||||
|
|
||||||
|
class TestPatternMerger:
|
||||||
|
"""Tests for PatternMerger class."""
|
||||||
|
|
||||||
|
def setup_method(self):
|
||||||
|
"""Set up test fixtures."""
|
||||||
|
self.merger = PatternMerger()
|
||||||
|
|
||||||
|
def test_merge_single_pattern_set(self):
|
||||||
|
"""Test merging a single pattern set."""
|
||||||
|
patterns = ["__pycache__/\n*.pyc"]
|
||||||
|
result = self.merger.merge_patterns(patterns)
|
||||||
|
|
||||||
|
assert "__pycache__/" in result
|
||||||
|
assert "*.pyc" in result
|
||||||
|
|
||||||
|
def test_merge_multiple_pattern_sets(self):
|
||||||
|
"""Test merging multiple pattern sets."""
|
||||||
|
patterns = [
|
||||||
|
"__pycache__/\n*.pyc",
|
||||||
|
"node_modules/\n*.log",
|
||||||
|
]
|
||||||
|
result = self.merger.merge_patterns(patterns)
|
||||||
|
|
||||||
|
assert "__pycache__/" in result
|
||||||
|
assert "*.pyc" in result
|
||||||
|
assert "node_modules/" in result
|
||||||
|
assert "*.log" in result
|
||||||
|
|
||||||
|
def test_deduplication(self):
|
||||||
|
"""Test that duplicate patterns are removed."""
|
||||||
|
patterns = [
|
||||||
|
"*.pyc",
|
||||||
|
"*.pyc",
|
||||||
|
"*.pyc",
|
||||||
|
]
|
||||||
|
result = self.merger.merge_patterns(patterns)
|
||||||
|
|
||||||
|
assert result.count("*.pyc") == 1
|
||||||
|
|
||||||
|
def test_empty_patterns(self):
|
||||||
|
"""Test merging empty pattern sets."""
|
||||||
|
patterns = []
|
||||||
|
result = self.merger.merge_patterns(patterns)
|
||||||
|
|
||||||
|
assert result == "\n"
|
||||||
|
|
||||||
|
def test_whitespace_lines_removed(self):
|
||||||
|
"""Test that empty/whitespace lines are handled."""
|
||||||
|
patterns = [
|
||||||
|
"*.pyc\n\n\n \n*.pyo",
|
||||||
|
]
|
||||||
|
result = self.merger.merge_patterns(patterns)
|
||||||
|
|
||||||
|
assert "*.pyc" in result
|
||||||
|
assert "*.pyo" in result
|
||||||
|
|
||||||
|
def test_normalize_pattern(self):
|
||||||
|
"""Test pattern normalization."""
|
||||||
|
assert self.merger._normalize_pattern("*.pyc") == "*.pyc"
|
||||||
|
assert self.merger._normalize_pattern(" *.pyc ") == "*.pyc"
|
||||||
|
assert self.merger._normalize_pattern("") == ""
|
||||||
|
assert self.merger._normalize_pattern("# comment") == ""
|
||||||
|
assert self.merger._normalize_pattern("!important") == "!important"
|
||||||
|
|
||||||
|
def test_deduplicate_patterns_function(self):
|
||||||
|
"""Test the deduplicate_patterns convenience function."""
|
||||||
|
patterns = "*.pyc\n*.pyc\n*.pyo"
|
||||||
|
result = deduplicate_patterns(patterns)
|
||||||
|
|
||||||
|
assert result.count("*.pyc") == 1
|
||||||
|
|
||||||
|
def test_filter_comments(self):
|
||||||
|
"""Test filtering out comments."""
|
||||||
|
patterns = "*.pyc\n# another"
|
||||||
|
result = self.merger.filter_comments(patterns)
|
||||||
|
|
||||||
|
assert "*.pyc" in result
|
||||||
|
|
||||||
|
def test_preserve_negation_patterns(self):
|
||||||
|
"""Test that negation patterns (!) are preserved."""
|
||||||
|
patterns = [
|
||||||
|
"*.log\n!important.log",
|
||||||
|
]
|
||||||
|
result = self.merger.merge_patterns(patterns)
|
||||||
|
|
||||||
|
assert "*.log" in result
|
||||||
|
assert "!important.log" in result
|
||||||
|
|
||||||
|
def test_empty_string_patterns(self):
|
||||||
|
"""Test handling of empty string patterns."""
|
||||||
|
patterns = [""]
|
||||||
|
result = self.merger.merge_patterns(patterns)
|
||||||
|
|
||||||
|
assert result == "\n"
|
||||||
|
|
||||||
|
|
||||||
|
class TestMergeTemplatesFunction:
|
||||||
|
"""Tests for the merge_templates convenience function."""
|
||||||
|
|
||||||
|
def test_merge_templates_convenience(self):
|
||||||
|
"""Test the merge_templates convenience function."""
|
||||||
|
patterns = [
|
||||||
|
"*.pyc",
|
||||||
|
"*.pyo",
|
||||||
|
]
|
||||||
|
result = merge_templates(patterns)
|
||||||
|
|
||||||
|
assert "*.pyc" in result
|
||||||
|
assert "*.pyo" in result
|
||||||
Reference in New Issue
Block a user