|
| 1 | +import pytest |
| 2 | +from pathlib import Path |
| 3 | +from wdoc.wdoc import wdoc |
| 4 | + |
| 5 | +def test_wdoc_version(): |
| 6 | + """Test that wdoc has a valid version string.""" |
| 7 | + assert isinstance(wdoc.VERSION, str) |
| 8 | + assert len(wdoc.VERSION.split(".")) == 3 |
| 9 | + |
| 10 | +def test_fail_parse_small_file_text(sample_text_file): |
| 11 | + """Test that a too small text file parsing fails.""" |
| 12 | + # should fail because the file is too small |
| 13 | + with pytest.raises(Exception): |
| 14 | + wdoc.parse_file( |
| 15 | + path=str(sample_text_file), |
| 16 | + filetype="txt", |
| 17 | + debug=False, |
| 18 | + verbose=False |
| 19 | + ) |
| 20 | + |
| 21 | +def test_parse_file_text(sample_text_file): |
| 22 | + """Test basic text file parsing.""" |
| 23 | + # make a bigger text file |
| 24 | + f = Path(sample_text_file) |
| 25 | + content = f.read_text() |
| 26 | + f.write_text(50 * (content + "\n")) |
| 27 | + docs = wdoc.parse_file( |
| 28 | + path=str(sample_text_file), |
| 29 | + filetype="txt", |
| 30 | + debug=False, |
| 31 | + verbose=False |
| 32 | + ) |
| 33 | + assert len(docs) > 0 |
| 34 | + assert docs[0].page_content.startswith("This is a test document") |
| 35 | + assert "multiple lines" in docs[0].page_content |
| 36 | + |
| 37 | +def test_parse_file_only_text(sample_text_file): |
| 38 | + """Test text-only output from parse_file.""" |
| 39 | + f = Path(sample_text_file) |
| 40 | + content = f.read_text() |
| 41 | + f.write_text(50 * (content + "\n")) |
| 42 | + text = wdoc.parse_file( |
| 43 | + path=str(sample_text_file), |
| 44 | + filetype="txt", |
| 45 | + only_text=True, |
| 46 | + debug=False, |
| 47 | + verbose=False |
| 48 | + ) |
| 49 | + assert isinstance(text, str) |
| 50 | + assert text.startswith("This is a test document") |
| 51 | + assert "multiple lines" in text |
| 52 | + |
| 53 | +def test_invalid_filetype(): |
| 54 | + """Test that invalid filetype raises an error.""" |
| 55 | + with pytest.raises(Exception): |
| 56 | + wdoc.parse_file( |
| 57 | + path="dummy.txt", |
| 58 | + filetype="invalid_type", |
| 59 | + debug=False, |
| 60 | + verbose=False |
| 61 | + ) |
0 commit comments