<commit_before>import sqlite3

from datavisapp.create_db import make_table, append_csv_to_table


def test_make_table(tmpdir):
    db = str(tmpdir.join('test.db'))

    col_types = [
        ('DataSet', 'str'),
        ('Date', 'str'),
    ]
    make_table(db, 'metadata', col_types)

    conn = sqlite3.connect(db)
    cursor = conn.cursor()
    cursor.execute("select name from sqlite_master where type = 'table'")
    existing_tables = cursor.fetchall()
    conn.close()
    assert ('metadata',) in existing_tables


def test_append_csv_to_table(tmpdir):
    db = str(tmpdir.join('test.db'))

    col_types = [
        ('Sample', 'str'),
        ('MetricA', 'float'),
        ('MetricB', 'float'),
    ]
    make_table(db, 'experiment1_metrics', col_types)
    append_csv_to_table(db, 'experiment1_metrics', 'tests/data/DatasetX.csv')

    conn = sqlite3.connect(db)
    cursor = conn.cursor()
    cursor.execute("select * from experiment1_metrics")
    table_result = cursor.fetchall()
    conn.close()
    assert ('S01', 0.5, 20.0) and ('S02', 0.9, 45.0) in table_result<commit_msg>fix and expand test for append_csv<commit_after>import sqlite3
from pathlib import Path

from datavisapp.create_db import make_table, append_csv_to_table


def test_make_table(tmpdir):
    db = str(tmpdir.join('test.db'))

    col_types = [
        ('DataSet', 'str'),
        ('Date', 'str'),
    ]
    make_table(db, 'metadata', col_types)

    conn = sqlite3.connect(db)
    cursor = conn.cursor()
    cursor.execute("select name from sqlite_master where type = 'table'")
    existing_tables = cursor.fetchall()
    conn.close()
    assert ('metadata',) in existing_tables


def test_append_csv_to_table(tmpdir):
    db = str(tmpdir.join('test.db'))

    col_types = [
        ('Sample', 'str'),
        ('MetricA', 'float'),
        ('MetricB', 'float'),
    ]
    make_table(db, 'experiment1_metrics', col_types)
    csv_x = Path('tests', 'data', 'DatasetX.csv')
    csv_y = Path('tests', 'data', 'DatasetY.csv')
    append_csv_to_table(db, 'experiment1_metrics', csv_x)
    append_csv_to_table(db, 'experiment1_metrics', csv_y)

    conn = sqlite3.connect(db)
    cursor = conn.cursor()
    cursor.execute("select * from experiment1_metrics")
    table_result = cursor.fetchall()
    conn.close()
    assert table_result == [
        ('S01', 0.5, 20.0),
        ('S02', 0.9, 45.0),
        ('S01', 0.7, 10.0),
        ('S02', 0.9, 20.0),
    ]
{'fraction_non_alphanumeric': 0.1539408866995074, 'fraction_numerical': 0.02257799671592775, 'mean_word_length': 3.282952548330404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6683860', 'n_tokens_mistral': 880, 'n_tokens_neox': 836, 'n_words': 171}