Example #1
0
def test_task2_api2():
    '''
    Test whether entity multiplicity is handled properly
    '''
    tweets = [{'entities': {'dogs': [{'type': 'poodle'}, {'type': 'poodle'}]}}]
    assert (find_min_count_entities(tweets, ("dogs", "type"),
                                    1) == [('poodle', 2)])
Example #2
0
def test_task2_api0():
    '''
    Test whether keys and subkeys are handled properly in find_top_k_entities
    '''
    tweets = [{'entities': {'dogs': [{'type': 'poodle'}]}}]
    assert (find_min_count_entities(tweets, ("dogs", "type"),
                                    1) == [('poodle', 1)])
Example #3
0
def test_task2_api4():
    '''
    Test whether functionality works end-to-end
    '''
    tweets = [{
        'entities': {
            'hashtags': [{
                'text': '#abc'
            }]
        }
    }, {
        'entities': {
            'hashtags': [{
                'text': '#bcd'
            }]
        }
    }, {
        'entities': {
            'hashtags': [{
                'text': '#bad'
            }]
        }
    }, {
        'entities': {
            'hashtags': [{
                'text': '#bcd'
            }]
        }
    }, {
        'entities': {
            'hashtags': [{
                'text': '#abc'
            }]
        }
    }]

    assert (find_min_count_entities(tweets,
                                    ("hashtags", "text"), 1) == [('#abc', 2),
                                                                 ('#bcd', 2),
                                                                 ("#bad", 1)])
    assert (find_min_count_entities(tweets, ("hashtags", "text"),
                                    2) == [('#abc', 2), ('#bcd', 2)])
    assert find_min_count_entities(tweets, ("hashtags", "text"), 3) == []
Example #4
0
def test_task2_api1():
    '''
    Test whether upper and lower case is handled properly
    '''
    tweets = [{
        'entities': {
            'dogs': [{
                'type': 'poodle'
            }]
        }
    }, {
        'entities': {
            'dogs': [{
                'type': 'Poodle'
            }]
        }
    }]
    assert (find_min_count_entities(tweets, ("dogs", "type"),
                                    1) == [('poodle', 2)])
Example #5
0
def test_find_min_count_entities(params):
    '''
    test code for find_min_count_entities
    '''

    # fix the type of "entity_type"
    params["entity_type"] = tuple(params["entity_type"])

    # fix the type of expected
    params["expected"] = [tuple(t) for t in params["expected"]]

    recreate_msg = setup_tweets(params)

    call_str = "  analyze.find_min_count_entities(tweets, {}, {})"
    recreate_msg += call_str.format(params["entity_type"], params["min_count"])
    try:
        actual = analyze.find_min_count_entities(params["tweets"],
                                                 params["entity_type"],
                                                 params["min_count"])
    except Exception as e:
        msg = str(e) + "\n" + recreate_msg
        pytest.fail(msg)

    compare_tuple_lists(actual, params, recreate_msg)