def test_rootfs_can_find_no_root_with_single_match(self): def mock_walker(root): return [ (root, ['bin', 'ausr'], []), (os.path.join(root, 'usr'), ['lib'], ['foo', 'bar']), ] assert rootfs.find_root('baz', walker=mock_walker) is None
def test_rootfs_can_find_root(self): def mock_walker(root): return [ (root, ['bin', 'usr'], []), (os.path.join(root, 'usr'), ['lib'], ['foo', 'bar']), ] assert rootfs.find_root('baz', walker=mock_walker) == 'baz'
def find_windows_details(cls, location): """ Find a Windows installation details and return a Distro object or None. """ if rootfs.find_root( location, max_depth=3, root_paths=rootfs.WINDOWS_PATHS, ): return cls( os='windows', identifier='windows', )
def test_rootfs_does_respects_max_depth(self): test_dir = self.extract_test_tar('rootfs/find_root.tar.gz') assert not rootfs.find_root(test_dir, max_depth=1) assert not rootfs.find_root(test_dir, max_depth=2) assert not rootfs.find_root(test_dir, max_depth=3) assert rootfs.find_root(test_dir, max_depth=4).endswith('level1/level2/level3') expected = '/find_root/level1/level2/level3' found = rootfs.find_root(test_dir, max_depth=5) assert found.replace(test_dir, '') == expected found = rootfs.find_root(test_dir, max_depth=0) assert found.replace(test_dir, '') == expected found = rootfs.find_root(os.path.join(test_dir, 'find_root'), max_depth=4) assert found.replace(test_dir, '') == expected