Exemple #1
0
def test_get_tree():
    with tempfile.TemporaryDirectory() as tmpdir:
        tree = {
            'a.txt': b'abc',
            'b.txt': b'cde',
            'subdir': {
                'e.txt': b'ddd'
            }
        }
        dir_info = DirectoryInfo(tmpdir)
        dir_info.make_tree(tree)

        assert dir_info.get_tree() == tree
Exemple #2
0
def test_make_tree_with_stream():
    with tempfile.TemporaryDirectory() as tmpdir:
        tree = {
            'a.txt': b'abc',
            'b.txt': b'cde',
            'subdir': {
                'e.txt': b'ddd'
            }
        }
        dir_info = DirectoryInfo(tmpdir)
        dir_info.make_tree(tree)

        with dir_info.get_tree(as_stream=True) as stree:
            with tempfile.TemporaryDirectory() as tmpdir2:
                dir_info_2 = DirectoryInfo(tmpdir2)
                dir_info_2.make_tree(stree)
                assert dir_info_2.get_tree() == tree
Exemple #3
0
def test_make_tree():
    with tempfile.TemporaryDirectory() as tmpdir:
        dir_info = DirectoryInfo(tmpdir)
        dir_info.make_tree({
            'a.txt': 'abc',
            'b.txt': b'cde',
            'subdir': {
                'e.txt': 'ddd'
            }
        })

        assert dir_info.get_fileinfo('a.txt').read_text() == 'abc'
        assert dir_info.get_fileinfo('b.txt').read_text() == 'cde'

        subdir = dir_info.get_dirinfo('subdir')
        assert subdir.is_directory()
        assert subdir.get_fileinfo('e.txt').read_text() == 'ddd'