76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
from faker import Faker
|
|
|
|
from streamer.parse import Shard, StreamFile
|
|
from streamer.parse.attach_markdown import (
|
|
ShardWithMarkdown,
|
|
StreamFileWithMarkdown,
|
|
attach_markdown,
|
|
)
|
|
|
|
fake = Faker()
|
|
|
|
|
|
class TestAttachMarkdown:
|
|
file_name: str = fake.file_name(extension="md")
|
|
|
|
def test_attach_markdown_with_shard(self):
|
|
markdown_text = "Hello World\n\nThis is a test."
|
|
shard = Shard(start_line=1, end_line=3)
|
|
stream_file = StreamFile(filename=self.file_name, shard=shard)
|
|
|
|
result = attach_markdown(stream_file, markdown_text)
|
|
|
|
assert result == StreamFileWithMarkdown(
|
|
filename=self.file_name,
|
|
shard=ShardWithMarkdown(
|
|
start_line=1,
|
|
end_line=3,
|
|
markdown_content=markdown_text,
|
|
markers=[],
|
|
tags=[],
|
|
children=[],
|
|
),
|
|
)
|
|
|
|
def test_attach_markdown_without_shard(self):
|
|
stream_file = StreamFile(filename=self.file_name, shard=None)
|
|
|
|
result = attach_markdown(stream_file, "Some markdown text")
|
|
|
|
assert result == StreamFileWithMarkdown(filename=self.file_name, shard=None)
|
|
|
|
def test_attach_markdown_with_nested_shards(self):
|
|
markdown_text = "Header\n\n@Marker1 Content 1\n\n@Marker2 Content 2"
|
|
shard = Shard(
|
|
start_line=1,
|
|
end_line=5,
|
|
children=[
|
|
Shard(markers=["Marker1"], start_line=3, end_line=3),
|
|
Shard(markers=["Marker2"], start_line=5, end_line=5),
|
|
],
|
|
)
|
|
stream_file = StreamFile(filename=self.file_name, shard=shard)
|
|
|
|
result = attach_markdown(stream_file, markdown_text)
|
|
|
|
assert result.filename == self.file_name
|
|
assert result.shard is not None
|
|
assert result.shard.start_line == 1
|
|
assert result.shard.end_line == 5
|
|
assert (
|
|
result.shard.markdown_content
|
|
== "Header\n\n@Marker1 Content 1\n\n@Marker2 Content 2"
|
|
)
|
|
assert len(result.shard.children) == 2
|
|
|
|
# Check first child
|
|
assert result.shard.children[0].markers == ["Marker1"]
|
|
assert result.shard.children[0].start_line == 3
|
|
assert result.shard.children[0].end_line == 3
|
|
assert result.shard.children[0].markdown_content == "@Marker1 Content 1"
|
|
|
|
# Check second child
|
|
assert result.shard.children[1].markers == ["Marker2"]
|
|
assert result.shard.children[1].start_line == 5
|
|
assert result.shard.children[1].end_line == 5
|
|
assert result.shard.children[1].markdown_content == "@Marker2 Content 2"
|