forked from JesperDramsch/python-deadlines
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_normalization.py
More file actions
688 lines (524 loc) · 25.5 KB
/
Copy pathtest_normalization.py
File metadata and controls
688 lines (524 loc) · 25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
"""Tests for conference name normalization.
This module tests the tidy_df_names function and related title normalization
logic. Tests verify specific transformations, not just that the code runs.
Key behaviors tested:
- Year removal from conference names
- Whitespace normalization
- Abbreviation expansion (Conf -> Conference)
- Known mapping application
- Idempotency (applying twice yields same result)
"""
import sys
from pathlib import Path
from unittest.mock import patch
import pandas as pd
import pytest
sys.path.insert(0, str(Path(__file__).parent))
sys.path.append(str(Path(__file__).parent.parent / "utils"))
from hypothesis_strategies import HYPOTHESIS_AVAILABLE
from hypothesis_strategies import valid_year
from tidy_conf.titles import tidy_df_names
class TestYearRemoval:
"""Test that tidy_df_names correctly removes years from conference names."""
@pytest.fixture(autouse=True)
def setup_mock_mappings(self):
"""Mock title mappings for all tests in this class."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
yield mock
def test_removes_four_digit_year_2026(self):
"""Name normalization should remove 4-digit year from conference name.
Input: "PyCon Germany 2026"
Expected: Year removed, conference name preserved
"""
df = pd.DataFrame({"conference": ["PyCon Germany 2026"]})
result = tidy_df_names(df)
assert (
"2026" not in result["conference"].iloc[0]
), f"Year '2026' should be removed, got: {result['conference'].iloc[0]}"
assert "PyCon" in result["conference"].iloc[0], "Conference name 'PyCon' should be preserved"
assert "Germany" in result["conference"].iloc[0], "Conference location 'Germany' should be preserved"
def test_removes_four_digit_year_2025(self):
"""Year removal should work for different years (2025)."""
df = pd.DataFrame({"conference": ["DjangoCon US 2025"]})
result = tidy_df_names(df)
assert "2025" not in result["conference"].iloc[0]
assert "DjangoCon US" in result["conference"].iloc[0]
def test_removes_year_at_end(self):
"""Year at end of name should be removed."""
df = pd.DataFrame({"conference": ["EuroPython 2026"]})
result = tidy_df_names(df)
assert "2026" not in result["conference"].iloc[0]
assert "EuroPython" in result["conference"].iloc[0]
def test_removes_year_in_middle(self):
"""Year in middle of name should be removed."""
df = pd.DataFrame({"conference": ["PyCon 2026 US"]})
result = tidy_df_names(df)
assert "2026" not in result["conference"].iloc[0]
def test_preserves_non_year_numbers(self):
"""Non-year numbers should be preserved (e.g., Python 3)."""
df = pd.DataFrame({"conference": ["Python 3 Conference"]})
result = tidy_df_names(df)
# "3" should be preserved since it's not a year
assert "3" in result["conference"].iloc[0] or "Python" in result["conference"].iloc[0]
class TestWhitespaceNormalization:
"""Test whitespace handling in conference names."""
@pytest.fixture(autouse=True)
def setup_mock_mappings(self):
"""Mock title mappings for all tests in this class."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
yield mock
def test_removes_extra_spaces(self):
"""Multiple spaces should be collapsed to single space."""
df = pd.DataFrame({"conference": ["PyCon Germany 2026"]})
result = tidy_df_names(df)
# Should not have double spaces
assert (
" " not in result["conference"].iloc[0]
), f"Double spaces should be removed, got: '{result['conference'].iloc[0]}'"
def test_strips_leading_trailing_whitespace(self):
"""Leading and trailing whitespace should be removed."""
df = pd.DataFrame({"conference": [" PyCon Germany "]})
result = tidy_df_names(df)
assert not result["conference"].iloc[0].startswith(" "), "Leading whitespace should be stripped"
assert not result["conference"].iloc[0].endswith(" "), "Trailing whitespace should be stripped"
def test_handles_tabs_and_newlines(self):
"""Tabs and other whitespace should be normalized."""
df = pd.DataFrame({"conference": ["PyCon\tGermany"]})
result = tidy_df_names(df)
# Result should be clean
assert "\t" not in result["conference"].iloc[0]
class TestAbbreviationExpansion:
"""Test expansion of common abbreviations."""
@pytest.fixture(autouse=True)
def setup_mock_mappings(self):
"""Mock title mappings for all tests in this class."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
yield mock
def test_expands_conf_to_conference(self):
"""'Conf ' should be expanded to 'Conference '."""
# Test with actual "Conf " pattern (with space after)
df = pd.DataFrame({"conference": ["Python Conf 2026", "PyConf 2026"]})
result = tidy_df_names(df)
# The regex replaces r"\bConf \b" with "Conference "
# "Python Conf 2026" should become "Python Conference" (year removed, Conf expanded)
# "PyConf" has no space after "Conf", so it should remain "PyConf" (just year removed)
assert isinstance(result["conference"].iloc[0], str), "Result should be a string"
assert len(result["conference"].iloc[0]) > 0, "Result should not be empty"
# Year should be removed from both
assert "2026" not in result["conference"].iloc[0], "Year should be removed"
assert "2026" not in result["conference"].iloc[1], "Year should be removed"
class TestKnownMappings:
"""Test that known conference name mappings are applied."""
def test_applies_reverse_mapping(self):
"""Known mappings should map variants to canonical names."""
mapping_data = {
"PyCon DE": "PyCon Germany & PyData Conference",
"PyCon Italia": "PyCon Italy",
}
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], mapping_data)
df = pd.DataFrame({"conference": ["PyCon DE"]})
result = tidy_df_names(df)
# Should be mapped to canonical name
assert (
result["conference"].iloc[0] == "PyCon Germany & PyData Conference"
), f"Expected canonical name, got: {result['conference'].iloc[0]}"
def test_preserves_unmapped_names(self):
"""Conferences without mappings should be preserved."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
df = pd.DataFrame({"conference": ["Unique Conference Name"]})
result = tidy_df_names(df)
assert "Unique Conference Name" in result["conference"].iloc[0]
class TestIdempotency:
"""Test that normalization is idempotent (applying twice yields same result)."""
@pytest.fixture(autouse=True)
def setup_mock_mappings(self):
"""Mock title mappings for all tests in this class."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
yield mock
def test_idempotent_on_simple_name(self):
"""Applying tidy_df_names twice should yield identical result."""
df = pd.DataFrame({"conference": ["PyCon Germany 2026"]})
result1 = tidy_df_names(df.copy())
result2 = tidy_df_names(result1.copy())
assert result1["conference"].iloc[0] == result2["conference"].iloc[0], "tidy_df_names should be idempotent"
def test_idempotent_on_already_clean_name(self):
"""Already normalized names should stay the same."""
df = pd.DataFrame({"conference": ["PyCon Germany"]})
result1 = tidy_df_names(df.copy())
result2 = tidy_df_names(result1.copy())
assert result1["conference"].iloc[0] == result2["conference"].iloc[0]
class TestSpecialCharacters:
"""Test handling of special characters in conference names."""
@pytest.fixture(autouse=True)
def setup_mock_mappings(self):
"""Mock title mappings for all tests in this class."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
yield mock
def test_preserves_accented_characters(self):
"""Accented characters (like in México) should be preserved."""
df = pd.DataFrame({"conference": ["PyCon México 2026"]})
result = tidy_df_names(df)
# The accented character should be preserved
assert (
"xico" in result["conference"].iloc[0].lower()
), f"Conference name should preserve México, got: {result['conference'].iloc[0]}"
def test_handles_ampersand(self):
"""Ampersand in conference names should be preserved."""
df = pd.DataFrame({"conference": ["PyCon Germany & PyData Conference"]})
result = tidy_df_names(df)
assert "&" in result["conference"].iloc[0], "Ampersand should be preserved in conference name"
def test_handles_plus_sign(self):
"""Plus signs should be replaced with spaces (based on code)."""
df = pd.DataFrame({"conference": ["Python+3 Conference"]})
result = tidy_df_names(df)
# The regex replaces + with space
assert "+" not in result["conference"].iloc[0], "Plus sign should be replaced"
class TestMultipleConferences:
"""Test normalization on DataFrames with multiple conferences."""
@pytest.fixture(autouse=True)
def setup_mock_mappings(self):
"""Mock title mappings for all tests in this class."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
yield mock
def test_normalizes_all_conferences(self):
"""All conferences in DataFrame should be normalized."""
df = pd.DataFrame(
{
"conference": [
"PyCon Germany 2026",
"DjangoCon US 2025",
"EuroPython 2026",
],
},
)
result = tidy_df_names(df)
# No year should remain in any name
for name in result["conference"]:
assert "2025" not in name and "2026" not in name, f"Year should be removed from '{name}'"
def test_preserves_dataframe_length(self):
"""Normalization should not add or remove rows."""
df = pd.DataFrame(
{
"conference": [
"PyCon Germany 2026",
"DjangoCon US 2025",
"EuroPython 2026",
],
},
)
result = tidy_df_names(df)
assert len(result) == len(df), "DataFrame length should be preserved"
def test_preserves_other_columns(self):
"""Other columns should be preserved through normalization."""
df = pd.DataFrame(
{
"conference": ["PyCon Germany 2026"],
"year": [2026],
"link": ["https://pycon.de/"],
},
)
result = tidy_df_names(df)
assert "year" in result.columns
assert "link" in result.columns
assert result["year"].iloc[0] == 2026
assert result["link"].iloc[0] == "https://pycon.de/"
class TestRealDataNormalization:
"""Test normalization with real test fixtures (integration-style unit tests)."""
@pytest.fixture(autouse=True)
def setup_mock_mappings(self):
"""Mock title mappings for all tests in this class."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
yield mock
def test_normalizes_minimal_yaml_fixture(self, minimal_yaml_df):
"""Normalization should work correctly on the minimal_yaml fixture."""
result = tidy_df_names(minimal_yaml_df.reset_index(drop=True))
# All conferences should still be present
assert len(result) == len(minimal_yaml_df)
# Conference names should be normalized (no years in the test data anyway)
for name in result["conference"]:
assert isinstance(name, str), f"Conference name should be string, got {type(name)}"
assert len(name) > 0, "Conference name should not be empty"
def test_handles_csv_dataframe(self, minimal_csv_df):
"""Normalization should work on CSV-sourced DataFrame."""
result = tidy_df_names(minimal_csv_df)
# Should handle CSV names (which may have year variants)
assert len(result) == len(minimal_csv_df)
# Check that PyCon US 2026 has year removed
pycon_us_rows = result[result["conference"].str.contains("PyCon US", na=False)]
if len(pycon_us_rows) > 0:
for name in pycon_us_rows["conference"]:
assert "2026" not in name, f"Year should be removed from '{name}'"
class TestRegressionCases:
"""Regression tests for bugs found in production.
These tests document specific bugs and ensure they stay fixed.
"""
@pytest.fixture(autouse=True)
def setup_mock_mappings(self):
"""Mock title mappings for all tests in this class."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
yield mock
def test_regression_pycon_de_name_preserved(self):
"""REGRESSION: PyCon DE name should not be corrupted during normalization.
This ensures the normalization doesn't mangle short conference names.
"""
df = pd.DataFrame({"conference": ["PyCon DE"]})
result = tidy_df_names(df)
# Name should still be recognizable
assert "PyCon" in result["conference"].iloc[0], "PyCon should be preserved in the name"
def test_regression_extra_spaces_dont_accumulate(self):
"""REGRESSION: Repeated normalization shouldn't add extra spaces.
Processing with regex should not introduce artifacts.
"""
df = pd.DataFrame({"conference": ["PyCon Germany"]})
# Apply multiple times
for _ in range(3):
df = tidy_df_names(df.copy())
# Should not have accumulated spaces
name = df["conference"].iloc[0]
assert " " not in name, f"Extra spaces accumulated: '{name}'"
class TestRTLUnicodeHandling:
"""Test handling of Right-to-Left scripts (Arabic, Hebrew).
Coverage gap: RTL scripts require special handling and can cause
display and processing issues if not handled correctly.
"""
def test_arabic_conference_name(self):
"""Test Arabic script in conference name."""
# "PyCon Arabia" with Arabic text
df = pd.DataFrame({"conference": ["PyCon العربية 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
# Should not crash and should preserve Arabic characters
assert len(result) == 1
conf_name = result["conference"].iloc[0]
assert len(conf_name) > 0
def test_hebrew_conference_name(self):
"""Test Hebrew script in conference name."""
# "PyCon Israel" with Hebrew text
df = pd.DataFrame({"conference": ["PyCon ישראל 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
# Should not crash and should preserve Hebrew characters
assert len(result) == 1
conf_name = result["conference"].iloc[0]
assert len(conf_name) > 0
def test_mixed_rtl_ltr_text(self):
"""Test mixed RTL and LTR text (bidirectional)."""
# Conference name with both English and Arabic
df = pd.DataFrame({"conference": ["PyData مؤتمر Conference 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
# Should handle bidirectional text without crashing
assert len(result) == 1
conf_name = result["conference"].iloc[0]
assert "PyData" in conf_name or len(conf_name) > 0
def test_persian_farsi_conference_name(self):
"""Test Persian/Farsi script (RTL, Arabic-derived)."""
df = pd.DataFrame({"conference": ["PyCon ایران 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
assert len(result) == 1
assert len(result["conference"].iloc[0]) > 0
def test_urdu_conference_name(self):
"""Test Urdu script (RTL, Arabic-derived)."""
df = pd.DataFrame({"conference": ["PyCon پاکستان 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
assert len(result) == 1
assert len(result["conference"].iloc[0]) > 0
def test_rtl_with_numbers(self):
"""Test RTL text with embedded numbers."""
# Numbers in RTL context can have special display behavior
df = pd.DataFrame({"conference": ["مؤتمر 2026 Python"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
# Should handle without crashing
assert len(result) == 1
def test_rtl_marks_and_controls(self):
"""Test handling of RTL control characters."""
# Unicode RTL mark (U+200F) and LTR mark (U+200E)
rtl_mark = "\u200f"
ltr_mark = "\u200e"
df = pd.DataFrame({"conference": [f"PyCon {rtl_mark}Test{ltr_mark} 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
# Should handle invisible control characters
assert len(result) == 1
class TestCJKUnicodeHandling:
"""Test handling of CJK (Chinese, Japanese, Korean) scripts.
Additional coverage for East Asian character sets.
"""
def test_chinese_simplified_conference_name(self):
"""Test Simplified Chinese conference name."""
df = pd.DataFrame({"conference": ["PyCon 中国 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
assert len(result) == 1
assert len(result["conference"].iloc[0]) > 0
def test_chinese_traditional_conference_name(self):
"""Test Traditional Chinese conference name."""
df = pd.DataFrame({"conference": ["PyCon 台灣 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
assert len(result) == 1
assert len(result["conference"].iloc[0]) > 0
def test_japanese_conference_name(self):
"""Test Japanese conference name with mixed scripts."""
# Japanese uses Hiragana, Katakana, and Kanji
df = pd.DataFrame({"conference": ["PyCon JP 日本 パイコン 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
assert len(result) == 1
assert len(result["conference"].iloc[0]) > 0
def test_korean_conference_name(self):
"""Test Korean (Hangul) conference name."""
df = pd.DataFrame({"conference": ["PyCon 한국 파이콘 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
assert len(result) == 1
assert len(result["conference"].iloc[0]) > 0
def test_fullwidth_characters(self):
"""Test fullwidth ASCII characters (common in CJK contexts)."""
# Fullwidth "PyCon" using Unicode escapes (U+FF30, U+FF59, U+FF43, U+FF4F, U+FF4E)
fullwidth_pycon = "\uff30\uff59\uff43\uff4f\uff4e"
df = pd.DataFrame({"conference": [f"{fullwidth_pycon} Conference 2026"]})
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
result = tidy_df_names(df)
assert len(result) == 1
# ---------------------------------------------------------------------------
# Property-based tests using Hypothesis
# ---------------------------------------------------------------------------
if HYPOTHESIS_AVAILABLE:
from hypothesis import HealthCheck
from hypothesis import assume
from hypothesis import given
from hypothesis import settings
from hypothesis import strategies as st
pytestmark_hypothesis = pytest.mark.skipif(
not HYPOTHESIS_AVAILABLE,
reason="hypothesis not installed - run: pip install hypothesis",
)
@pytest.mark.skipif(not HYPOTHESIS_AVAILABLE, reason="hypothesis not installed")
class TestNormalizationProperties:
"""Property-based tests for name normalization."""
@given(st.text(min_size=1, max_size=100))
@settings(max_examples=100, suppress_health_check=[HealthCheck.filter_too_much])
def test_normalization_never_crashes(self, text):
"""Normalization should never crash regardless of input."""
assume(len(text.strip()) > 0)
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
df = pd.DataFrame({"conference": [text]})
# Should not raise any exception
try:
result = tidy_df_names(df)
assert isinstance(result, pd.DataFrame)
except Exception as e:
# Only allow expected exceptions
if "empty" not in str(e).lower():
raise
@given(st.text(alphabet=st.characters(whitelist_categories=("L", "N", "P", "S")), min_size=5, max_size=50))
@settings(max_examples=100)
def test_normalization_preserves_non_whitespace(self, text):
"""Normalization should preserve meaningful characters."""
assume(len(text.strip()) > 0)
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
df = pd.DataFrame({"conference": [text]})
result = tidy_df_names(df)
# Result should not be empty
assert len(result) == 1
assert len(result["conference"].iloc[0].strip()) > 0
@given(st.text(min_size=1, max_size=50))
@settings(max_examples=50)
def test_normalization_is_idempotent(self, text):
"""Applying normalization twice should yield same result."""
assume(len(text.strip()) > 0)
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
df = pd.DataFrame({"conference": [text]})
result1 = tidy_df_names(df.copy())
result2 = tidy_df_names(result1.copy())
assert (
result1["conference"].iloc[0] == result2["conference"].iloc[0]
), f"Idempotency failed: '{result1['conference'].iloc[0]}' != '{result2['conference'].iloc[0]}'"
@given(valid_year)
@settings(max_examples=50)
def test_year_removal_works_for_any_valid_year(self, year):
"""Year removal should work for any year 1990-2050."""
name = f"PyCon Conference {year}"
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
df = pd.DataFrame({"conference": [name]})
result = tidy_df_names(df)
assert (
str(year) not in result["conference"].iloc[0]
), f"Year {year} should be removed from '{result['conference'].iloc[0]}'"
@pytest.mark.skipif(not HYPOTHESIS_AVAILABLE, reason="hypothesis not installed")
class TestUnicodeHandlingProperties:
"""Property-based tests for Unicode handling."""
@given(
st.text(
alphabet=st.characters(
whitelist_categories=("L",), # Letters only
whitelist_characters="áéíóúñüöäÄÖÜßàèìòùâêîôûçÇ",
),
min_size=5,
max_size=30,
),
)
@settings(max_examples=50)
def test_unicode_letters_preserved(self, text):
"""Unicode letters should be preserved through normalization."""
assume(len(text.strip()) > 3)
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
df = pd.DataFrame({"conference": [f"PyCon {text}"]})
result = tidy_df_names(df)
# Check that some Unicode is preserved
result_text = result["conference"].iloc[0]
assert len(result_text) > 0, "Result should not be empty"
@given(
st.sampled_from(
[
"PyCon México",
"PyCon España",
"PyCon Österreich",
"PyCon Česko",
"PyCon Türkiye",
"PyCon Ελλάδα",
"PyCon 日本",
"PyCon 한국",
],
),
)
def test_specific_unicode_names_handled(self, name):
"""Specific international conference names should be handled."""
with patch("tidy_conf.titles.load_title_mappings") as mock:
mock.return_value = ([], {})
df = pd.DataFrame({"conference": [name]})
result = tidy_df_names(df)
# Should not crash and should produce non-empty result
assert len(result) == 1
assert len(result["conference"].iloc[0]) > 0