<s> from __future__ import unicode_literals <EOL> from nose_parameterized import parameterized , param <EOL> from datetime import datetime , tzinfo <EOL> from tests import BaseTestCase <EOL> from dateparser . conf import settings <EOL> from dateparser . conf import apply_settings <EOL> from dateparser import parse <EOL> def test_function ( settings = None ) : <EOL> return settings <EOL> class TimeZoneSettingsTest ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TimeZoneSettingsTest , self ) . setUp ( ) <EOL> self . given_ds = NotImplemented <EOL> self . result = NotImplemented <EOL> self . timezone = NotImplemented <EOL> self . confs = NotImplemented <EOL> @ parameterized . expand ( [ <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:30> ) ) , <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:30> ) ) , <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:15> , <NUM_LIT:30> ) ) , <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:30> ) ) , <EOL> ] ) <EOL> def test_should_return_tz_aware_dates ( self , ds , dt ) : <EOL> self . given ( ds ) <EOL> self . given_configurations ( { '<STR_LIT>' : True } ) <EOL> self . when_date_is_parsed ( ) <EOL> self . then_date_is_tz_aware ( ) <EOL> self . then_date_is ( dt ) <EOL> @ parameterized . expand ( [ <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT:30> ) , '<STR_LIT>' ) , <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:20> , <NUM_LIT:30> ) , '<STR_LIT>' ) , <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:20> , <NUM_LIT:30> ) , '<STR_LIT>' ) , <EOL> ] ) <EOL> def test_should_return_and_assert_tz ( self , ds , dt , tz ) : <EOL> self . given ( ds ) <EOL> self . given_configurations ( { '<STR_LIT>' : True , '<STR_LIT>' : tz } ) <EOL> self . when_date_is_parsed ( ) <EOL> self . then_date_is_tz_aware ( ) <EOL> self . then_date_is ( dt ) <EOL> self . then_timezone_is ( tz ) <EOL> @ parameterized . expand ( [ <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT:30> ) , None ) , <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT:30> ) , '<STR_LIT>' ) , <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:20> , <NUM_LIT:30> ) , '<STR_LIT>' ) , <EOL> param ( '<STR_LIT>' , datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:20> , <NUM_LIT:30> ) , '<STR_LIT>' ) , <EOL> ] ) <EOL> def test_only_return_explicit_timezone ( self , ds , dt , tz ) : <EOL> self . given ( ds ) <EOL> self . given_configurations ( { '<STR_LIT>' : True , '<STR_LIT>' : None } ) <EOL> self . when_date_is_parsed ( ) <EOL> self . then_date_is ( dt ) <EOL> if tz : <EOL> self . then_date_is_tz_aware ( ) <EOL> self . then_timezone_is ( tz ) <EOL> else : <EOL> self . then_date_is_not_tz_aware ( ) <EOL> def then_timezone_is ( self , tzname ) : <EOL> self . assertEqual ( self . result . tzinfo . tzname ( '<STR_LIT>' ) , tzname ) <EOL> def given ( self , ds ) : <EOL> self . given_ds = ds <EOL> def given_configurations ( self , confs ) : <EOL> self . confs = confs <EOL> def when_date_is_parsed ( self ) : <EOL> self . result = parse ( self . given_ds , settings = ( self . confs or { } ) ) <EOL> def then_date_is_tz_aware ( self ) : <EOL> self . assertIsInstance ( self . result . tzinfo , tzinfo ) <EOL> def then_date_is_not_tz_aware ( self ) : <EOL> self . assertIsNone ( self . result . tzinfo ) <EOL> def then_date_is ( self , date ) : <EOL> dtc = self . result . replace ( tzinfo = None ) <EOL> self . assertEqual ( dtc , date ) <EOL> class SettingsTest ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SettingsTest , self ) . setUp ( ) <EOL> self . default_settings = settings <EOL> def test_apply_settings_should_return_default_settings_when_no_settings_are_supplied_to_the_decorated_function ( self ) : <EOL> test_func = apply_settings ( test_function ) <EOL> self . assertEqual ( test_func ( ) , self . default_settings ) <EOL> def test_apply_settings_should_return_non_default_settings_when_settings_are_supplied_to_the_decorated_function ( self ) : <EOL> test_func = apply_settings ( test_function ) <EOL> self . assertNotEqual ( test_func ( settings = { '<STR_LIT>' : '<STR_LIT>' } ) , self . default_settings ) <EOL> def test_apply_settings_should_not_create_new_settings_when_same_settings_are_supplied_to_the_decorated_function_more_than_once ( self ) : <EOL> test_func = apply_settings ( test_function ) <EOL> settings_once = test_func ( settings = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> settings_twice = test_func ( settings = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( settings_once , settings_twice ) <EOL> def test_apply_settings_should_return_default_settings_when_called_with_no_settings_after_once_called_with_settings_supplied_to_the_decorated_function ( self ) : <EOL> test_func = apply_settings ( test_function ) <EOL> settings_once = test_func ( settings = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> settings_twice = test_func ( ) <EOL> self . assertNotEqual ( settings_once , self . default_settings ) <EOL> self . assertEqual ( settings_twice , self . default_settings ) </s>
