import pytest
import tarzi
@pytest.fixture
def fetcher():
return tarzi.WebFetcher()
@pytest.fixture
def test_url():
return "https://httpbin.org/html"
@pytest.mark.integration
class TestWebFetcher:
def test_fetcher_creation(self, fetcher):
assert isinstance(fetcher, tarzi.WebFetcher)
assert str(fetcher) == "Tarzi web page fetcher"
assert repr(fetcher) == "WebFetcher()"
@pytest.mark.network
def test_fetch_html(self, fetcher, test_url):
try:
result = fetcher.fetch(test_url, "html")
assert isinstance(result, str)
assert len(result) > 0
except Exception as e:
pytest.skip(f"Network request failed: {e}")
@pytest.mark.network
def test_fetch_markdown(self, fetcher, test_url):
try:
result = fetcher.fetch(test_url, "markdown")
assert isinstance(result, str)
assert len(result) > 0
except Exception as e:
pytest.skip(f"Network request failed: {e}")
@pytest.mark.network
def test_fetch(self, fetcher, test_url):
try:
result = fetcher.fetch(test_url, "html")
assert isinstance(result, str)
assert len(result) > 0
except Exception as e:
pytest.skip(f"Network request failed: {e}")
def test_invalid_format(self, fetcher, test_url):
with pytest.raises(ValueError, match="Invalid format"):
fetcher.fetch(test_url, "invalid_format")
def test_from_config(self):
config = tarzi.Config()
fetcher = tarzi.WebFetcher.from_config(config)
assert isinstance(fetcher, tarzi.WebFetcher)
@pytest.mark.integration
@pytest.mark.network
def test_fetch_function(test_url):
try:
result = tarzi.fetch(test_url, "html")
assert isinstance(result, str)
assert len(result) > 0
except Exception as e:
pytest.skip(f"Network request failed: {e}")
@pytest.mark.integration
def test_fetch_invalid_format(test_url):
with pytest.raises(ValueError, match="Invalid format"):
tarzi.fetch(test_url, "invalid_format")