<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007-2008 <NAME>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.

import shutil
import os
import tempfile
import unittest
from couchdb import ResourceConflict, ResourceNotFound, Server


class CouchTests(unittest.TestCase):

    def setUp(self):
        uri = os.environ.get('COUCHDB_URI', 'http://localhost:5984/')
        self.cache_dir = tempfile.mkdtemp(prefix='couchdb')
        self.server = Server(uri, cache=self.cache_dir)
        try:
            self.server.delete('python-tests')
        except client.ResourceNotFound:
            pass
        self.db = self.server.create('python-tests')

    def tearDown(self):
        try:
            self.server.delete('python-tests')
        except client.ResourceNotFound:
            pass
        shutil.rmtree(self.cache_dir)

    def _create_test_docs(self, num):
        for i in range(num):
            self.db[str(i)] = {'a': i + 1, 'b': (i + 1) ** 2}

    def test_basics(self):
        self.assertEqual(0, len(self.db))

        # create a document
        data = {'a': 1, 'b': 1}
        self.db['0'] = data
        self.assertEqual('0', data['_id'])
        assert '_rev' in data
        doc = self.db['0']
        self.assertEqual('0', doc.id)
        self.assertEqual(data['_rev'], doc.rev)
        self.assertEqual(1, len(self.db))

        # delete a document
        del self.db['0']
        self.assertRaises(ResourceNotFound, self.db.__getitem__, '0')<commit_msg>Fix a couple of unit tests.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007-2008 <NAME>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.

import shutil
import os
import tempfile
import unittest
from couchdb import ResourceConflict, ResourceNotFound, Server


class CouchTests(unittest.TestCase):

    def setUp(self):
        uri = os.environ.get('COUCHDB_URI', 'http://localhost:5984/')
        self.cache_dir = tempfile.mkdtemp(prefix='couchdb')
        self.server = Server(uri, cache=self.cache_dir)
        try:
            self.server.delete('python-tests')
        except ResourceNotFound:
            pass
        self.db = self.server.create('python-tests')

    def tearDown(self):
        try:
            self.server.delete('python-tests')
        except ResourceNotFound:
            pass
        shutil.rmtree(self.cache_dir)

    def _create_test_docs(self, num):
        for i in range(num):
            self.db[str(i)] = {'a': i + 1, 'b': (i + 1) ** 2}

    def test_basics(self):
        self.assertEqual(0, len(self.db))

        # create a document
        data = {'a': 1, 'b': 1}
        self.db['0'] = data
        self.assertEqual('0', data['_id'])
        assert '_rev' in data
        doc = self.db['0']
        self.assertEqual('0', doc.id)
        self.assertEqual(data['_rev'], doc.rev)
        self.assertEqual(1, len(self.db))

        # delete a document
        del self.db['0']
        self.assertRaises(ResourceNotFound, self.db.__getitem__, '0')
{'fraction_non_alphanumeric': 0.13405572755417958, 'fraction_numerical': 0.01609907120743034, 'mean_word_length': 2.463022508038585, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3488700', 'n_tokens_mistral': 1034, 'n_tokens_neox': 989, 'n_words': 250}