<commit_before># setup the test environment
import sys
import os
sys.path.insert(0, 'src')
sys.path.insert(0, '..%ssrc' % os.sep)
sys.path.insert(0, 'C:\\Program Files (x86)\\Google\\google_appengine\\')

# unit testing specific imports
import base64
import unittest2
from mock import patch
# from sure import expect
# from httpretty import HTTPretty, httprettified

from google.appengine.ext import testbed


class Test_Humans(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.setup_env(app_id='dcputoolchain-module-site')
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()

    def test_gen_types(self):
        class webapp2_replacement:
            class RequestHandler:
                pass
        patcher = patch(
            'humans.webapp2', webapp2_replacement)
        self.addCleanup(patcher.stop)
        patcher.start()
        import humans
        end_data = humans.gen_types()

        self.assertEqual(
            end_data,
            [{'selected': '', 'name': 'preprocessor'},
            {'selected': '', 'name': 'debugger'},
            {'selected': '', 'name': 'hardware'},
            {'selected': '', 'name': 'optimizer'}])

        end_data = humans.gen_types(selected='optimizer')

        self.assertEqual(
            end_data,
            [{'selected': '', 'name': 'preprocessor'},
            {'selected': '', 'name': 'debugger'},
            {'selected': '', 'name': 'hardware'},
            {'selected': 'selected', 'name': 'optimizer'}])

    def test_search(self):
        class webapp2_replacement:
            class RequestHandler:
                pass
        patcher = patch(
            'humans.webapp2', webapp2_replacement)
        self.addCleanup(patcher.stop)
        patcher.start()

        # patch some functions
        def get_tree(handler=None):
            return [{
                u'url': '',
                u'sha': u'7cc95910b367f08159cf207c08918ae5d4c04bb5',
                u'mode': u'100644',
                u'path': u'hmd2043.lua',
                u'type': u'blob',
                u'size': 3979}]

        patcher = patch(
            'humans.get_tree', get_tree)
        self.addCleanup(patcher.stop)
        patcher.start()

        def get_url_content(handler=None, url=None):
            return {
                'content': base64.b64encode('''
                    MODULE = {
                        Type = "Hardware",
                        Name = "HMD2043",
                        Version = "1.1",
                        SDescription = "Deprecated HMD2043 hardware device",
                        URL = "False URL"
                    };''')}
        patcher = patch(
            'dtmm_utils.get_url_content', get_url_content)
        self.addCleanup(patcher.stop)
        patcher.start()

        # run the actual tests
        import humans
        # tests with and without success. firstly, without a type specified
        end_data = humans.search(None, 'query', '')
        self.assertEqual(end_data, [])
        end_data = humans.search(None, 'hmd', '')
        self.assertEqual(
            end_data,
            [{
                u'url': '',
                u'sha': u'7cc95910b367f08159cf207c08918ae5d4c04bb5',
                u'mode': u'100644',
                u'path': u'hmd2043.lua',
                u'type': u'blob',
                u'size': 3979}])

        # secondly, without a type specified
        end_data = humans.search(None, 'query', 'hardware')
        self.assertEqual(end_data, [])
        end_data = humans.search(None, 'HMD2043')
        self.assertEqual(
            end_data,
            [{
                u'url': u'',
                u'sha': u'7cc95910b367f08159cf207c08918ae5d4c04bb5',
                u'mode': u'100644',
                u'path': u'hmd2043.lua',
                u'type': u'blob',
                u'size': 3979}])

    def test_pretty_colours(self):
        class webapp2_replacement:
            class RequestHandler:
                pass
        patcher = patch(
            'humans.webapp2', webapp2_replacement)
        self.addCleanup(patcher.stop)
        patcher.start()
        import humans
        import re
        import random

        output = humans.pretty_colours(random.randint(200, 500))

        for colour in output:
            self.assertNotEqual(re.match(
                r'rgb\(\d+?, \d+?, \d+?\)'), None)
<commit_msg>Small addition<commit_after># setup the test environment
import sys
import os
sys.path.insert(0, 'src')
sys.path.insert(0, '..%ssrc' % os.sep)
sys.path.insert(0, 'C:\\Program Files (x86)\\Google\\google_appengine\\')

# unit testing specific imports
import base64
import unittest2
from mock import patch
# from sure import expect
# from httpretty import HTTPretty, httprettified

from google.appengine.ext import testbed


class Test_Humans(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.setup_env(app_id='dcputoolchain-module-site')
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()

    def test_gen_types(self):
        class webapp2_replacement:
            class RequestHandler:
                pass
        patcher = patch(
            'humans.webapp2', webapp2_replacement)
        self.addCleanup(patcher.stop)
        patcher.start()
        import humans
        end_data = humans.gen_types()

        self.assertEqual(
            end_data,
            [{'selected': '', 'name': 'preprocessor'},
            {'selected': '', 'name': 'debugger'},
            {'selected': '', 'name': 'hardware'},
            {'selected': '', 'name': 'optimizer'}])

        end_data = humans.gen_types(selected='optimizer')

        self.assertEqual(
            end_data,
            [{'selected': '', 'name': 'preprocessor'},
            {'selected': '', 'name': 'debugger'},
            {'selected': '', 'name': 'hardware'},
            {'selected': 'selected', 'name': 'optimizer'}])

    def test_search(self):
        class webapp2_replacement:
            class RequestHandler:
                pass
        patcher = patch(
            'humans.webapp2', webapp2_replacement)
        self.addCleanup(patcher.stop)
        patcher.start()

        # patch some functions
        def get_tree(handler=None):
            return [{
                u'url': '',
                u'sha': u'7cc95910b367f08159cf207c08918ae5d4c04bb5',
                u'mode': u'100644',
                u'path': u'hmd2043.lua',
                u'type': u'blob',
                u'size': 3979}]

        patcher = patch(
            'humans.get_tree', get_tree)
        self.addCleanup(patcher.stop)
        patcher.start()

        def get_url_content(handler=None, url=None):
            return {
                'content': base64.b64encode('''
                    MODULE = {
                        Type = "Hardware",
                        Name = "HMD2043",
                        Version = "1.1",
                        SDescription = "Deprecated HMD2043 hardware device",
                        URL = "False URL"
                    };''')}
        patcher = patch(
            'dtmm_utils.get_url_content', get_url_content)
        self.addCleanup(patcher.stop)
        patcher.start()

        # run the actual tests
        import humans
        # tests with and without success. firstly, without a type specified
        end_data = humans.search(None, 'query', '')
        self.assertEqual(end_data, [])
        end_data = humans.search(None, 'hmd', '')
        self.assertEqual(
            end_data,
            [{
                u'url': '',
                u'sha': u'<KEY>',
                u'mode': u'100644',
                u'path': u'hmd2043.lua',
                u'type': u'blob',
                u'size': 3979}])

        # secondly, without a type specified
        end_data = humans.search(None, 'query', 'hardware')
        self.assertEqual(end_data, [])
        end_data = humans.search(None, 'HMD2043')
        self.assertEqual(
            end_data,
            [{
                u'url': u'',
                u'sha': u'<KEY>',
                u'mode': u'100644',
                u'path': u'hmd2043.lua',
                u'type': u'blob',
                u'size': 3979}])

    def test_pretty_colours(self):
        class webapp2_replacement:
            class RequestHandler:
                pass
        patcher = patch(
            'humans.webapp2', webapp2_replacement)
        self.addCleanup(patcher.stop)
        patcher.start()
        import humans
        import re
        import random

        output = humans.pretty_colours(random.randint(200, 500))

        for colour in output:
            self.assertNotEqual(re.match(
                r'rgb\(\d+?, \d+?, \d+?\)', colour), None)

{'fraction_non_alphanumeric': 0.12526397688118263, 'fraction_numerical': 0.030899188618428365, 'mean_word_length': 1.7424565681194757, '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': '5246783', 'n_tokens_mistral': 2853, 'n_tokens_neox': 2587, 'n_words': 520}