Skip to content

Commit

Permalink
edited tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Olthoff231381 committed Sep 10, 2024
1 parent 4a37487 commit ec1e25d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions mailcom/test/test_inout.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
from mailcom.inout import list_of_files, get_text, get_html_text
from mailcom import inout
import pytest
from pathlib import Path
from importlib import resources

pkg = resources.files("mailcom")
io = inout.InoutHandler()

FILE_PATH = Path(pkg / "test" / "data" / "Bonjour Agathe.eml")
TEXT_REF = "J'espère que tu vas bien!"

def test_list_of_files_found(tmp_path):
p = tmp_path / "test.eml"
p.write_text("test")
assert len(list_of_files(tmp_path)) != 0
assert len(io.list_of_files(tmp_path)) != 0

def test_list_of_files_empty(tmp_path):
with pytest.raises(ValueError):
list_of_files(tmp_path)
io.list_of_files(tmp_path)

def test_list_of_files_dir_not_existing():
with pytest.raises(OSError):
list_of_files("nonexistingDir")
io.list_of_files("nonexistingDir")

def test_list_of_files_correct_format(tmp_path):
p = tmp_path / "test.eml"
Expand All @@ -28,29 +29,29 @@ def test_list_of_files_correct_format(tmp_path):
p.write_text("test2")
p = tmp_path / "test3.xml"
p.write_text("test3")
assert tmp_path / "test3.xml" not in list_of_files(tmp_path)
assert tmp_path / "test3.xml" not in io.list_of_files(tmp_path)

def test_get_text(tmp_path):
p = tmp_path / "test.eml"
p.write_text("test")
assert get_text(p) == 'test'
text = get_text(FILE_PATH)
assert io.get_text(p) == 'test'
text = io.get_text(FILE_PATH)
print(text[0:25])
assert text[0:25] == TEXT_REF

def test_get_text_err():
with pytest.raises(OSError):
list_of_files("nonexistingDir")
io.list_of_files("nonexistingDir")

def test_get_html_text():
html = """<html><head><title>Test</title></head></html>"""
assert get_html_text(html) == 'Test'
assert io.get_html_text(html) == 'Test'

def test_get_html_text_noHtml():
noHtml = """Test"""
assert get_html_text(noHtml) == 'Test'
assert io.get_html_text(noHtml) == 'Test'

def test_get_text_no_file(tmp_path):
p = tmp_path / "test.eml"
with pytest.raises(OSError):
get_text(p)
io.get_text(p)

0 comments on commit ec1e25d

Please sign in to comment.