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

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

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

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

    assert fs.tree == {'/': {'home': {'user': {}}}}
예제 #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': {}}}}
예제 #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 == {'/': {}}
예제 #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'}}}}
예제 #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': {}}}}
예제 #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
예제 #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')
예제 #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'
예제 #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')
예제 #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': {}}}}}
예제 #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'
                }
            }
        }
    }
예제 #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
예제 #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
예제 #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
예제 #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')
예제 #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
예제 #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'
예제 #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')
예제 #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')
예제 #23
0
async def test_mkdir_first_toplevel():
    fs = MemProtocol()

    await fs.mkdir('/home')

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

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

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