<s> import bowerstatic <EOL> from webtest import TestApp as Client <EOL> import os <EOL> import sys <EOL> import json <EOL> from datetime import datetime , timedelta <EOL> import pytest <EOL> from bowerstatic import compat <EOL> from bowerstatic import filesystem_microsecond_autoversion <EOL> def test_local_falls_back_to_components ( ) : <EOL> bower = bowerstatic . Bower ( ) <EOL> components = bower . components ( '<STR_LIT>' , os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> local = bower . local_components ( '<STR_LIT>' , components ) <EOL> def wsgi ( environ , start_response ) : <EOL> start_response ( '<STR_LIT>' , [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> include = local . includer ( environ ) <EOL> include ( '<STR_LIT>' ) <EOL> return [ b'<STR_LIT>' ] <EOL> wrapped = bower . wrap ( wsgi ) <EOL> c = Client ( wrapped ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> assert response . body == ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) <EOL> response = c . get ( '<STR_LIT>' ) <EOL> assert response . body == b'<STR_LIT>' <EOL> def test_local_with_local_component_main ( ) : <EOL> bower = bowerstatic . Bower ( ) <EOL> components = bower . components ( '<STR_LIT>' , os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> local = bower . local_components ( '<STR_LIT>' , components ) <EOL> path = os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> local . component ( path , version = '<STR_LIT>' ) <EOL> def wsgi ( environ , start_response ) : <EOL> start_response ( '<STR_LIT>' , [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> include = local . includer ( environ ) <EOL> include ( '<STR_LIT>' ) <EOL> return [ b'<STR_LIT>' ] <EOL> wrapped = bower . wrap ( wsgi ) <EOL> c = Client ( wrapped ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> assert response . body == ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) <EOL> response = c . get ( '<STR_LIT>' ) <EOL> assert response . body == b'<STR_LIT>' <EOL> def test_local_with_local_component_specific_file ( ) : <EOL> bower = bowerstatic . Bower ( ) <EOL> components = bower . components ( '<STR_LIT>' , os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> local = bower . local_components ( '<STR_LIT>' , components ) <EOL> path = os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> local . component ( path , version = '<STR_LIT>' ) <EOL> def wsgi ( environ , start_response ) : <EOL> start_response ( '<STR_LIT>' , [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> include = local . includer ( environ ) <EOL> include ( '<STR_LIT>' ) <EOL> return [ b'<STR_LIT>' ] <EOL> wrapped = bower . wrap ( wsgi ) <EOL> c = Client ( wrapped ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> assert response . body == ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) <EOL> response = c . get ( '<STR_LIT>' ) <EOL> assert response . body == b'<STR_LIT>' <EOL> def test_local_internal_dependencies ( ) : <EOL> bower = bowerstatic . Bower ( ) <EOL> components = bower . components ( '<STR_LIT>' , os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> local = bower . local_components ( '<STR_LIT>' , components ) <EOL> path = os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> local . component ( path , version = '<STR_LIT>' ) <EOL> local . resource ( '<STR_LIT>' , dependencies = [ <EOL> '<STR_LIT>' ] ) <EOL> def wsgi ( environ , start_response ) : <EOL> start_response ( '<STR_LIT>' , [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> include = local . includer ( environ ) <EOL> include ( '<STR_LIT>' ) <EOL> return [ b'<STR_LIT>' ] <EOL> wrapped = bower . wrap ( wsgi ) <EOL> c = Client ( wrapped ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> assert response . body == ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) <EOL> def test_local_external_dependencies ( ) : <EOL> bower = bowerstatic . Bower ( ) <EOL> components = bower . components ( '<STR_LIT>' , os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> local = bower . local_components ( '<STR_LIT>' , components ) <EOL> path = os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> local . component ( path , version = '<STR_LIT>' ) <EOL> local . resource ( '<STR_LIT>' , dependencies = [ <EOL> '<STR_LIT>' ] ) <EOL> def wsgi ( environ , start_response ) : <EOL> start_response ( '<STR_LIT>' , [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> include = local . includer ( environ ) <EOL> include ( '<STR_LIT>' ) <EOL> return [ b'<STR_LIT>' ] <EOL> wrapped = bower . wrap ( wsgi ) <EOL> c = Client ( wrapped ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> assert response . body == ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) <EOL> def test_local_bower_json_dependencies ( ) : <EOL> bower = bowerstatic . Bower ( ) <EOL> components = bower . components ( '<STR_LIT>' , os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> local = bower . local_components ( '<STR_LIT>' , components ) <EOL> path = os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> local . component ( path , version = '<STR_LIT>' ) <EOL> def wsgi ( environ , start_response ) : <EOL> start_response ( '<STR_LIT>' , [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> include = local . includer ( environ ) <EOL> include ( '<STR_LIT>' ) <EOL> return [ b'<STR_LIT>' ] <EOL> wrapped = bower . wrap ( wsgi ) <EOL> c = Client ( wrapped ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> assert response . body == ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) <EOL> def test_local_with_missing_version ( ) : <EOL> bower = bowerstatic . Bower ( ) <EOL> components = bower . components ( '<STR_LIT>' , os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> local = bower . local_components ( '<STR_LIT>' , components ) <EOL> path = os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> with pytest . raises ( ValueError ) as err : <EOL> local . component ( path , version = None ) <EOL> assert str ( err . value ) . startswith ( '<STR_LIT>' ) <EOL> assert str ( err . value ) . endswith ( '<STR_LIT>' ) <EOL> @ pytest . mark . skipif ( <EOL> sys . platform == '<STR_LIT>' , <EOL> reason = "<STR_LIT>" ) <EOL> def test_local_with_microsecond_auto_version ( tmpdir ) : <EOL> after_dt = datetime . now ( ) - timedelta ( seconds = <NUM_LIT:1> ) <EOL> component_dir = tmpdir . mkdir ( '<STR_LIT>' ) <EOL> bower_json_file = component_dir . join ( '<STR_LIT>' ) <EOL> bower_json_file . write ( json . dumps ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) ) <EOL> main_js_file = component_dir . join ( '<STR_LIT>' ) <EOL> main_js_file . write ( '<STR_LIT>' ) <EOL> bower = bowerstatic . Bower ( autoversion = filesystem_microsecond_autoversion ) <EOL> components = bower . components ( '<STR_LIT>' , os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> local = bower . local_components ( '<STR_LIT>' , components ) <EOL> local . component ( component_dir . strpath , version = None ) <EOL> def wsgi ( environ , start_response ) : <EOL> start_response ( '<STR_LIT>' , [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> include = local . includer ( environ ) <EOL> include ( '<STR_LIT>' ) <EOL> return [ b'<STR_LIT>' ] <EOL> wrapped = bower . wrap ( wsgi ) <EOL> c = Client ( wrapped ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> before_dt = datetime . now ( ) <EOL> def get_url_dt ( response ) : <EOL> s = compat . text_type ( response . body , '<STR_LIT>' ) <EOL> start = s . find ( '<STR_LIT>' ) + len ( '<STR_LIT>' ) <EOL> end = s . find ( '<STR_LIT:">' , start ) <EOL> url = s [ start : end ] <EOL> parts = url . split ( '<STR_LIT:/>' ) <EOL> url_dt_str = parts [ <NUM_LIT:4> ] <EOL> url_dt = datetime . strptime ( url_dt_str , '<STR_LIT>' ) <EOL> return url_dt_str , url_dt <EOL> url_dt_str , url_dt = get_url_dt ( response ) <EOL> assert url_dt >= after_dt <EOL> assert url_dt <= before_dt <EOL> response = c . get ( '<STR_LIT>' % url_dt_str ) <EOL> assert response . body == b'<STR_LIT>' <EOL> after_dt = datetime . now ( ) - timedelta ( seconds = <NUM_LIT:1> ) <EOL> main_js_file . write ( '<STR_LIT>' ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> before_dt = datetime . now ( ) <EOL> original_url_dt_str , original_url_dt = url_dt_str , url_dt <EOL> url_dt_str , url_dt = get_url_dt ( response ) <EOL> assert original_url_dt_str != url_dt_str <EOL> assert url_dt >= after_dt <EOL> assert url_dt <= before_dt <EOL> assert url_dt > original_url_dt <EOL> c . get ( '<STR_LIT>' % original_url_dt_str , <EOL> status = <NUM_LIT> ) <EOL> response = c . get ( '<STR_LIT>' % <EOL> url_dt_str ) <EOL> assert response . body == b'<STR_LIT>' <EOL> def test_local_with_second_auto_version ( tmpdir ) : <EOL> after_dt = datetime . now ( ) - timedelta ( seconds = <NUM_LIT:1> ) <EOL> component_dir = tmpdir . mkdir ( '<STR_LIT>' ) <EOL> bower_json_file = component_dir . join ( '<STR_LIT>' ) <EOL> bower_json_file . write ( json . dumps ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) ) <EOL> main_js_file = component_dir . join ( '<STR_LIT>' ) <EOL> main_js_file . write ( '<STR_LIT>' ) <EOL> bower = bowerstatic . Bower ( ) <EOL> components = bower . components ( '<STR_LIT>' , os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> local = bower . local_components ( '<STR_LIT>' , components ) <EOL> local . component ( component_dir . strpath , version = None ) <EOL> def wsgi ( environ , start_response ) : <EOL> start_response ( '<STR_LIT>' , [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] ) <EOL> include = local . includer ( environ ) <EOL> include ( '<STR_LIT>' ) <EOL> return [ b'<STR_LIT>' ] <EOL> wrapped = bower . wrap ( wsgi ) <EOL> c = Client ( wrapped ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> before_dt = datetime . now ( ) <EOL> def get_url_dt ( response ) : <EOL> s = compat . text_type ( response . body , '<STR_LIT>' ) <EOL> start = s . find ( '<STR_LIT>' ) + len ( '<STR_LIT>' ) <EOL> end = s . find ( '<STR_LIT:">' , start ) <EOL> url = s [ start : end ] <EOL> parts = url . split ( '<STR_LIT:/>' ) <EOL> url_dt_str = parts [ <NUM_LIT:4> ] <EOL> url_dt = datetime . strptime ( url_dt_str , '<STR_LIT>' ) <EOL> return url_dt_str , url_dt <EOL> url_dt_str , url_dt = get_url_dt ( response ) <EOL> assert url_dt >= after_dt <EOL> assert url_dt <= before_dt <EOL> response = c . get ( '<STR_LIT>' % url_dt_str ) <EOL> assert response . body == b'<STR_LIT>' <EOL> after_dt = datetime . now ( ) - timedelta ( seconds = <NUM_LIT:1> ) <EOL> main_js_file . write ( '<STR_LIT>' ) <EOL> response = c . get ( '<STR_LIT:/>' ) <EOL> before_dt = datetime . now ( ) <EOL> original_url_dt = url_dt <EOL> url_dt_str , url_dt = get_url_dt ( response ) <EOL> assert url_dt >= after_dt <EOL> assert url_dt <= before_dt <EOL> assert url_dt >= original_url_dt <EOL> response = c . get ( '<STR_LIT>' % <EOL> url_dt_str ) <EOL> assert response . body == b'<STR_LIT>' </s>
