Exemple #1
0
async def test_mkdirs_nested_within_inexisting_path():
    fs = MemProtocol()
    fs.tree = {'/': {}}

    await fs.mkdirs('/home/user/documents')

    assert fs.tree == {'/': {'home': {'user': {'documents': {}}}}}
Exemple #2
0
async def test_mkdirs_existing_dir():
    fs = MemProtocol()
    fs.tree = {'/': {'home': {'user': {}}}}

    await fs.mkdirs('/home/user')

    assert fs.tree == {'/': {'home': {'user': {}}}}
Exemple #3
0
async def test_cp_file_to_existing_file():
    fs = MemProtocol()
    fs.tree = {
        '/': {
            'tmp': {
                'xxx': {
                    'b.txt': b''
                },
                'a.txt': b'data data data'
            }
        }
    }

    await fs.cp('/tmp/a.txt', '/tmp/xxx/b.txt')

    assert fs.tree == {
        '/': {
            'tmp': {
                'a.txt': b'data data data',
                'xxx': {
                    'b.txt': b'data data data'
                }
            }
        }
    }
Exemple #4
0
async def test_mkdir_nested():
    fs = MemProtocol()
    fs.tree = {'/': {'home': {}}}

    await fs.mkdir('/home/user')

    assert fs.tree == {'/': {'home': {'user': {}}}}
Exemple #5
0
async def test_rm_file():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    await fs.rm('/tmp/a.txt')

    assert fs.tree == {'/': {'tmp': {'xxx': {}}}}
Exemple #6
0
async def test_rm_non_empty_dir():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    await fs.rm('/tmp')

    assert fs.tree == {'/': {}}
Exemple #7
0
async def test_mv_file_to_inexisting_file():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    await fs.mv('/tmp/a.txt', '/tmp/xxx/c.txt')

    assert fs.tree == {'/': {'tmp': {'xxx': {'c.txt': b'data data data'}}}}
Exemple #8
0
async def test_rm_empty_dir():
    fs = MemProtocol()
    fs.tree = {'/': {'home': {'user': {'documents': {}}}}}

    await fs.rm('/home/user/documents')

    assert fs.tree == {'/': {'home': {'user': {}}}}
Exemple #9
0
async def test_open_inexisting_file_for_read_should_fail():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    with pytest.raises(FileNotFoundError):
        async with fs.open('/tmp/b.txt'):
            pass
Exemple #10
0
async def test_cp_dir_to_existing_file_should_fail():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    with pytest.raises(
            ValueError,
            match='Unable to copy directory /tmp/xxx to file /tmp/a.txt'):
        await fs.cp('/tmp/xxx', '/tmp/a.txt')
Exemple #11
0
async def test_closed_file_changes_fs():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    async with fs.open('/tmp/a.txt', mode='w') as f:
        f.write('TEST TEST TEST')

    assert fs.tree['/']['tmp']['a.txt'] == b'TEST TEST TEST'
Exemple #12
0
async def test_mkdirs_fails_when_path_is_a_file():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    with pytest.raises(FileNotFoundError):
        await fs.mkdirs('/tmp/a.txt')

    with pytest.raises(FileNotFoundError):
        await fs.mkdirs('/tmp/a.txt/dir')
Exemple #13
0
async def test_rm_inexisting_dir():
    fs = MemProtocol()

    await fs.rm('/home/user/documents')

    assert fs.tree == {}

    fs.tree = {'/': {'home': {'user': {'documents': {}}}}}

    await fs.rm('/tmp')

    assert fs.tree == {'/': {'home': {'user': {'documents': {}}}}}
Exemple #14
0
async def test_cp_file_to_inexisting_dir():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    await fs.cp('/tmp/a.txt', '/tmp/yyy/')

    assert fs.tree == {
        '/': {
            'tmp': {
                'a.txt': b'data data data',
                'xxx': {},
                'yyy': {
                    'a.txt': b'data data data'
                }
            }
        }
    }
Exemple #15
0
async def test_directory_is_a_direcotry():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    assert await fs.is_dir('/tmp/xxx') is True
Exemple #16
0
async def test_file_is_not_a_directory():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    assert await fs.is_dir('/tmp/a.txt') is False
Exemple #17
0
async def test_inexisting_path_does_not_exist():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    assert await fs.exists('/pmt/a.txt') is False
Exemple #18
0
async def test_ls_tmp_dir():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    assert await fs.ls('/tmp') == ('xxx', 'a.txt')
Exemple #19
0
async def test_existing_path_exists():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    assert await fs.exists('/tmp/a.txt') is True
Exemple #20
0
async def test_open_existing_file_for_read():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    async with fs.open('/tmp/a.txt') as f:
        assert f.read() == 'data data data'
Exemple #21
0
async def test_inexisting_path_is_dir_check_fails():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    with pytest.raises(FileNotFoundError):
        assert await fs.is_dir('/tmp/yyy.txt')
Exemple #22
0
async def test_ls_inextisting_dir_fails():
    fs = MemProtocol()
    fs.tree = {'/': {'tmp': {'xxx': {}, 'a.txt': b'data data data'}}}

    with pytest.raises(FileNotFoundError):
        assert await fs.ls('/pmt')
Exemple #23
0
async def test_mkdir_first_toplevel():
    fs = MemProtocol()

    await fs.mkdir('/home')

    assert fs.tree == {'/': {'home': {}}}
Exemple #24
0
async def test_mkdirs_first_nested():
    fs = MemProtocol()

    await fs.mkdirs('/home/user/documents')

    assert fs.tree == {'/': {'home': {'user': {'documents': {}}}}}