def test_find_files(): """ Test calling function for collecting all files in a folder. """ target = 'testpath' find_file = patch('bear.__main__.find_files') sysargv = patch('sys.argv', [__name__, '--traverse', target]) with sysargv, find_file as mocked: run() mocked.assert_called_once_with(target)
def test_hash_file(): """ Test calling hashing function for a file. """ target = 'testpath' hash_file = patch('bear.__main__.hash_file') sysargv = patch('sys.argv', [__name__, '--files', target]) with sysargv, hash_file as mocked: run() mocked.assert_called_once_with(target)
def test_find_files(): """ Test calling function for collecting all files in a folder. """ target = 'testpath' context = Context( Namespace(traverse=[target], files=[], hash=[], duplicates=[])) ctx = patch("bear.__main__.Context", return_value=context) find_file = patch('bear.__main__.find_files') sysargv = patch('sys.argv', [__name__, '--traverse', target]) with sysargv, ctx, find_file as mocked: run() mocked.assert_called_once_with(ctx=context, folder=target)
def test_hash_folder(self): """ Test collecting all files in a folder and calling hashing function on them. """ target = 'testpath' sysv = patch('sys.argv', [__name__, '--hash', target]) hfile = patch('bear.__main__.hash_files') ffile_ret = [None] ffile = patch('bear.__main__.find_files', return_value=ffile_ret) fhash = patch('bear.__main__.filter_files') with sysv, hfile as m_hash, ffile as m_find, fhash as m_filter: run() m_find.assert_called_once_with(target) m_hash.assert_called_once_with(m_find.return_value) self.assertEqual(m_find.return_value, ffile_ret) m_filter.assert_called_once_with(m_hash.return_value)
def test_hash_folder(self): """ Test collecting all files in a folder and calling hashing function on them. """ target = 'testpath' context = Context( Namespace(hash=[target], traverse=[], files=[], duplicates=[])) ctx = patch("bear.__main__.Context", return_value=context) sysv = patch('sys.argv', [__name__, '--hash', target]) hfile = patch('bear.__main__.hash_files') ffile_ret = [None] ffile = patch('bear.__main__.find_files', return_value=ffile_ret) fhash = patch('bear.__main__.filter_files') with sysv, ctx, hfile as m_hash, ffile as m_find, fhash as m_filter: run() m_find.assert_called_once_with(ctx=context, folder=target) m_hash.assert_called_once_with(files=m_find.return_value, hasher=Hasher.MD5) self.assertEqual(m_find.return_value, ffile_ret) m_filter.assert_called_once_with(m_hash.return_value)