<commit_before>import unittest
import tunldb
import time
import itertools
import threading
import os

PERSIST_PATH = 'test.db'

class TestTunlDB(unittest.TestCase):
    def setUp(self):
        self.db = tunldb.TunlDB()

    def test_set(self):
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        self.db.remove('key')

    def test_get(self):
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        self.db.remove('key')

    def test_remove(self):
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        self.db.remove('key')
        self.assertIsNone(self.db.get('key'))

    def test_exists(self):
        self.assertFalse(self.db.exists('key'))
        self.db.set('key', 'val')
        self.assertTrue(self.db.exists('key'))
        self.db.remove('key')

    def test_rename(self):
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        self.db.rename('key', 'key2')
        self.assertIsNone(self.db.get('key'))
        self.assertEqual(self.db.get('key2'), 'val')

    def test_expire(self):
        self.db.expire('key', 1)
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        time.sleep(1.0001)
        self.assertIsNone(self.db.get('key'))

    def test_increment(self):
        self.db.increment('key')
        self.assertEqual(self.db.get('key'), '1')
        self.db.increment('key')
        self.assertEqual(self.db.get('key'), '2')
        self.db.remove('key')

    def test_decrement(self):
        self.db.decrement('key')
        self.assertEqual(self.db.get('key'), '-1')
        self.db.decrement('key')
        self.assertEqual(self.db.get('key'), '-2')
        self.db.remove('key')

    def test_keys(self):
        self.db.set('key1', 'val1')
        self.db.set('key2', 'val2')
        self.assertEqual(self.db.keys(), {'key1', 'key2'})
        self.db.remove('key1')
        self.db.remove('key2')

    def test_set_add(self):
        self.db.set_add('key', 'val')
        self.assertEqual(self.db.set_elements('key'), {'val'})
        self.db.remove('key')

    def test_set_remove(self):
        self.db.set_add('key', 'val')
        self.assertEqual(self.db.set_elements('key'), {'val'})
        self.db.set_remove('key', 'val')
        self.assertEqual(self.db.set_elements('key'), set())
        self.db.remove('key')

    def test_set_exists(self):
        self.db.set_add('key', 'val')
        self.assertTrue(self.db.set_exists('key', 'val'))
        self.db.set_remove('key', 'val')
        self.assertFalse(self.db.set_exists('key', 'val'))
        self.db.remove('key')

    def test_set_elements(self):
        self.db.set_add('key', 'val1')
        self.db.set_add('key', 'val2')
        self.assertEqual(self.db.set_elements('key'), {'val1', 'val2'})
        self.db.remove('key')

    def test_set_length(self):
        self.db.set_add('key', 'val')
        self.assertEqual(self.db.set_length('key'), 1)
        self.db.set_remove('key', 'val')
        self.assertEqual(self.db.set_length('key'), 0)
        self.db.remove('key')

    def test_list_lpush(self):
        self.db.list_lpush('key', 'val1')
        self.db.list_lpush('key', 'val2')
        self.assertEqual(self.db.list_elements('key'), ['val2', 'val1'])
        self.db.remove('key')

    def test_list_rpush(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_elements('key'), ['val1', 'val2'])
        self.db.remove('key')

    def test_list_lpop(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_lpop('key'), 'val1')
        self.assertEqual(self.db.list_elements('key'), ['val2'])
        self.db.remove('key')

    def test_list_rpop(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_rpop('key'), 'val2')
        self.assertEqual(self.db.list_elements('key'), ['val1'])
        self.db.remove('key')

    def test_list_index(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_index('key', 0), 'val1')
        self.assertEqual(self.db.list_index('key', 1), 'val2')
        self.db.remove('key')

    def test_list_elements(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_elements('key'), ['val1', 'val2'])
        self.db.remove('key')

    def test_list_iter(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertTrue(all([x == y for x, y in itertools.izip(
            ['val1', 'val2'], self.db.list_iter('key'))]))
        self.db.remove('key')

    def test_list_iter_range(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.db.list_rpush('key', 'val3')
        self.assertTrue(all([x == y for x, y in itertools.izip(
            ['val2', 'val3'], self.db.list_iter_range('key', 1, 2))]))<commit_msg>Fix list iter range unittest<commit_after>import unittest
import tunldb
import time
import itertools
import threading
import os

PERSIST_PATH = 'test.db'

class TestTunlDB(unittest.TestCase):
    def setUp(self):
        self.db = tunldb.TunlDB()

    def test_set(self):
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        self.db.remove('key')

    def test_get(self):
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        self.db.remove('key')

    def test_remove(self):
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        self.db.remove('key')
        self.assertIsNone(self.db.get('key'))

    def test_exists(self):
        self.assertFalse(self.db.exists('key'))
        self.db.set('key', 'val')
        self.assertTrue(self.db.exists('key'))
        self.db.remove('key')

    def test_rename(self):
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        self.db.rename('key', 'key2')
        self.assertIsNone(self.db.get('key'))
        self.assertEqual(self.db.get('key2'), 'val')

    def test_expire(self):
        self.db.expire('key', 1)
        self.db.set('key', 'val')
        self.assertEqual(self.db.get('key'), 'val')
        time.sleep(1.0001)
        self.assertIsNone(self.db.get('key'))

    def test_increment(self):
        self.db.increment('key')
        self.assertEqual(self.db.get('key'), '1')
        self.db.increment('key')
        self.assertEqual(self.db.get('key'), '2')
        self.db.remove('key')

    def test_decrement(self):
        self.db.decrement('key')
        self.assertEqual(self.db.get('key'), '-1')
        self.db.decrement('key')
        self.assertEqual(self.db.get('key'), '-2')
        self.db.remove('key')

    def test_keys(self):
        self.db.set('key1', 'val1')
        self.db.set('key2', 'val2')
        self.assertEqual(self.db.keys(), {'key1', 'key2'})
        self.db.remove('key1')
        self.db.remove('key2')

    def test_set_add(self):
        self.db.set_add('key', 'val')
        self.assertEqual(self.db.set_elements('key'), {'val'})
        self.db.remove('key')

    def test_set_remove(self):
        self.db.set_add('key', 'val')
        self.assertEqual(self.db.set_elements('key'), {'val'})
        self.db.set_remove('key', 'val')
        self.assertEqual(self.db.set_elements('key'), set())
        self.db.remove('key')

    def test_set_exists(self):
        self.db.set_add('key', 'val')
        self.assertTrue(self.db.set_exists('key', 'val'))
        self.db.set_remove('key', 'val')
        self.assertFalse(self.db.set_exists('key', 'val'))
        self.db.remove('key')

    def test_set_elements(self):
        self.db.set_add('key', 'val1')
        self.db.set_add('key', 'val2')
        self.assertEqual(self.db.set_elements('key'), {'val1', 'val2'})
        self.db.remove('key')

    def test_set_length(self):
        self.db.set_add('key', 'val')
        self.assertEqual(self.db.set_length('key'), 1)
        self.db.set_remove('key', 'val')
        self.assertEqual(self.db.set_length('key'), 0)
        self.db.remove('key')

    def test_list_lpush(self):
        self.db.list_lpush('key', 'val1')
        self.db.list_lpush('key', 'val2')
        self.assertEqual(self.db.list_elements('key'), ['val2', 'val1'])
        self.db.remove('key')

    def test_list_rpush(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_elements('key'), ['val1', 'val2'])
        self.db.remove('key')

    def test_list_lpop(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_lpop('key'), 'val1')
        self.assertEqual(self.db.list_elements('key'), ['val2'])
        self.db.remove('key')

    def test_list_rpop(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_rpop('key'), 'val2')
        self.assertEqual(self.db.list_elements('key'), ['val1'])
        self.db.remove('key')

    def test_list_index(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_index('key', 0), 'val1')
        self.assertEqual(self.db.list_index('key', 1), 'val2')
        self.db.remove('key')

    def test_list_elements(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertEqual(self.db.list_elements('key'), ['val1', 'val2'])
        self.db.remove('key')

    def test_list_iter(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.assertTrue(all([x == y for x, y in itertools.izip(
            ['val1', 'val2'], self.db.list_iter('key'))]))
        self.db.remove('key')

    def test_list_iter_range(self):
        self.db.list_rpush('key', 'val1')
        self.db.list_rpush('key', 'val2')
        self.db.list_rpush('key', 'val3')
        self.assertTrue(all([x == y for x, y in itertools.izip(
            ['val2', 'val3'], self.db.list_iter_range('key', 1, 3))]))
{'fraction_non_alphanumeric': 0.1956958393113343, 'fraction_numerical': 0.01205164992826399, 'mean_word_length': 2.714387211367673, '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': '6836703', 'n_tokens_mistral': 3764, 'n_tokens_neox': 3717, 'n_words': 505}