Skip to content

Commit

Permalink
Add Telegram tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joweich committed Nov 19, 2023
1 parent 4169138 commit 9b6cc32
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/telegram/test_batch_export.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"chats": {
"list": [
{
"name": "Chatname",
"messages": [
{
"type": "message",
"date_unixtime": "1544006350",
"from": "Author 1",
"text": "Minimal Message"
},
{
"type": "message",
"date_unixtime": "1544006964",
"from": "Author 2",
"text": [
{
"type": "bold",
"text": "Link:"
},
{
"type": "link",
"text": "https://telegram.org/"
}
]
}
]
}
]
}
}
25 changes: 25 additions & 0 deletions test/telegram/test_single_export.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"messages": [
{
"type": "message",
"date_unixtime": "1544006350",
"from": "Author 1",
"text": "Minimal Message"
},
{
"type": "message",
"date_unixtime": "1544006964",
"from": "Author 2",
"text": [
{
"type": "bold",
"text": "Link:"
},
{
"type": "link",
"text": "https://telegram.org/"
}
]
}
]
}
3 changes: 3 additions & 0 deletions test/telegram/test_target.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
timestamp,author,message,weekday,hour,words,letters
2018-12-05 11:39:10,Author 1,Minimal Message,Wednesday,11,2,15
2018-12-05 11:49:24,Author 2,Link: https://telegram.org/,Wednesday,11,2,27
32 changes: 32 additions & 0 deletions test/test_telegram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pandas as pd
from pandas.testing import assert_frame_equal

from chatminer.chatparsers import TelegramJsonParser


def test_telegram_single_export():
parser = TelegramJsonParser("test/telegram/test_single_export.json")
parser.parse_file()
df_res = parser.parsed_messages.get_df()
df_test = pd.read_csv(
"test/telegram/test_target.csv",
parse_dates=["timestamp"],
)
assert_frame_equal(
df_test[["author", "message", "words", "letters"]],
df_res[["author", "message", "words", "letters"]],
)


def test_telegram_batch_export():
parser = TelegramJsonParser("test/telegram/test_single_export.json", "Chatname")
parser.parse_file()
df_res = parser.parsed_messages.get_df()
df_test = pd.read_csv(
"test/telegram/test_target.csv",
parse_dates=["timestamp"],
)
assert_frame_equal(
df_test[["author", "message", "words", "letters"]],
df_res[["author", "message", "words", "letters"]],
)

0 comments on commit 9b6cc32

Please sign in to comment.