<s> import os <EOL> from fake_useragent import UserAgent <EOL> from fake_useragent import settings <EOL> from fake_useragent import utils <EOL> def clear ( ) : <EOL> try : <EOL> os . unlink ( settings . DB ) <EOL> except OSError : <EOL> pass <EOL> def check_dict ( data ) : <EOL> assert data . get ( '<STR_LIT>' ) <EOL> assert data . get ( '<STR_LIT>' ) <EOL> assert data . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) <EOL> assert data . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) <EOL> assert data . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) <EOL> assert data . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) <EOL> assert data . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) <EOL> def test_get_no_args ( ) : <EOL> html = utils . get ( settings . BROWSERS_STATS_PAGE ) <EOL> assert len ( html ) > <NUM_LIT:0> <EOL> def test_get_args ( ) : <EOL> html = utils . get ( settings . BROWSER_BASE_PAGE , '<STR_LIT>' ) <EOL> assert len ( html ) > <NUM_LIT:0> <EOL> def test_get_browsers ( ) : <EOL> browsers = utils . get_browsers ( ) <EOL> browser_list = [ ] <EOL> for browser in browsers : <EOL> if browser [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> assert int ( float ( browser [ <NUM_LIT:1> ] ) ) < <NUM_LIT:20> <EOL> browser_list . append ( browser [ <NUM_LIT:0> ] ) <EOL> assert len ( browser_list ) == <NUM_LIT:5> <EOL> assert '<STR_LIT>' in browser_list <EOL> assert '<STR_LIT>' in browser_list <EOL> assert '<STR_LIT>' in browser_list <EOL> assert '<STR_LIT>' in browser_list <EOL> assert '<STR_LIT>' in browser_list <EOL> global browser_list <EOL> def test_get_browser_versions ( ) : <EOL> for browser in browser_list : <EOL> assert ( <EOL> len ( utils . get_browser_versions ( browser ) ) <EOL> == <EOL> settings . BROWSERS_COUNT_LIMIT <EOL> ) <EOL> def test_load ( ) : <EOL> fake_useragent_dict = utils . load ( ) <EOL> check_dict ( fake_useragent_dict ) <EOL> global fake_useragent_dict <EOL> def test_write ( ) : <EOL> clear ( ) <EOL> assert not os . path . isfile ( settings . DB ) <EOL> utils . write ( fake_useragent_dict ) <EOL> assert os . path . isfile ( settings . DB ) <EOL> def test_read ( ) : <EOL> data = utils . read ( ) <EOL> check_dict ( data ) <EOL> assert os . path . isfile ( settings . DB ) <EOL> def test_exists ( ) : <EOL> assert utils . exist ( ) <EOL> def test_rm ( ) : <EOL> assert utils . exist ( ) <EOL> utils . rm ( ) <EOL> assert not utils . exist ( ) <EOL> def test_update ( ) : <EOL> assert not utils . exist ( ) <EOL> utils . update ( ) <EOL> assert utils . exist ( ) <EOL> utils . update ( ) <EOL> assert utils . exist ( ) <EOL> def test_load_cached ( ) : <EOL> data = utils . load_cached ( ) <EOL> check_dict ( data ) <EOL> clear ( ) <EOL> data = utils . load_cached ( ) <EOL> check_dict ( data ) <EOL> def test_user_agent ( ) : <EOL> clear ( ) <EOL> assert not utils . exist ( ) <EOL> ua = UserAgent ( cache = False ) <EOL> assert ua . ie is not None <EOL> assert ua . msie is not None <EOL> assert ua . internetexplorer is not None <EOL> assert ua . internet_explorer is not None <EOL> assert ua [ '<STR_LIT>' ] is not None <EOL> assert ua . google is not None <EOL> assert ua . chrome is not None <EOL> assert ua . googlechrome is not None <EOL> assert ua . google_chrome is not None <EOL> assert ua [ '<STR_LIT>' ] is not None <EOL> assert ua . firefox is not None <EOL> assert ua . ff is not None <EOL> assert ua . ie is not None <EOL> assert ua . safari is not None <EOL> assert ua . random is not None <EOL> assert ua [ '<STR_LIT>' ] is not None <EOL> assert ua . non_existing is None <EOL> assert ua [ '<STR_LIT>' ] is None <EOL> data1 = ua . data <EOL> ua . update ( ) <EOL> data2 = ua . data <EOL> assert data1 == data2 <EOL> assert data1 is not data2 <EOL> clear ( ) <EOL> del ua <EOL> ua = UserAgent ( ) <EOL> assert utils . exist ( ) <EOL> data1 = ua . data <EOL> clear ( ) <EOL> ua . update ( ) <EOL> assert utils . exist ( ) <EOL> data2 = ua . data <EOL> assert data1 == data2 <EOL> assert data1 is not data2 </s>
