Exemple #1
0
 def test_file_ValueError(self, tmpdir):
     with tmpdir.as_cwd():
         os.mkdir('bark')
         with open(os.path.join('bark', 'mark.txt'), 'w') as f:
             f.write('hello\nthis is a cool file\n')
         with pytest.raises(ValueError):
             t = Tree('bark/mark.txt')
Exemple #2
0
    def test_init(self, tmpdir):
        """
        Test that leaf works for:
            1. nonexistent file
            2. existing file

        Test that exception raised for:
            1. leaf initialized with existing directory

        """
        with tmpdir.as_cwd():

            # test nonexistent file
            t = Leaf('bark')
            assert not t.exists

            # test existent file
            t.make()
            assert t.exists

            t2 = Leaf('bark')
            assert t2.exists

            # test that init with directory raises ValueError

            # this should create a nonexistent Tree
            t3 = Tree('mark/').make()
            assert t3.exists

            with pytest.raises(ValueError):
                t4 = Leaf('mark')
Exemple #3
0
def draw_tree(tmpdir):
    # set up a tree to draw with
    with tmpdir.as_cwd():
        t = Tree('here')
        t['file_zero'].make()
        t['.file_zero_hidden'].make()
        t['dir_one/'].make()
        t['dir_one/file_one'].make()
        t['dir_one/.file_one_hidden'].make()
        t['dir_one/dir_two/'].make()
        t['dir_one/dir_two/file_two'].make()
        t['dir_one/dir_two/.file_two_hidden'].make()

        yield t
Exemple #4
0
 def contains_Tree(self, tmpdir):
     # Contains various combinations of files and directories
     # that do and do not exist. Structure:
     # container
     # + dir1
     #   + file2
     # + dir3  # doesn't exist
     #   + file4  # doesn't exist
     with tmpdir.as_cwd():
         os.mkdir('container')
         os.mkdir(os.path.join('container', 'dir1'))
         with open(os.path.join('container', 'dir1', 'file2'), 'w') as f:
             f.write('some data here\n')
         tree = Tree('container')
         yield tree
Exemple #5
0
 def test_existing(self, tmpdir):
     with tmpdir.as_cwd():
         os.makedirs('bark/lark')
         t = Tree('bark/lark/')
         assert isinstance(t, Tree)
         assert t.exists
Exemple #6
0
 def test_nonexistant(self, tmpdir):
     with tmpdir.as_cwd():
         # test nonexistent directory
         t = Tree('bark')
         assert isinstance(t, Tree)
         assert not t.exists
Exemple #7
0
 def tree(self, tmpdir):
     with tmpdir.as_cwd():
         t = Tree(self.name)
         yield t
Exemple #8
0
 def test_parent(self, veg):
     p = veg.parent
     assert isinstance(p, Tree)
     assert p == Tree(os.path.split(self.name)[0])