<commit_before>import os, sys, subprocess, shutil
import unittest
sys.path.append(os.path.realpath(os.path.join(
    os.path.dirname(os.path.realpath(__file__)), '..', 'bench')))
from vard import Client
import time

VARDLOG = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'vardlog.native')

class TestVard(unittest.TestCase):
    client = None
    processes = None

    def setUp(self):
        """Start up a cluster"""
        self.processes = []
        for i in range(3):
            port = 8000 + i
            args = [VARDLOG,
                    '-dbpath', 'db-%d' % i,
                    '-port', '%d' % port,
                    '-node', '0,localhost:9000',
                    '-node', '1,localhost:9001',
                    '-node', '2,localhost:9002',
                    '-me', '%d' % i]
            FNULL = open(os.devnull, 'w')
            proc = subprocess.Popen(args, stdout=FNULL, stderr=subprocess.STDOUT, close_fds=True)
            self.processes.append(proc)
            time.sleep(1)
        cluster = [('localhost', 8000),
                   ('localhost', 8001),
                   ('localhost', 8002)]
        host, port = Client.find_leader(cluster)
        self.client = Client(host, port)

    def tearDown(self):
        for i in range(3):
            self.processes[i].terminate()
#            shutil.rmtree('db-%d' % i)
        self.client = None
        self.processes = None

    def test_put_get(self):
       self.client.put('answer', '42')
       self.assertEqual(self.client.get('answer'), '42')

    def test_crash(self):
       self.client.put('answer', '42')
       self.client.put('plse', 'lab')
       self.client.put('average', 'joe')
       self.tearDown()
       self.setUp()
       self.assertEqual(self.client.get('answer'), '42')
       self.assertEqual(self.client.get('plse'), 'lab')
       self.assertEqual(self.client.get('average'), 'joe')
    
    def test_put_delete_get(self):
        self.client.put('answer', '42')
        self.client.delete('answer')
        self.assertEqual(self.client.get('answer'), None)


if __name__ == '__main__':
    unittest.main()

<commit_msg>Small test changes<commit_after>import os, sys, subprocess, shutil
import unittest
sys.path.append(os.path.realpath(os.path.join(
    os.path.dirname(os.path.realpath(__file__)), '..', 'bench')))
from vard import Client
import time

VARDLOG = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'vardlog.native')

class TestVard(unittest.TestCase):
    client = None
    processes = None

    def startProcesses(self):
        self.processes = []
        for i in range(3):
            port = 8000 + i
            args = [VARDLOG,
                    '-dbpath', 'db-%d' % i,
                    '-port', '%d' % port,
                    '-node', '0,localhost:9000',
                    '-node', '1,localhost:9001',
                    '-node', '2,localhost:9002',
                    '-me', '%d' % i]
            FNULL = open(os.devnull, 'w')
            proc = subprocess.Popen(args, stdout=FNULL, stderr=subprocess.STDOUT, close_fds=True)
            self.processes.append(proc)
            time.sleep(1)

    def setUp(self):
        """Start up a cluster"""
        self.startProcesses()
        cluster = [('localhost', 8000),
                   ('localhost', 8001),
                   ('localhost', 8002)]
        host, port = Client.find_leader(cluster)
        self.client = Client(host, port)

    def terminateProcesses(self):
        for i in range(3):
            self.processes[i].terminate()

    def tearDown(self):
        self.terminateProcesses()
        for i in range(3):
            shutil.rmtree('db-%d' % i)
        self.client = None
        self.processes = None

    def test_put_get(self):
       self.client.put('answer', '42')
       self.assertEqual(self.client.get('answer'), '42')

    def test_crash(self):
       self.client.put('answer', '42')
       self.client.put('plse', 'lab')
       self.client.put('average', 'joe')
       self.terminateProcesses()
       self.startProcesses()
       self.assertEqual(self.client.get('answer'), '42')
       self.assertEqual(self.client.get('plse'), 'lab')
       self.assertEqual(self.client.get('average'), 'joe')
    
    def test_put_delete_get(self):
        self.client.put('answer', '42')
        self.client.delete('answer')
        self.assertEqual(self.client.get('answer'), None)


if __name__ == '__main__':
    unittest.main()


{'fraction_non_alphanumeric': 0.15944618133095131, 'fraction_numerical': 0.019874944171505135, 'mean_word_length': 2.129979035639413, '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': '397377', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1396, 'n_words': 262}