Download tests/test_cleaner.py from Amitkumar001/Law_Slm: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/Amitkumar001/Law_Slm/resolve/main/tests/test_cleaner.py
- Command line
-
hf download hf://Amitkumar001/Law_Slm/tests/test_cleaner.py
-
curl -L -o test_cleaner.py https://huggingface.co/Amitkumar001/Law_Slm/resolve/main/tests/test_cleaner.py
1.26 kB
| """ | |
| Unit tests for DataCleaner. | |
| """ | |
| import pytest | |
| from slm.dataset.cleaner import DataCleaner | |
| def test_data_cleaner_functions(): | |
| cleaner = DataCleaner(min_doc_chars=10, min_doc_words=2) | |
| # 1. HTML stripping & Unicode normalization | |
| dirty_text = "<p>Hello & World!\u00A0</p>\x00" | |
| cleaned = cleaner.clean_document(dirty_text) | |
| assert "<p>" not in cleaned | |
| assert "Hello" in cleaned | |
| assert "World!" in cleaned | |
| # 2. Paragraph deduplication | |
| dup_text = "Paragraph One.\n\nParagraph Two.\n\nParagraph One." | |
| deduped = cleaner.deduplicate_paragraphs(dup_text) | |
| assert deduped == "Paragraph One.\n\nParagraph Two." | |
| # 3. Document validation | |
| assert cleaner.is_valid_document("This is a valid test document.") | |
| assert not cleaner.is_valid_document("Short") | |
| def test_process_corpus(): | |
| cleaner = DataCleaner(min_doc_chars=10, min_doc_words=2) | |
| corpus = [ | |
| "<h1>Title</h1>\n<p>This is a valid long document for testing.</p>", | |
| "Too short", | |
| "Duplicate paragraph.\n\nDuplicate paragraph." | |
| ] | |
| retained, stats = cleaner.process_corpus(corpus) | |
| assert stats["total_input_documents"] == 3 | |
| assert stats["retained_documents"] == 2 | |
| assert stats["filtered_documents"] == 1 | |