Beispiel #1
0
def test_merge():
    chat1 = WhatsAppChat.from_source(filename1)
    chat2 = WhatsAppChat.from_source(filename2)
    chat = chat1.merge(chat2)
    assert (isinstance(chat.df, pd.DataFrame))
    chat = chat1.merge(chat2, rename_users={'J': ['John']})
    assert (isinstance(chat.df, pd.DataFrame))
Beispiel #2
0
def test_interventions_date_cumsum():
    chat = WhatsAppChat.from_source(filename)
    counts = get_interventions_count(chat=chat,
                                     date_mode='date',
                                     msg_length=False,
                                     cumulative=True)

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

    # 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())

    # TO BE DEPRECATED
    counts = get_interventions_count(chat=chat,
                                     date_mode='date',
                                     msg_length=False,
                                     cummulative=True)

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

    # 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())
Beispiel #3
0
def test_get_response_matrix_2():
    chat = WhatsAppChat.from_source(filename)
    df_resp = get_response_matrix(chat=chat, zero_own=False)

    # Check shape and colnames of returned dataframe
    n_users = len(chat.users)
    assert(df_resp.shape == (n_users, n_users))
    assert(set(chat.users) == set(df_resp.columns))
Beispiel #4
0
def test_interventions_error_1():
    chat = WhatsAppChat.from_source(filename)
    with pytest.raises(ValueError):
        _ = get_interventions_count(chat=chat,
                                    date_mode='error',
                                    msg_length=False)
    with pytest.raises(ValueError):
        _ = get_interventions_count(chat=chat,
                                    date_mode='error',
                                    msg_length=True)
Beispiel #5
0
def test_get_response_matrix_5():
    chat = WhatsAppChat.from_source(filename)
    df_resp = get_response_matrix(chat=chat, norm='receiver')

    # Check shape and colnames of returned dataframe
    n_users = len(chat.users)
    assert(df_resp.shape == (n_users, n_users))
    assert(set(chat.users) == set(df_resp.columns))

    # Check scaling has been done correct
    assert(all([math.isclose(x, 1) for x in df_resp.sum(axis=0)]))
Beispiel #6
0
def test_get_response_matrix_1():
    chat = WhatsAppChat.from_source(filename)
    df_resp = get_response_matrix(chat=chat, zero_own=True)

    # Check shape and colnames of returned dataframe
    n_users = len(chat.users)
    assert(df_resp.shape == (n_users, n_users))
    assert(set(chat.users) == set(df_resp.columns))

    # Check diagonal of returned dataframe is zero
    assert(all([df_resp.loc[user, user] == 0 for user in df_resp.columns]))
Beispiel #7
0
def test_get_response_matrix_3():
    chat = WhatsAppChat.from_source(filename)
    df_resp = get_response_matrix(chat=chat, norm='joint')

    # Check shape and colnames of returned dataframe
    n_users = len(chat.users)
    assert(df_resp.shape == (n_users, n_users))
    assert(set(chat.users) == set(df_resp.columns))

    # Check scaling has been done correct
    assert(math.isclose(df_resp.sum().sum(), 1))
Beispiel #8
0
def main():
    """Main script."""
    args = _parse_args()
    chat = WhatsAppChat.from_source(filepath=args.input_filename,
                                    hformat=args.hformat)

    if args.type == "interventions_count":
        fig = FigureBuilder(chat=chat).user_interventions_count_linechart(
            date_mode=args.icount_date_mode,
            msg_length=False,
            cumulative=args.icount_cumulative)
    elif args.type == "msg_length":
        fig = FigureBuilder(chat=chat).user_msg_length_boxplot()
    plot(fig, filename=args.output_filename)
Beispiel #9
0
def test_interventions_hour_msg_length():
    chat = WhatsAppChat.from_source(filename)
    counts = get_interventions_count(chat=chat,
                                     date_mode='hour',
                                     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 (len(chat.users) == counts.shape[1])

    # Check range hours
    assert (counts.index.max() == chat.df.index.hour.max())
    assert (counts.index.min() == chat.df.index.hour.min())
Beispiel #10
0
def test_interventions_date_all():
    chat = WhatsAppChat.from_source(filename)
    counts = get_interventions_count(chat=chat,
                                     date_mode='date',
                                     msg_length=False,
                                     all_users=True)

    assert (isinstance(counts, pd.DataFrame))
    # Asswert chat df and counts df have same users
    assert (len(counts.columns) == 1)
    assert (counts.columns == ['interventions count'])

    # 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())
Beispiel #11
0
def test_object_error():
    with pytest.raises(ValueError):
        _ = WhatsAppChat.from_source(filename, auto_header=False)
Beispiel #12
0
def main():
    """Main script."""
    args = _parse_args()
    chat = WhatsAppChat.from_source(filepath=args.input_filename,
                                    hformat=args.hformat)
    chat.to_csv(args.output_filename)
Beispiel #13
0
def test_len():
    chat = WhatsAppChat.from_source(filename)
    assert (isinstance(len(chat), int))
Beispiel #14
0
def test_rename_users_error():
    chat = WhatsAppChat.from_source(filename)
    with pytest.raises(ValueError):
        chat = chat.rename_users(mapping={'J': 'John'})
Beispiel #15
0
def test_rename_users():
    chat = WhatsAppChat.from_source(filename)
    chat = chat.rename_users(mapping={'J': ['John']})
    assert (isinstance(chat.df, pd.DataFrame))
Beispiel #16
0
def test_properties():
    chat = WhatsAppChat.from_source(filepath)

    assert (isinstance(chat.start_date, datetime))
    assert (isinstance(chat.end_date, datetime))
Beispiel #17
0
def test_object_from_source_error(tmpdir):
    with pytest.raises((HFormatError, KeyError)):
        _ = WhatsAppChat.from_source(filename, hformat="%y%name")
Beispiel #18
0
def test_object_to_txt(tmpdir):
    chat = WhatsAppChat.from_source(filename)
    filename_ = tmpdir.join("export")
    with pytest.raises(ValueError):
        chat.to_txt(filepath=str(filename_))
Beispiel #19
0
def load_chat_as_df():
    return WhatsAppChat.from_source(filename).df
Beispiel #20
0
def test_get_response_matrix_error():
    chat = WhatsAppChat.from_source(filename)
    with pytest.raises(ValueError):
        _ = get_response_matrix(chat=chat, norm='error')
Beispiel #21
0
def test_object_hformat():
    chat = WhatsAppChat.from_source(filename)
    assert (isinstance(chat.df, pd.DataFrame))

    chat = WhatsAppChat.from_source(filename)
    assert (isinstance(chat.df, pd.DataFrame))
Beispiel #22
0
def test_object_to_csv_1(tmpdir):
    chat = WhatsAppChat.from_source(filename)
    filename_ = tmpdir.join("export.csv")
    chat.to_csv(filepath=str(filename_))
Beispiel #23
0
def load_chat():
    return WhatsAppChat.from_source(filename)