Exemplo n.º 1
0
def test_object_hformat():
    filename = 'tests/chats/example_1.txt'
    hformat = '%d.%m.%y, %H:%M - %name:'
    chat = WhatsAppChat.from_txt(filename)
    assert (isinstance(chat.df, pd.DataFrame))

    filename = 'tests/chats/example_2.txt'
    hformat = '[%y/%m/%d %H:%M] %name:'
    chat = WhatsAppChat.from_txt(filename)
    assert (isinstance(chat.df, pd.DataFrame))
Exemplo n.º 2
0
def test_interventions_error():

    for filename in filenames:
        chat = WhatsAppChat.from_txt(filename)
        with pytest.raises(ValueError):
            counts = interventions(chat, date_mode='error', msg_length=False)
        with pytest.raises(ValueError):
            counts = interventions(chat, date_mode='error', msg_length=True)
Exemplo n.º 3
0
def test_vis():
    for filename in filenames:
        chat = WhatsAppChat.from_txt(filename)
        counts = interventions(chat=chat, date_mode='date', msg_length=False)
        counts_cumsum = counts.cumsum() 
        fig = vis(counts_cumsum, 'cumulative number of messages sent per day')
        assert isinstance(fig, dict)
        assert ('data' in fig and 'layout' in fig)
Exemplo n.º 4
0
def test_object_len_shape():
    filename = 'tests/chats/example_1.txt'
    hformat = '%d.%m.%y, %H:%M - %name:'
    chat = WhatsAppChat.from_txt(filename)
    l = len(chat)
    assert (isinstance(l, int))
    s = chat.shape
    assert (isinstance(s, tuple))
    assert (len(s) == 2)
Exemplo n.º 5
0
def test_interventions_month_msg_length():

    for filename in filenames:
        chat = WhatsAppChat.from_txt(filename)
        counts = interventions(chat, date_mode='month', msg_length=False)

        assert (isinstance(counts, pd.DataFrame))
        # Asswert chat df and counts df have same users
        assert (set(chat.users) == set(counts.columns))

        # Check range hours
        assert (counts.index.max() == chat.df.index.month.max())
        assert (counts.index.min() == chat.df.index.month.min())
Exemplo n.º 6
0
def test_interventions_date_msg_length():

    for filename in filenames:
        chat = WhatsAppChat.from_txt(filename)
        counts = interventions(chat, date_mode='date', msg_length=True)

        assert (isinstance(counts, pd.DataFrame))
        # Asswert chat df and counts df have same users
        assert (set(chat.users) == set(counts.columns))

        # Assert chat df and counts df have same date window
        assert (chat.df.index.max().date() == counts.index.max().date())
        assert (chat.df.index.min().date() == counts.index.min().date())
Exemplo n.º 7
0
def test_interventions_hourweekday_msg_length():

    for filename in filenames:
        chat = WhatsAppChat.from_txt(filename)
        counts = interventions(chat, date_mode='hourweekday', msg_length=True)

        assert (isinstance(counts, pd.DataFrame))
        # Asswert chat df and counts df have same users
        assert (set(chat.users) == set(counts.columns))

        # Check range days
        assert (counts.index.levels[0].max() == chat.df.index.weekday.max())
        assert (counts.index.levels[0].min() == chat.df.index.weekday.min())

        # Check range hours
        assert (counts.index.levels[1].max() == chat.df.index.hour.max())
        assert (counts.index.levels[1].min() == chat.df.index.hour.min())
Exemplo n.º 8
0
def test_object_error():
    for filename in filenames:
        with pytest.raises(ValueError):
            chat = WhatsAppChat.from_txt(filename, auto_header=False)
Exemplo n.º 9
0
def test_object_auto():
    for filename in filenames:
        chat = WhatsAppChat.from_txt(filename)
        assert (isinstance(chat.df, pd.DataFrame))