Ejemplo n.º 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': {}}}}}
Ejemplo n.º 2
0
async def test_mkdirs_existing_dir():
    fs = MemProtocol()
    fs.tree = {'/': {'home': {'user': {}}}}

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

    assert fs.tree == {'/': {'home': {'user': {}}}}
Ejemplo n.º 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'
                }
            }
        }
    }
Ejemplo n.º 4
0
async def test_mkdir_nested():
    fs = MemProtocol()
    fs.tree = {'/': {'home': {}}}

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

    assert fs.tree == {'/': {'home': {'user': {}}}}
Ejemplo n.º 5
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'}}}}
Ejemplo n.º 6
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': {}}}}
Ejemplo n.º 7
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': {}}}}
Ejemplo n.º 8
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 == {'/': {}}
Ejemplo n.º 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
Ejemplo n.º 10
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'
Ejemplo n.º 11
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')
Ejemplo n.º 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')
Ejemplo n.º 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': {}}}}}
Ejemplo n.º 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'
                }
            }
        }
    }
Ejemplo n.º 15
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')
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
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
Ejemplo n.º 19
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')
Ejemplo n.º 20
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
Ejemplo n.º 21
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'
Ejemplo n.º 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')