def __init__(self): # The default folder path is along the lines of 2017-06-17_01-04-14-dsc_1234-some-title.jpg self.default_file_name_definition = { 'date': '%Y-%m-%d_%H-%M-%S', 'name': '%date-%original_name-%title.%extension', } # The default folder path is along the lines of 2015-01-Jan/Chicago self.default_folder_path_definition = { 'date': '%Y-%m-%b', 'location': '%city', 'full_path': '%date/%album|%location|"{}"'.format( geolocation.__DEFAULT_LOCATION__), } self.cached_file_name_definition = None self.cached_folder_path_definition = None # Python3 treats the regex \s differently than Python2. # It captures some additional characters like the unicode checkmark \u2713. # See build failures in Python3 here. # https://travis-ci.org/jmathai/elodie/builds/483012902 self.whitespace_regex = '[ \t\n\r\f\v]+' # Instantiate a plugins object self.plugins = Plugins()
def test_load_plugins_unset_backwards_compat(): with open( '%s/config.ini-load-plugins-unset-backwards-compat' % gettempdir(), 'w') as f: f.write(""" """) if hasattr(load_config, 'config'): del load_config.config plugins = Plugins() plugins.load() if hasattr(load_config, 'config'): del load_config.config assert plugins.plugins == [], plugins.plugins
def test_load_plugins_exists_not_set(): with open('%s/config.ini-load-plugins-exists-not-set' % gettempdir(), 'w') as f: f.write(""" [Plugins] """) if hasattr(load_config, 'config'): del load_config.config plugins = Plugins() plugins.load() if hasattr(load_config, 'config'): del load_config.config assert plugins.plugins == [], plugins.plugins
def test_load_plugins_one_with_invalid(): with open('%s/config.ini-load-plugins-one' % gettempdir(), 'w') as f: f.write(""" [Plugins] plugins=DNE """) if hasattr(load_config, 'config'): del load_config.config plugins = Plugins() plugins.load() if hasattr(load_config, 'config'): del load_config.config assert plugins.plugins == [], plugins.plugins assert len(plugins.classes) == 0, len(plugins.classes)
def test_load_plugins_set_many_with_invalid(): with open('%s/config.ini-load-plugins-many-with-invalid' % gettempdir(), 'w') as f: f.write(""" [Plugins] plugins=ThrowError,Dummy,DNE """) if hasattr(load_config, 'config'): del load_config.config plugins = Plugins() plugins.load() if hasattr(load_config, 'config'): del load_config.config assert plugins.plugins == ['ThrowError', 'Dummy'], plugins.plugins
def test_run_before(): with open('%s/config.ini-run-before' % gettempdir(), 'w') as f: f.write(""" [Plugins] plugins=Dummy """) if hasattr(load_config, 'config'): del load_config.config plugins = Plugins() plugins.load() before_ran_1 = plugins.classes['Dummy'].before_ran plugins.run_all_before('', '') before_ran_2 = plugins.classes['Dummy'].before_ran if hasattr(load_config, 'config'): del load_config.config assert before_ran_1 == False, before_ran_1 assert before_ran_2 == True, before_ran_2
def test_throw_error_runtime_error(): with open('%s/config.ini-throw-runtime-error' % gettempdir(), 'w') as f: f.write(""" [Plugins] plugins=RuntimeError """) if hasattr(load_config, 'config'): del load_config.config plugins = Plugins() plugins.load() status_after = plugins.run_all_after('', '', '', '') status_batch = plugins.run_batch() status_before = plugins.run_all_before('', '') if hasattr(load_config, 'config'): del load_config.config assert status_after == True, status_after assert status_batch == True, status_batch assert status_before == True, status_before
def test_throw_error_one_of_many(): with open('%s/config.ini-throw-error-one-of-many' % gettempdir(), 'w') as f: f.write(""" [Plugins] plugins=Dummy,ThrowError """) if hasattr(load_config, 'config'): del load_config.config plugins = Plugins() plugins.load() status_after = plugins.run_all_after('', '', '', '') status_batch = plugins.run_batch() status_before = plugins.run_all_before('', '') if hasattr(load_config, 'config'): del load_config.config assert status_after == False, status_after assert status_batch == False, status_batch assert status_before == False, status_before
def test_load_plugins_many(): with open('%s/config.ini-load-plugins-many' % gettempdir(), 'w') as f: f.write(""" [Plugins] plugins=ThrowError,Dummy """) if hasattr(load_config, 'config'): del load_config.config plugins = Plugins() plugins.load() if hasattr(load_config, 'config'): del load_config.config assert plugins.plugins == ['ThrowError', 'Dummy'], plugins.plugins assert plugins.classes[ 'ThrowError'].__name__ == 'ThrowError', plugins.classes[ 'ThrowError'].__name__ assert plugins.classes['Dummy'].__name__ == 'Dummy', plugins.classes[ 'Dummy'].__name__ assert len(plugins.classes) == 2, len(plugins.classes)
def _batch(debug): """Run batch() for all plugins. """ constants.debug = debug plugins = Plugins() plugins.run_batch()
def __init__(self): self.destination_folder = DestinationFolder() # Instantiate a plugins object self.plugins = Plugins()