<commit_before>
import threading
import unittest
from Queue import Queue


from cloudify.state import ctx, current_ctx

from cloudify.mocks import MockCloudifyContext


class TestCurrentContextAndCtxLocalProxy(unittest.TestCase):

    def test_basic(self):
        self.assertRaises(RuntimeError, current_ctx.get)
        self.assertRaises(RuntimeError, lambda: ctx.node_id)
        value = MockCloudifyContext(node_id='1')
        current_ctx.set(value)
        self.assertEqual(value, current_ctx.get())
        self.assertEqual(value.node_id, ctx.node_id)
        current_ctx.clear()
        self.assertRaises(RuntimeError, current_ctx.get)
        self.assertRaises(RuntimeError, lambda: ctx.node_id)

    def test_threads(self):
        num_iterations = 1000
        num_threads = 10
        for _ in range(num_iterations):
            queues = [Queue() for _ in range(num_threads)]

            def run(queue, value):
                try:
                    self.assertRaises(RuntimeError, current_ctx.get)
                    self.assertRaises(RuntimeError, lambda: ctx.node_id)
                    current_ctx.set(value)
                    self.assertEqual(value, current_ctx.get())
                    self.assertEqual(value.node_id, ctx.node_id)
                    current_ctx.clear()
                    self.assertRaises(RuntimeError, current_ctx.get)
                    self.assertRaises(RuntimeError, lambda: ctx.node_id)
                except Exception, e:
                    queue.put(e)
                else:
                    queue.put('ok')

            threads = []
            for index, queue in enumerate(queues):
                value = MockCloudifyContext(node_id=str(index))
                threads.append(threading.Thread(target=run,
                                                args=(queue, value)))

            for thread in threads:
                thread.start()

            for queue in queues:
                self.assertEqual('ok', queue.get())
<commit_msg>fix unit tests<commit_after>
import threading
import unittest
from Queue import Queue


from cloudify.state import ctx, current_ctx

from cloudify.mocks import MockCloudifyContext


class TestCurrentContextAndCtxLocalProxy(unittest.TestCase):

    def test_basic(self):
        self.assertRaises(RuntimeError, current_ctx.get_ctx)
        self.assertRaises(RuntimeError, lambda: ctx.node_id)
        value = MockCloudifyContext(node_id='1')
        current_ctx.set(value)
        self.assertEqual(value, current_ctx.get_ctx())
        self.assertEqual(value.node_id, ctx.node_id)
        current_ctx.clear()
        self.assertRaises(RuntimeError, current_ctx.get_ctx)
        self.assertRaises(RuntimeError, lambda: ctx.node_id)

    def test_threads(self):
        num_iterations = 1000
        num_threads = 10
        for _ in range(num_iterations):
            queues = [Queue() for _ in range(num_threads)]

            def run(queue, value):
                try:
                    self.assertRaises(RuntimeError, current_ctx.get_ctx)
                    self.assertRaises(RuntimeError, lambda: ctx.node_id)
                    current_ctx.set(value)
                    self.assertEqual(value, current_ctx.get_ctx())
                    self.assertEqual(value.node_id, ctx.node_id)
                    current_ctx.clear()
                    self.assertRaises(RuntimeError, current_ctx.get_ctx)
                    self.assertRaises(RuntimeError, lambda: ctx.node_id)
                except Exception, e:
                    queue.put(e)
                else:
                    queue.put('ok')

            threads = []
            for index, queue in enumerate(queues):
                value = MockCloudifyContext(node_id=str(index))
                threads.append(threading.Thread(target=run,
                                                args=(queue, value)))

            for thread in threads:
                thread.start()

            for queue in queues:
                self.assertEqual('ok', queue.get())

{'fraction_non_alphanumeric': 0.08480039672700224, 'fraction_numerical': 0.0034713612695264073, 'mean_word_length': 1.8834882058613296, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4123466', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1048, 'n_words': 206}