<s> from test . unit_tests . providers import common <EOL> from test . unit_tests . providers . common import ProviderTestCase <EOL> from totalimpact . providers . provider import Provider , ProviderContentMalformedError <EOL> from test . utils import http <EOL> import os <EOL> import collections <EOL> from nose . tools import assert_equals , raises <EOL> datadir = os . path . join ( os . path . split ( __file__ ) [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> SAMPLE_EXTRACT_METRICS_PAGE = os . path . join ( datadir , "<STR_LIT>" ) <EOL> SAMPLE_EXTRACT_ALIASES_PAGE = os . path . join ( datadir , "<STR_LIT>" ) <EOL> SAMPLE_EXTRACT_MEMBER_ITEMS_PAGE = os . path . join ( datadir , "<STR_LIT>" ) <EOL> SAMPLE_EXTRACT_BIBLIO_PAGE = os . path . join ( datadir , "<STR_LIT>" ) <EOL> TEST_DOI = "<STR_LIT>" <EOL> class TestWikipedia ( ProviderTestCase ) : <EOL> provider_name = "<STR_LIT>" <EOL> testitem_metrics = ( "<STR_LIT>" , TEST_DOI ) <EOL> testitem_aliases = ( "<STR_LIT>" , TEST_DOI ) <EOL> testitem_biblio = None <EOL> testitem_members = None <EOL> def setUp ( self ) : <EOL> ProviderTestCase . setUp ( self ) <EOL> def test_is_relevant_alias ( self ) : <EOL> assert_equals ( self . provider . is_relevant_alias ( self . testitem_aliases ) , True ) <EOL> def test_extract_metrics_success ( self ) : <EOL> f = open ( SAMPLE_EXTRACT_METRICS_PAGE , "<STR_LIT:r>" ) <EOL> good_page = f . read ( ) <EOL> metrics_dict = self . provider . _extract_metrics ( good_page ) <EOL> assert_equals ( metrics_dict [ "<STR_LIT>" ] , <NUM_LIT:1> ) <EOL> def test_extract_metrics_empty ( self ) : <EOL> empty_page = """<STR_LIT>""" <EOL> res = self . provider . _extract_metrics ( empty_page ) <EOL> assert_equals ( res , { } ) <EOL> @ raises ( ProviderContentMalformedError ) <EOL> def test_extract_metrics_invalid ( self ) : <EOL> incorrect_doc = """<STR_LIT>""" <EOL> self . provider . _extract_metrics ( incorrect_doc ) <EOL> @ http <EOL> def test_metrics ( self ) : <EOL> metrics_dict = self . provider . metrics ( [ self . testitem_metrics ] ) <EOL> expected = { '<STR_LIT>' : ( <NUM_LIT:1> , '<STR_LIT>' ) } <EOL> print metrics_dict <EOL> for key in expected : <EOL> assert metrics_dict [ key ] [ <NUM_LIT:0> ] >= expected [ key ] [ <NUM_LIT:0> ] , [ key , metrics_dict [ key ] , expected [ key ] ] <EOL> assert metrics_dict [ key ] [ <NUM_LIT:1> ] == expected [ key ] [ <NUM_LIT:1> ] , [ key , metrics_dict [ key ] , expected [ key ] ] </s>
