def test_empty_filters(): conf = Config.from_string(""" rules: - folders: '/' filters: actions: - Trash - folders: '~/' actions: - Trash """) assert conf.rules == [ Rule( folders=['/'], filters=[], actions=[Trash()], subfolders=False, system_files=False, ), Rule( folders=['~/'], filters=[], actions=[Trash()], subfolders=False, system_files=False, ) ]
def test_empty_filters(): conf = """ rules: - folders: '/' filters: actions: - trash - folders: '~/' actions: - trash """ assert Config.from_string(conf).rules == [ Rule( folders=["/"], filters=[], actions=[Trash()], subfolders=False, system_files=False, ), Rule( folders=["~/"], filters=[], actions=[Trash()], subfolders=False, system_files=False, ), ]
def test_yaml_ref(): config = """ media: &media - wav - png all_folders: &all - ~/Desktop - ~/Documents rules: - folders: *all filters: - Extension: *media - Extension: - *media - jpg - LastModified: days: 10 actions: - Echo: msg: 'Hello World' - folders: - *all - /more/more filters: actions: - Trash """ conf = Config.from_string(config) assert conf.rules == [ Rule( folders=['~/Desktop', '~/Documents'], filters=[ Extension('.wav', '.PNG'), Extension('.wav', '.PNG', 'jpg'), LastModified(days=10) ], actions=[Echo(msg='Hello World')], subfolders=False, system_files=False, ), Rule( folders=['~/Desktop', '~/Documents', '/more/more'], filters=[], actions=[Trash()], subfolders=False, system_files=False, ) ]
def test_yaml_ref(): config = """ media: &media - wav - png all_folders: &all - ~/Desktop - ~/Documents rules: - folders: *all filters: - extension: *media - extension: - *media - jpg - lastmodified: days: 10 actions: - echo: msg: 'Hello World' - folders: - *all - /more/more filters: actions: - trash """ conf = Config.from_string(config) assert conf.rules == [ Rule( folders=["~/Desktop", "~/Documents"], filters=[ Extension(".wav", ".PNG"), Extension(".wav", ".PNG", "jpg"), LastModified(days=10), ], actions=[Echo(msg="Hello World")], subfolders=False, system_files=False, ), Rule( folders=["~/Desktop", "~/Documents", "/more/more"], filters=[], actions=[Trash()], subfolders=False, system_files=False, ), ]
def test_trash(mock_trash): trash = Trash() trash.run(Path('~/this'), Path('~/this/file.tar.gz'), {}, False) mock_trash.assert_called_with(os.path.join(USER_DIR, 'this', 'file.tar.gz'))
def test_trash(mock_trash): trash = Trash() trash.run({'path': Path.home() / 'this' / 'file.tar.gz'}, False) mock_trash.assert_called_with(os.path.join(USER_DIR, 'this', 'file.tar.gz'))
def test_trash(mock_trash): trash = Trash() trash.run(path=Path.home() / "this" / "file.tar.gz", simulate=False) mock_trash.assert_called_with(os.path.join(USER_DIR, "this", "file.tar.gz"))