def test_locate_recursive(): "FileSystem.locate recursive" mox = Mox() base_path = '../to/project' full_path = '/full/path/to/project' class MyFs(io.FileSystem): stack = [] abspath = mox.CreateMockAnything() walk = mox.CreateMockAnything() io.glob('%s/*match*.py' % full_path) MyFs.abspath(base_path).AndReturn(full_path) walk_list = [ (None, None, ['file1.py', 'file2.jpg']), (None, None, ['path1/file3.png', 'path1/file4.html']) ] MyFs.walk(full_path).AndReturn(walk_list) mox.ReplayAll() try: MyFs.locate(base_path, '*match*.py', recursive=True) mox.VerifyAll() finally: mox.UnsetStubs()
def test_locate_recursive(): "FileSystem.locate recursive" mox = Mox() base_path = '../to/project' full_path = '/full/path/to/project' class MyFs(io.FileSystem): stack = [] abspath = mox.CreateMockAnything() walk = mox.CreateMockAnything() io.glob('%s/*match*.py' % full_path) MyFs.abspath(base_path).AndReturn(full_path) walk_list = [(None, None, ['file1.py', 'file2.jpg']), (None, None, ['path1/file3.png', 'path1/file4.html'])] MyFs.walk(full_path).AndReturn(walk_list) mox.ReplayAll() try: MyFs.locate(base_path, '*match*.py', recursive=True) mox.VerifyAll() finally: mox.UnsetStubs()
def test_locate_non_recursive(): "FileSystem.locate non-recursive" mox = Mox() old_glob = io.glob io.glob = mox.CreateMockAnything() base_path = '../to/project' full_path = '/full/path/to/project' class MyFs(io.FileSystem): stack = [] abspath = mox.CreateMockAnything() io.glob('%s/*match*.py' % full_path) MyFs.abspath(base_path).AndReturn(full_path) mox.ReplayAll() try: MyFs.locate(base_path, '*match*.py', recursive=False) mox.VerifyAll() finally: mox.UnsetStubs() io.glob = old_glob