<commit_before>from bndl.compute import cassandra  # @UnusedImport
from bndl.compute.dataset.tests import DatasetTest


class CassandraTest(DatasetTest):
    keyspace = 'bndl_cassandra_test'
    table = 'test_table'

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        with cls.ctx.cassandra_session() as session:
            session.execute('''
                create keyspace if not exists {keyspace} 
                with replication = {{
                    'class': 'SimpleStrategy',
                    'replication_factor': '1'
                }};
            '''.format(keyspace=cls.keyspace))

            session.execute('''
                create table if not exists {keyspace}.{table} (
                    key text,
                    cluster text,
                    int_list list<int>,
                    double_set set<double>,
                    text_map map<text,text>,
                    timestamp_val timestamp,
                    varint_val varint,
                    primary key (key, cluster)
                );
            '''.format(keyspace=cls.keyspace, table=cls.table))


    def setUp(self):
        super().setUp()
        truncate = 'truncate {keyspace}.{table};'.format(keyspace=self.keyspace, table=self.table)
        self.ctx.cassandra_session().execute(truncate)
<commit_msg>use cassandra_session as a context manager<commit_after>from bndl.compute import cassandra  # @UnusedImport
from bndl.compute.dataset.tests import DatasetTest


class CassandraTest(DatasetTest):
    keyspace = 'bndl_cassandra_test'
    table = 'test_table'

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        with cls.ctx.cassandra_session() as session:
            session.execute('''
                create keyspace if not exists {keyspace} 
                with replication = {{
                    'class': 'SimpleStrategy',
                    'replication_factor': '1'
                }};
            '''.format(keyspace=cls.keyspace))

            session.execute('''
                create table if not exists {keyspace}.{table} (
                    key text,
                    cluster text,
                    int_list list<int>,
                    double_set set<double>,
                    text_map map<text,text>,
                    timestamp_val timestamp,
                    varint_val varint,
                    primary key (key, cluster)
                );
            '''.format(keyspace=cls.keyspace, table=cls.table))


    def setUp(self):
        super().setUp()
        truncate = 'truncate {keyspace}.{table};'.format(keyspace=self.keyspace, table=self.table)
        with self.ctx.cassandra_session() as session:
            session.execute(truncate)

{'fraction_non_alphanumeric': 0.10116026105873821, 'fraction_numerical': 0.0007251631617113851, 'mean_word_length': 1.6996086105675148, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3386415', 'n_tokens_mistral': 764, 'n_tokens_neox': 714, 'n_words': 153}