def test_mutual_one_file_no_roots(mutual_one_file): """ Test two mutually recursive linked trees with one file, with no valid roots. """ _, tmpdir = mutual_one_file tree = FSTree.at_path(os.path.join(tmpdir, 'a'), set()) assert tree == FSTree({})
def test_basic(basic): """Test basic tree with not much drama.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}) # Note no entry for 'a/g' - it's an empty folder jib = FSTree({ 'a': FSTree({ 'b': None, 'a': FSTree({ 'd': None, 'e': None, }), 'f': None, }), 'h': FSTree({ 'a': FSTree({ 'i': None, }), }), 'j': FSTree({ 'a': None, }), }) assert tree == jib
def test_filter_on_path(with_suffixes): """ Test that filters can consider paths or path fragments. """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) # A pattern specifying a full path to a file full = re.compile('^foo/moo/zoo/BAR.md$') # A pattern specifying a file prefix, i.e. a path to a directory. prefix = re.compile('^fred.*$') filtered = tree.filter([full, prefix]) assert filtered == FSTree({ 'foo': FSTree({ 'moo': FSTree({ 'zoo': FSTree({ 'BAR.md': None, }), }), }), 'fred': FSTree({ 'blah.txt': None, 'klang.rst': None, 'wuub': None, }), })
def test_foobar(with_suffixes): _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) assert tree == FSTree({ 'foo': FSTree({ 'bar.md': None, 'moo': FSTree({ 'BAR.MD': None, 'thing': None, 'zoo': FSTree({ 'BAR.md': None, 'BAR.RST': None, }), }), }), 'fred': FSTree({ 'blah.txt': None, 'klang.rst': None, 'wuub': None, }), })
def test_filter_on_path(with_suffixes): """ Test that filters can consider paths or path fragments. """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) # A pattern specifying a full path to a file full = re.compile('^foo/moo/zoo/BAR.md$') # A pattern specifying a file prefix, i.e. a path to a directory. prefix = re.compile('^fred.*$') filtered = tree.filter([full, prefix]) assert filtered == FSTree({ 'foo': FSTree({ 'moo': FSTree({ 'zoo': FSTree({ 'BAR.md': None, }), }), }), 'fred': FSTree({ 'blah.txt': None, 'klang.rst': None, 'wuub': None, }), })
def test_filter_many(basic): """ Test using multiple filters. """ _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}) filtered = tree.filter( [re.compile(p) for p in ('.*a$', '.*(d|i)$', '.*e$')]) assert filtered == FSTree({ 'a': FSTree({ 'a': FSTree({ 'd': None, 'e': None, }), }), 'h': FSTree({ 'a': FSTree({ 'i': None, }), }), 'j': FSTree({ 'a': None, }), })
def test_basic(basic): """Test basic tree with not much drama.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}) # Note no entry for 'a/g' - it's an empty folder jib = FSTree({ 'a': FSTree({ 'b': None, 'a': FSTree({ 'd': None, 'e': None, }), 'f': None, }), 'h': FSTree({ 'a': FSTree({ 'i': None, }), }), 'j': FSTree({ 'a': None, }), }) assert tree == jib
def test_filter_many(basic): """ Test using multiple filters. """ _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}) filtered = tree.filter( [re.compile(p) for p in ('.*a$', '.*(d|i)$', '.*e$')] ) assert filtered == FSTree({ 'a': FSTree({ 'a': FSTree({ 'd': None, 'e': None, }), }), 'h': FSTree({ 'a': FSTree({ 'i': None, }), }), 'j': FSTree({ 'a': None, }), })
def test_filter_suffices_case_insens(with_suffixes): """ Test the kind of filter we're really going to want to do. """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) md_insens = re.compile(r'.*\.md$', re.IGNORECASE) rst_insens = re.compile(r'.*\.rst$', re.IGNORECASE) filtered = tree.filter([md_insens, rst_insens]) assert filtered == FSTree({ 'foo': FSTree({ 'bar.md': None, 'moo': FSTree({ 'BAR.MD': None, 'zoo': FSTree({ 'BAR.md': None, 'BAR.RST': None, }), }), }), 'fred': FSTree({'klang.rst': None}), })
def test_filter_empty(basic): """Test an empty filter list.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}) filtered = tree.filter([]) assert filtered == FSTree({ 'a': FSTree({ 'b': None, 'a': FSTree({ 'd': None, 'e': None, }), 'f': None, }), 'h': FSTree({ 'a': FSTree({ 'i': None, }), }), 'j': FSTree({ 'a': None, }), })
def test_triple_linked_all_valid(triple_linked): """ Test linking across three trees, where all three are valid roots. """ _, tmpdir = triple_linked first = os.path.join(tmpdir, 'a') second = os.path.join(tmpdir, 'd') third = os.path.join(tmpdir, 'g') tree = FSTree.at_path(first, {first, second, third}) assert tree == FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'f': FSTree({ 'h': FSTree({ 'i': None, }), }), }), }), }), })
def test_mutual_one_file_no_roots(mutual_one_file): """ Test two mutually recursive linked trees with one file, with no valid roots. """ _, tmpdir = mutual_one_file tree = FSTree.at_path(os.path.join(tmpdir, 'a'), set()) assert tree == FSTree({})
def test_mutual_one_file_first_root_valid(mutual_one_file): """ Test two mutually recursive linked trees with one file, where the tree the file is actually in is not a valid root. """ _, tmpdir = mutual_one_file root = os.path.join(tmpdir, 'a') tree = FSTree.at_path(root, {root}) assert tree == FSTree({})
def test_mutual_one_file_first_root_valid(mutual_one_file): """ Test two mutually recursive linked trees with one file, where the tree the file is actually in is not a valid root. """ _, tmpdir = mutual_one_file root = os.path.join(tmpdir, 'a') tree = FSTree.at_path(root, {root}) assert tree == FSTree({})
def test_basic_ignore_dir(basic): """Test ignoring some directory (which appears twice).""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}, ignore('a/')) # Causes 'h' to go too since it's now empty assert tree == FSTree({ 'j': FSTree({ 'a': None, }), })
def test_mutual_one_file_second_root_valid(mutual_one_file): """ Test two mutually recursive linked trees with one file, where the tree we ask to query is not a valid root. """ _, tmpdir = mutual_one_file root = os.path.join(tmpdir, 'a') other = os.path.join(tmpdir, 'd') tree = FSTree.at_path(root, {other}) assert tree == FSTree({})
def test_basic_ignore_dir(basic): """Test ignoring some directory (which appears twice).""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}, ignore('a/')) # Causes 'h' to go too since it's now empty assert tree == FSTree({ 'j': FSTree({ 'a': None, }), })
def test_mutual_one_file_second_root_valid(mutual_one_file): """ Test two mutually recursive linked trees with one file, where the tree we ask to query is not a valid root. """ _, tmpdir = mutual_one_file root = os.path.join(tmpdir, 'a') other = os.path.join(tmpdir, 'd') tree = FSTree.at_path(root, {other}) assert tree == FSTree({})
def test_basic_ignore_top_level_dir(basic): """Test ignoring some directory at the top level only.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}, ignore('/a/')) assert tree == FSTree({ 'h': FSTree({'a': FSTree({ 'i': None, })}), 'j': FSTree({ 'a': None, }), })
def test_basic_ignore_several(basic): """Test ignoring several names.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}, ignore('b', 'h', 'j')) assert tree == FSTree({ 'a': FSTree({ 'a': FSTree({ 'd': None, 'e': None, }), 'f': None, }), })
def test_filter_dir_path_link_resolved(with_suffixes): """ Test that matching vs a folder we linked to doesn't work. """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) # Here zoom is not in our tree at all (as fred links to it); even though # it's part of the absolute name of some files, we're only matching vs # names in the tree, from which this name is pruned because fred already # got there. prefix = re.compile('^.*zoom.*$') filtered = tree.filter([prefix]) assert filtered == FSTree({})
def test_filter_dir_path_link_resolved(with_suffixes): """ Test that matching vs a folder we linked to doesn't work. """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) # Here zoom is not in our tree at all (as fred links to it); even though # it's part of the absolute name of some files, we're only matching vs # names in the tree, from which this name is pruned because fred already # got there. prefix = re.compile('^.*zoom.*$') filtered = tree.filter([prefix]) assert filtered == FSTree({})
def test_basic_subtree(basic): """Test subtree of basic tree with not much drama.""" _, tmpdir = basic root = os.path.join(tmpdir, 'a') tree = FSTree.at_path(root, {root}) # Note no entry for 'a/g' - it's an empty folder assert tree == FSTree({ 'b': None, 'a': FSTree({ 'd': None, 'e': None, }), 'f': None, })
def test_basic_ignore_several(basic): """Test ignoring several names.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}, ignore('b', 'h', 'j')) assert tree == FSTree({ 'a': FSTree({ 'a': FSTree({ 'd': None, 'e': None, }), 'f': None, }), })
def test_basic_subtree(basic): """Test subtree of basic tree with not much drama.""" _, tmpdir = basic root = os.path.join(tmpdir, 'a') tree = FSTree.at_path(root, {root}) # Note no entry for 'a/g' - it's an empty folder assert tree == FSTree({ 'b': None, 'a': FSTree({ 'd': None, 'e': None, }), 'f': None, })
def test_basic_ignore_top_level_dir(basic): """Test ignoring some directory at the top level only.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}, ignore('/a/')) assert tree == FSTree({ 'h': FSTree({ 'a': FSTree({ 'i': None, }) }), 'j': FSTree({ 'a': None, }), })
def test_filter_one(basic): """ Test using a single filter. This test keeps matching files (but not matching directories), and that folders which are empty after filtering after filtered too. """ _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}) filtered = tree.filter([re.compile('.*a$')]) assert filtered == FSTree({ 'j': FSTree({ 'a': None, }), })
def test_filter_one(basic): """ Test using a single filter. This test keeps matching files (but not matching directories), and that folders which are empty after filtering after filtered too. """ _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}) filtered = tree.filter([re.compile('.*a$')]) assert filtered == FSTree({ 'j': FSTree({ 'a': None, }), })
def test_filter_suffix_md(with_suffixes): """ Test filtering on *.md """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) filtered = tree.filter([re.compile(r'.*\.md$')]) assert filtered == FSTree({ 'foo': FSTree({ 'bar.md': None, 'moo': FSTree({ 'zoo': FSTree({ 'BAR.md': None, }), }), }), })
def test_mutual_one_file_both_valid_roots(mutual_one_file): """ Test two mutually recursive linked trees with one file, where both trees are valid roots. """ _, tmpdir = mutual_one_file root = os.path.join(tmpdir, 'a') other = os.path.join(tmpdir, 'd') tree = FSTree.at_path(root, {root, other}) assert tree == FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'g': None, }), }), }), })
def test_mutual_one_file_parent_valid_root(mutual_one_file): """ Test two mutually recursive linked trees with one file, where the parent is valid. """ _, tmpdir = mutual_one_file root = os.path.join(tmpdir, 'a') tree = FSTree.at_path(root, {tmpdir}) # Same result as before: valid parent implies valid children assert tree == FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'g': None, }), }), }), })
def test_filter_suffix_md(with_suffixes): """ Test filtering on *.md """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) filtered = tree.filter([re.compile(r'.*\.md$')]) assert filtered == FSTree({ 'foo': FSTree({ 'bar.md': None, 'moo': FSTree({ 'zoo': FSTree({ 'BAR.md': None, }), }), }), })
def test_mutual_one_file_both_valid_roots(mutual_one_file): """ Test two mutually recursive linked trees with one file, where both trees are valid roots. """ _, tmpdir = mutual_one_file root = os.path.join(tmpdir, 'a') other = os.path.join(tmpdir, 'd') tree = FSTree.at_path(root, {root, other}) assert tree == FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'g': None, }), }), }), })
def test_mutual_one_file_parent_valid_root(mutual_one_file): """ Test two mutually recursive linked trees with one file, where the parent is valid. """ _, tmpdir = mutual_one_file root = os.path.join(tmpdir, 'a') tree = FSTree.at_path(root, {tmpdir}) # Same result as before: valid parent implies valid children assert tree == FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'g': None, }), }), }), })
def test_triple_linked_invalids(triple_linked): """ Test linking across three trees, where 0-2 of of them are not valid roots. """ _, tmpdir = triple_linked first = os.path.join(tmpdir, 'a') second = os.path.join(tmpdir, 'd') third = os.path.join(tmpdir, 'g') for nope in ( set(), {first}, {second}, {third}, {first, second}, {first, third}, {second, third}, ): tree = FSTree.at_path(first, valid_roots=nope) assert tree == FSTree({})
def test_filter_suffix_md_case_insens(with_suffixes): """ Case insensitive version of test_filter_suffix_md """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) md_insens = re.compile(r'.*\.md$', re.IGNORECASE) filtered = tree.filter([md_insens]) assert filtered == FSTree({ 'foo': FSTree({ 'bar.md': None, 'moo': FSTree({ 'BAR.MD': None, 'zoo': FSTree({ 'BAR.md': None, }), }), }), })
def test_triple_linked_invalids(triple_linked): """ Test linking across three trees, where 0-2 of of them are not valid roots. """ _, tmpdir = triple_linked first = os.path.join(tmpdir, 'a') second = os.path.join(tmpdir, 'd') third = os.path.join(tmpdir, 'g') for nope in ( set(), {first}, {second}, {third}, {first, second}, {first, third}, {second, third}, ): tree = FSTree.at_path(first, valid_roots=nope) assert tree == FSTree({})
def test_mutual_one_file_parent_valid_root_start_root(mutual_one_file): """ Test two mutually recursive linked trees with one file, where the parent is valid, starting at the parent. """ _, tmpdir = mutual_one_file tree = FSTree.at_path(tmpdir, {tmpdir}) # Same result as before, but with the extra layer of 'a'; no top-level # 'd' folder because we already found it while recursing into 'a'. assert tree == FSTree({ 'a': FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'g': None, }), }), }), }), })
def test_triple_linked_parent_valid(triple_linked): """ Test linking across three trees, where their parent is a valid root. """ _, tmpdir = triple_linked first = os.path.join(tmpdir, 'a') tree = FSTree.at_path(first, {tmpdir}) assert tree == FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'f': FSTree({ 'h': FSTree({ 'i': None, }), }), }), }), }), })
def test_mutual_one_file_parent_valid_root_start_root(mutual_one_file): """ Test two mutually recursive linked trees with one file, where the parent is valid, starting at the parent. """ _, tmpdir = mutual_one_file tree = FSTree.at_path(tmpdir, {tmpdir}) # Same result as before, but with the extra layer of 'a'; no top-level # 'd' folder because we already found it while recursing into 'a'. assert tree == FSTree({ 'a': FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'g': None, }), }), }), }), })
def test_foobar(with_suffixes): _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) assert tree == FSTree({ 'foo': FSTree({ 'bar.md': None, 'moo': FSTree({ 'BAR.MD': None, 'thing': None, 'zoo': FSTree({ 'BAR.md': None, 'BAR.RST': None, }), }), }), 'fred': FSTree({ 'blah.txt': None, 'klang.rst': None, 'wuub': None, }), })
def test_filter_suffix_md_case_insens(with_suffixes): """ Case insensitive version of test_filter_suffix_md """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) md_insens = re.compile(r'.*\.md$', re.IGNORECASE) filtered = tree.filter([md_insens]) assert filtered == FSTree({ 'foo': FSTree({ 'bar.md': None, 'moo': FSTree({ 'BAR.MD': None, 'zoo': FSTree({ 'BAR.md': None, }), }), }), })
def test_triple_linked_all_valid(triple_linked): """ Test linking across three trees, where all three are valid roots. """ _, tmpdir = triple_linked first = os.path.join(tmpdir, 'a') second = os.path.join(tmpdir, 'd') third = os.path.join(tmpdir, 'g') tree = FSTree.at_path(first, {first, second, third}) assert tree == FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'f': FSTree({ 'h': FSTree({ 'i': None, }), }), }), }), }), })
def test_triple_linked_parent_valid(triple_linked): """ Test linking across three trees, where their parent is a valid root. """ _, tmpdir = triple_linked first = os.path.join(tmpdir, 'a') tree = FSTree.at_path(first, {tmpdir}) assert tree == FSTree({ 'b': FSTree({ 'c': FSTree({ 'e': FSTree({ 'f': FSTree({ 'h': FSTree({ 'i': None, }), }), }), }), }), })
def test_filter_empty(basic): """Test an empty filter list.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}) filtered = tree.filter([]) assert filtered == FSTree({ 'a': FSTree({ 'b': None, 'a': FSTree({ 'd': None, 'e': None, }), 'f': None, }), 'h': FSTree({ 'a': FSTree({ 'i': None, }), }), 'j': FSTree({ 'a': None, }), })
def test_filter_suffices_case_insens(with_suffixes): """ Test the kind of filter we're really going to want to do. """ _, tmpdir = with_suffixes tree = FSTree.at_path(tmpdir, {tmpdir}) md_insens = re.compile(r'.*\.md$', re.IGNORECASE) rst_insens = re.compile(r'.*\.rst$', re.IGNORECASE) filtered = tree.filter([md_insens, rst_insens]) assert filtered == FSTree({ 'foo': FSTree({ 'bar.md': None, 'moo': FSTree({ 'BAR.MD': None, 'zoo': FSTree({ 'BAR.md': None, 'BAR.RST': None, }), }), }), 'fred': FSTree({ 'klang.rst': None }), })
def test_basic_ignore_tree_being_walked(basic): """Test ignoring the whole tree we're walking.""" _, tmpdir = basic tree = FSTree.at_path(os.path.join(tmpdir, 'h'), {tmpdir}, ignore('h')) # Everything disappears assert tree == FSTree({})
def test_basic_ignore_file_and_dir(basic): """Test ignoring some name used for file and directory.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}, ignore('a')) # Everything disappears assert tree == FSTree({})
def test_basic_ignore_file_and_dir(basic): """Test ignoring some name used for file and directory.""" _, tmpdir = basic tree = FSTree.at_path(tmpdir, {tmpdir}, ignore('a')) # Everything disappears assert tree == FSTree({})
def test_mutual_empty(mutual_empty): """Test two mutually recursive linked trees with no files.""" _, tmpdir = mutual_empty tree = FSTree.at_path(os.path.join(tmpdir, 'a'), {tmpdir}) assert tree == FSTree({})
def test_basic_ignore_tree_being_walked(basic): """Test ignoring the whole tree we're walking.""" _, tmpdir = basic tree = FSTree.at_path(os.path.join(tmpdir, 'h'), {tmpdir}, ignore('h')) # Everything disappears assert tree == FSTree({})
def test_mutual_empty(mutual_empty): """Test two mutually recursive linked trees with no files.""" _, tmpdir = mutual_empty tree = FSTree.at_path(os.path.join(tmpdir, 'a'), {tmpdir}) assert tree == FSTree({})