<commit_before>from unittest import TestCase
import time, ConfigParser
import os

from py_ms_cognitive import PyMsCognitiveWebSearch
from py_ms_cognitive import PyMsCognitiveImageSearch
from py_ms_cognitive import PyMsCognitiveVideoSearch
from py_ms_cognitive import PyMsCognitiveNewsSearch


def grab_search_secret():
    config = ConfigParser.ConfigParser()
    try:
        config.readfp(open('tests/secrets.cfg'))
        secret = config.get('secret', 'search_secret')
        if secret is None:
            return os.environ.get("PY_MS_COGNITIVE_SECRET", "search_secret")
        return secret
    except IOError:
        return os.environ.get("PY_MS_COGNITIVE_SECRET", "search_secret")

def setUpModule():
    global SECRET_KEY
    SECRET_KEY = grab_search_secret()
    print('Setting Up Test.')

class TestPyMsCognitiveWebSearch(TestCase):

    def tearDown(self):
        '''To not overload API calls'''
        time.sleep(0.75)

    def test_can_search(self):
        web_bing = PyMsCognitiveWebSearch(SECRET_KEY, "Python Software Foundation")
        result_one = web_bing.search(limit=50)
        self.assertTrue(len(result_one) == 50)
        self.assertTrue("python" in result_one[0].name.lower())

    def test_search_all(self):
        web_bing = PyMsCognitiveWebSearch(SECRET_KEY, "Python Software Foundation")
        result_one = web_bing.search_all(quota=60)
        self.assertTrue(len(result_one) == 60)
        self.assertTrue("python" in result_one[0].name.lower())

    def test_empty_response(self):
        '''
        This test was written before adding the handling to ensure the root cause of the error was indeed
        a query without results.

        This test is suppose to fail once the change is done.
        :return:
        '''
        non_existing_result = u'youwillmostdeffinitlynotfindthisveryweirdandlongstringopnanysitewhatsoever123'
        web_bing = PyMsCognitiveWebSearch(SECRET_KEY, non_existing_result)
        self.assertRaises(KeyError, web_bing.search)

# Image Tests
class TestPyMsCognitiveImageSearch(TestCase):

    def tearDown(self):
        '''To not overload API calls'''
        time.sleep(0.75)

    def test_can_search(self):
        web_bing = PyMsCognitiveImageSearch(SECRET_KEY, "Python Software Foundation")
        result_one = web_bing.search(limit=50)
        self.assertTrue(len(result_one) == 50)
        self.assertTrue("python" in result_one[0].name.lower())

    def test_search_all(self):
        web_bing = PyMsCognitiveImageSearch(SECRET_KEY, "Python Software Foundation")
        result_one = web_bing.search_all(quota=60)
        self.assertTrue(len(result_one) == 60)
        self.assertTrue(len(result_one) == 60)
        self.assertTrue("python" in result_one[0].name.lower())

# Video Tests
class TestPyMsCognitiveVideoSearch(TestCase):
<commit_msg>fixing the empty test to pass<commit_after>from unittest import TestCase
import time, ConfigParser
import os

from py_ms_cognitive import PyMsCognitiveWebSearch
from py_ms_cognitive import PyMsCognitiveImageSearch
from py_ms_cognitive import PyMsCognitiveVideoSearch
from py_ms_cognitive import PyMsCognitiveNewsSearch


def grab_search_secret():
    config = ConfigParser.ConfigParser()
    try:
        config.readfp(open('tests/secrets.cfg'))
        secret = config.get('secret', 'search_secret')
        if secret is None:
            return os.environ.get("PY_MS_COGNITIVE_SECRET", "search_secret")
        return secret
    except IOError:
        return os.environ.get("PY_MS_COGNITIVE_SECRET", "search_secret")

def setUpModule():
    global SECRET_KEY
    SECRET_KEY = grab_search_secret()
    print('Setting Up Test.')

class TestPyMsCognitiveWebSearch(TestCase):

    def tearDown(self):
        '''To not overload API calls'''
        time.sleep(0.75)

    def test_can_search(self):
        web_bing = PyMsCognitiveWebSearch(SECRET_KEY, "Python Software Foundation")
        result_one = web_bing.search(limit=50)
        self.assertTrue(len(result_one) == 50)
        self.assertTrue("python" in result_one[0].name.lower())

    def test_search_all(self):
        web_bing = PyMsCognitiveWebSearch(SECRET_KEY, "Python Software Foundation")
        result_one = web_bing.search_all(quota=60)
        self.assertTrue(len(result_one) == 60)
        self.assertTrue("python" in result_one[0].name.lower())

    def test_empty_response(self):
        '''
        This test checks that searching for a non-existent keyword will not error out.
        '''
        non_existing_result = u'youwillmostdeffinitlynotfindthisveryweirdandlongstringopnanysitewhatsoever123'
        web_bing = PyMsCognitiveWebSearch(SECRET_KEY, non_existing_result)
        self.assertTrue([] == web_bing.search())

# Image Tests
class TestPyMsCognitiveImageSearch(TestCase):

    def tearDown(self):
        '''To not overload API calls'''
        time.sleep(0.75)

    def test_can_search(self):
        web_bing = PyMsCognitiveImageSearch(SECRET_KEY, "Python Software Foundation")
        result_one = web_bing.search(limit=50)
        self.assertTrue(len(result_one) == 50)
        self.assertTrue("python" in result_one[0].name.lower())

    def test_search_all(self):
        web_bing = PyMsCognitiveImageSearch(SECRET_KEY, "Python Software Foundation")
        result_one = web_bing.search_all(quota=60)
        self.assertTrue(len(result_one) == 60)
        self.assertTrue(len(result_one) == 60)
        self.assertTrue("python" in result_one[0].name.lower())

# Video Tests
class TestPyMsCognitiveVideoSearch(TestCase):

{'fraction_non_alphanumeric': 0.09354722422494592, 'fraction_numerical': 0.011175198269646719, 'mean_word_length': 3.746792130025663, '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': '4096740', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1695, 'n_words': 352}