2424class TestIdentifyUpcomingChanges :
2525 """Test the identify_upcoming_changes function."""
2626
27- def test_extract_ikraft_datum_from_section (self ):
28- """Test extracting ikraft_datum from section tag."""
29- content = '''<section id="1" class="paragraf" selex:ikraft_datum="2025-06-01">
27+ @pytest .mark .parametrize ("date_attr,date_value,expected_type,section_id" , [
28+ ("ikraft_datum" , "2025-06-01" , "ikraft" , "1" ),
29+ ("upphor_datum" , "2025-12-31" , "upphor" , "2" ),
30+ ])
31+ def test_extract_date_from_section (self , date_attr , date_value , expected_type , section_id ):
32+ """Test extracting ikraft_datum and upphor_datum from section tag."""
33+ content = f'''<section id="{ section_id } " class="paragraf" selex:{ date_attr } ="{ date_value } ">
3034
31- ## 1 §
35+ ## { section_id } §
3236
3337Content here
3438
@@ -37,28 +41,11 @@ def test_extract_ikraft_datum_from_section(self):
3741 result = identify_upcoming_changes (content )
3842
3943 assert len (result ) == 1
40- assert result [0 ]['type' ] == 'ikraft'
41- assert result [0 ]['date' ] == '2025-06-01'
44+ assert result [0 ]['type' ] == expected_type
45+ assert result [0 ]['date' ] == date_value
4246 assert result [0 ]['source' ] == 'section_tag'
43- assert result [0 ]['section_id' ] == '1'
44- assert result [0 ]['section_title' ] == '1 §'
45-
46- def test_extract_upphor_datum_from_section (self ):
47- """Test extracting upphor_datum from section tag."""
48- content = '''<section id="2" class="paragraf" selex:upphor_datum="2025-12-31">
49-
50- ## 2 §
51-
52- This section expires.
53-
54- </section>'''
55-
56- result = identify_upcoming_changes (content )
57-
58- assert len (result ) == 1
59- assert result [0 ]['type' ] == 'upphor'
60- assert result [0 ]['date' ] == '2025-12-31'
61- assert result [0 ]['section_id' ] == '2'
47+ assert result [0 ]['section_id' ] == section_id
48+ assert result [0 ]['section_title' ] == f'{ section_id } §'
6249
6350 def test_extract_from_kapital_section (self ):
6451 """Test extracting from chapter (kapital) section."""
@@ -77,26 +64,19 @@ def test_extract_from_kapital_section(self):
7764 assert result [0 ]['class_name' ] == 'kapital'
7865 assert result [0 ]['section_title' ] == '1 kap. Inledande bestämmelser'
7966
80- def test_extract_ikraft_datum_from_article (self ):
81- """Test extracting ikraft_datum from article tag."""
82- content = '<article selex:ikraft_datum="2025-03-15">Content</article>'
83-
84- result = identify_upcoming_changes (content )
85-
86- assert len (result ) == 1
87- assert result [0 ]['type' ] == 'ikraft'
88- assert result [0 ]['date' ] == '2025-03-15'
89- assert result [0 ]['source' ] == 'article_tag'
90-
91- def test_extract_upphor_datum_from_article (self ):
92- """Test extracting upphor_datum from article tag."""
93- content = '<article selex:upphor_datum="2026-12-31">Content</article>'
67+ @pytest .mark .parametrize ("date_attr,date_value,expected_type" , [
68+ ("ikraft_datum" , "2025-03-15" , "ikraft" ),
69+ ("upphor_datum" , "2026-12-31" , "upphor" ),
70+ ])
71+ def test_extract_date_from_article (self , date_attr , date_value , expected_type ):
72+ """Test extracting ikraft_datum and upphor_datum from article tag."""
73+ content = f'<article selex:{ date_attr } ="{ date_value } ">Content</article>'
9474
9575 result = identify_upcoming_changes (content )
9676
9777 assert len (result ) == 1
98- assert result [0 ]['type' ] == 'upphor'
99- assert result [0 ]['date' ] == '2026-12-31'
78+ assert result [0 ]['type' ] == expected_type
79+ assert result [0 ]['date' ] == date_value
10080 assert result [0 ]['source' ] == 'article_tag'
10181
10282 def test_extract_with_upphavd_flag (self ):
@@ -131,20 +111,20 @@ def test_multiple_dates_in_document(self):
131111 assert result [1 ]['date' ] == '2025-06-01'
132112 assert result [2 ]['date' ] == '2025-12-31'
133113
134- def test_invalid_date_format_ignored (self ):
135- """Test that invalid date formats are ignored."""
136- content = '''<section id="1" class="paragraf" selex:ikraft_datum="2025-13-45">
114+ @pytest .mark .parametrize ("invalid_date,tag_type" , [
115+ ("2025-13-45" , "section" ), # Invalid month/day
116+ ("not-a-date" , "article" ), # Malformed date
117+ ("2025-02-30" , "section" ), # Invalid day for month
118+ ])
119+ def test_invalid_dates_ignored (self , invalid_date , tag_type ):
120+ """Test that invalid and malformed dates are ignored."""
121+ if tag_type == "section" :
122+ content = f'''<section id="1" class="paragraf" selex:ikraft_datum="{ invalid_date } ">
137123## 1 §
138124Invalid date
139125</section>'''
140-
141- result = identify_upcoming_changes (content )
142-
143- assert len (result ) == 0
144-
145- def test_malformed_date_ignored (self ):
146- """Test that malformed dates are ignored."""
147- content = '''<article selex:ikraft_datum="not-a-date">Content</article>'''
126+ else :
127+ content = f'<article selex:ikraft_datum="{ invalid_date } ">Content</article>'
148128
149129 result = identify_upcoming_changes (content )
150130
0 commit comments