import pytest
import tarzi
@pytest.fixture
def converter():
return tarzi.Converter()
@pytest.fixture
def sample_html():
return '<h1>Test Title</h1><p>Test <strong>content</strong> with <a href="https://example.com">link</a>.</p>'
@pytest.mark.unit
class TestConverter:
def test_converter_creation(self, converter):
assert isinstance(converter, tarzi.Converter)
assert str(converter) == "Tarzi HTML/text content converter"
assert repr(converter) == "Converter()"
def test_html_conversion(self, converter, sample_html):
result = converter.convert(sample_html, "html")
assert result == sample_html
def test_markdown_conversion(self, converter, sample_html):
result = converter.convert(sample_html, "markdown")
assert isinstance(result, str)
assert len(result) > 0
assert "Test Title" in result
def test_json_conversion(self, converter, sample_html):
result = converter.convert(sample_html, "json")
assert isinstance(result, str)
assert len(result) > 0
assert "Test Title" in result
assert "content" in result
def test_yaml_conversion(self, converter, sample_html):
result = converter.convert(sample_html, "yaml")
assert isinstance(result, str)
assert len(result) > 0
assert "Test Title" in result
def test_invalid_format(self, converter, sample_html):
with pytest.raises(ValueError, match="Invalid format"):
converter.convert(sample_html, "invalid_format")
def test_empty_html(self, converter):
result = converter.convert("", "html")
assert result == ""
def test_from_config(self):
config = tarzi.Config()
converter = tarzi.Converter.from_config(config)
assert isinstance(converter, tarzi.Converter)
@pytest.mark.unit
def test_convert_html_function(sample_html):
result = tarzi.convert_html(sample_html, "html")
assert result == sample_html
result = tarzi.convert_html(sample_html, "markdown")
assert isinstance(result, str)
assert len(result) > 0
@pytest.mark.unit
def test_convert_html_invalid_format(sample_html):
with pytest.raises(ValueError, match="Invalid format"):
tarzi.convert_html(sample_html, "invalid_format")