<commit_before># coding=utf-8

import sys
sys.path.insert(0, '../')
import unittest
from lib.storage import Storage
import tempfile
import shutil


class StorageTestCase(unittest.TestCase):
    def setUp(self):
        self.path = tempfile.mktemp(prefix="storage-test-")
        self.storage = Storage(self.path, 'test')

    def tearDown(self):
        if self.path:
            shutil.os.remove(self.path)

    def test_persistent(self):
        self.storage['key'] = 'value'
        self.assertEqual(self.storage['key'], 'value')
        del(self.storage)
        self.storage2 = Storage(self.path, 'test')
        self.assertEqual(self.storage2['key'], 'value')

    def test_storage(self):
        self.storage['key'] = 'value'
        self.storage['key2'] = 'value2'
        self.assertEqual(self.storage['key'], 'value')
        self.assertEqual(self.storage['key2'], 'value2')
        self.assertEqual(len(self.storage), 2)
        self.assertTrue('key' in self.storage)
        self.storage.pop('key')
        self.assertFalse('key' in self.storage)
        self.assertEqual(len(self.storage), 1)


if __name__ == '__main__':
    unittest.main()<commit_msg>update storage's tests<commit_after># coding=utf-8

import sys
sys.path.insert(0, '../')
import unittest
from lib.storage import Storage
import tempfile
import shutil
import operator


class StorageTestCase(unittest.TestCase):
    def setUp(self):
        self.path = tempfile.mktemp(prefix="storage-test-")
        self.storage = Storage(self.path, 'test')

    def tearDown(self):
        if self.path:
            shutil.os.remove(self.path)

    def test_connect(self):
        self.assertTrue(self.storage.connect())

    def test_operation_set_get(self):
        self.storage['key'] = 'value'
        self.assertEqual(self.storage['key'], 'value')
        self.assertEqual(self.storage.get('key', ''), 'value')
        self.assertRaises(KeyError, operator.getitem, self.storage, 'non-existing-key')

    def test_operation_del(self):
        self.storage['key'] = 'value'
        del(self.storage['key'])
        self.assertRaises(KeyError, operator.getitem, self.storage, 'key')

    def test_operation_len(self):
        self.assertEqual(len(self.storage), 0)
        self.storage['key'] = 'value'
        self.assertEqual(len(self.storage), 1)
        self.storage['key2'] = 'value2'
        self.assertEqual(len(self.storage), 2)
        del(self.storage['key'])
        self.assertEqual(len(self.storage), 1)
        del(self.storage['key2'])
        self.assertEqual(len(self.storage), 0)

    def test_operation_contains(self):
        self.storage['key'] = 'value'
        self.assertTrue('key' in self.storage)
        self.assertFalse('key2' in self.storage)

    def test_operation_iter(self):
        sample = (('key', 'value'), ('key2', 'value2'), ('key3', 'value3'))
        for item in sample:
            operator.setitem(self.storage, item[0], item[1])

        for key in self.storage:
            self.assertTrue((key, self.storage[key]) in sample)

    def test_persistent(self):
        self.storage['key'] = 'value'
        self.assertEqual(self.storage['key'], 'value')
        del(self.storage)
        self.storage2 = Storage(self.path, 'test')
        self.assertEqual(self.storage2['key'], 'value')


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.15271966527196654, 'fraction_numerical': 0.008667065152420802, 'mean_word_length': 2.9940334128878283, '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': '7621287', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1024, 'n_words': 190}