Exemplo n.º 1
0
def test_retrbinary_raises_if_file_doesnt_exist(fsx_fake):
    fsx_fake.add_dict({'ftp://ftp.python.org': {}})
    ftp = fsx.ftplib.FTP('ftp.python.org')
    ftp.login('user', 'passwd')
    ftp.prot_p()

    with pytest.raises(ftplib.error_perm):
        ftp.retrbinary('RETR f1', sys.stdout)
Exemplo n.º 2
0
def test_nlst_works(fsdict, query_path, exp, fsx_fake):
    fsx_fake.add_dict(fsdict)
    ftp = fsx.ftplib.FTP('ftp.python.org')
    ftp.login('user', 'passwd')
    ftp.prot_p()

    res = ftp.nlst(query_path)
    assert set(res) == set(exp)
Exemplo n.º 3
0
def test_scandir_below_top_level_works(fsdict, top_path, exp_entries, fsx_fake):
    fsx_fake.add_dict(fsdict)
    gen_walk = fsx.scandir.scandir(top_path)
    for exp_entry in exp_entries:
        entry = next(gen_walk)
        assert entry.name == exp_entry.rstrip('/')
        assert entry.is_dir() == exp_entry.endswith('/')
        assert entry.is_file() != exp_entry.endswith('/')
Exemplo n.º 4
0
def test_scandir(fsx_fake):
    with pytest.raises((OSError, WindowsError)):
        next(fsx.scandir.scandir('X:/non-existing'))

    fsx_fake.add_dict({'C:/some/path.txt': 'foo'})
    entry = next(fsx.scandir.scandir('C:/some'))

    size = entry.stat().st_size
    assert size == 3
Exemplo n.º 5
0
def test_mkd_creates_directories(pathname, fsx_fake):
    fsx_fake.add_dict({'ftp://ftp.python.org': {}})
    ftp = fsx.ftplib.FTP('ftp.python.org')
    ftp.login('user', 'passwd')
    ftp.prot_p()

    ftp.mkd(pathname)

    assert fsx.isdir('ftp://ftp.python.org/' + pathname)
Exemplo n.º 6
0
def test_storbinary_creates_file_on_server(fp, server_path, content, fsx_fake):
    fsx_fake.add_dict({'ftp://ftp.python.org': {}, 'src.txt': content})
    ftp = fsx.ftplib.FTP('ftp.python.org')
    ftp.login('user', 'passwd')
    ftp.prot_p()

    ftp.storbinary('STOR ' + fp, fsx.open('src.txt', 'rb'))

    res = fsx.open(server_path, 'r').read()
    assert res == content
Exemplo n.º 7
0
def test_retrbinary_works(fsdict, file_path, exp, fsx_fake):
    fsx_fake.add_dict(fsdict)
    ftp = fsx.ftplib.FTP('ftp.python.org')
    ftp.login('user', 'passwd')
    ftp.prot_p()

    with fsx.open('C:/tmp/f1', 'wb') as file_:
        ftp.retrbinary('RETR ' + file_path, file_.write)
    res = fsx.open('C:/tmp/f1').read()
    assert res == exp
Exemplo n.º 8
0
def test_walk_on_path_below_first_node_works(fsdict, top_path, exp_roots,
                                             exp_dir_lists, exp_file_lists,
                                             fsx_fake):
    fsx_fake.add_dict(fsdict)
    gen_walk = fsx.os.walk(top_path)
    for exp_root, exp_dir_list, exp_file_list in zip(exp_roots, exp_dir_lists,
                                                     exp_file_lists):
        (root, dirs, files) = next(gen_walk)
        assert root == exp_root
        assert dirs == exp_dir_list
        assert files == exp_file_list
Exemplo n.º 9
0
def test_walk_finds_roots_dirs_and_files(fsdict, top_path, exp_roots,
                                         exp_dir_lists, exp_file_lists,
                                         fsx_fake):
    fsx_fake.add_dict(fsdict)
    gen_walk = fsx.os.walk(top_path)
    for exp_root, exp_dir_list, exp_file_list in zip(exp_roots, exp_dir_lists,
                                                     exp_file_lists):
        (root, dirs, files) = next(gen_walk)
        assert root == exp_root
        assert dirs == exp_dir_list
        assert files == exp_file_list
Exemplo n.º 10
0
def test_scandir_basic(fsdict, top_path, exp_entries, fsx_fake):
    fsx_fake.add_dict(fsdict)
    walk_entries = set(fsx.scandir.scandir(top_path))
    we_names = {we.name for we in walk_entries}
    exp_entries_names = {exp_entry.rstrip('/') for exp_entry in exp_entries}

    for we in walk_entries:
        if we.is_dir():
            assert we.name + '/' in exp_entries
        elif we.is_file():
            assert we.name in exp_entries
    assert we_names == exp_entries_names
Exemplo n.º 11
0
    def test_removes_directory_and_nodes_underneath(
        self,
        fstree,
        dirpath,
        expTreeDict,
        fsx_fake,
    ):
        fsx_fake.add_dict(fstree)
        fsx.shutil.rmtree(dirpath)

        res = fsx_fake.as_dict()

        assert res == expTreeDict
Exemplo n.º 12
0
    def test_raises_error_if_not_existing(self, fstree, dirpath, fsx_fake,
                                          monkeypatch):
        fsx_fake.add_dict(fstree)

        monkeypatch.setattr('sys.platform', 'win32')
        with pytest.raises(WindowsError):
            fsx.os.chdir(dirpath)

        monkeypatch.setattr('sys.platform', 'darwin')
        with pytest.raises(OSError):
            fsx.os.chdir(dirpath)

        monkeypatch.setattr('sys.platform', 'linux2')
        with pytest.raises(OSError):
            fsx.os.chdir(dirpath)
Exemplo n.º 13
0
 def test_getcwd_has_no_trailing_backslash_after_it_was_set_with_chdir(
         self, fstree, dirpath, expCurDir, fsx_fake):
     fsx_fake.add_dict(fstree)
     fsx.os.chdir(dirpath)
     assert fsx.os.getcwd() == expCurDir
Exemplo n.º 14
0
 def test_chdir_works(self, fstree, dirpath, fsx_fake):
     fsx_fake.add_dict(fstree)
     fsx.os.chdir(dirpath)
Exemplo n.º 15
0
def test_rmdir_raises_if_subfile_exists(fsx_fake):
    fsx_fake.add_dict({'temp/subd': None})
    with pytest.raises((WindowsError, IOError)):
        fsx.os.rmdir('temp')
Exemplo n.º 16
0
 def test_getcwd_has_trailing_on_driveletter_paths(self, fstree, dirpath,
                                                   expCurDir, fsx_fake):
     fsx_fake.add_dict(fstree)
     fsx.os.chdir(dirpath)
     assert fsx.os.getcwd() == expCurDir
Exemplo n.º 17
0
def test_rmdir_removes_subdir(fsx_fake):
    fsx_fake.add_dict({'temp/subd': {}})
    fsx.os.rmdir('temp/subd')
    assert fsx_fake.as_dict() == {'temp': {}}
Exemplo n.º 18
0
def test_exists_returns_false_on_empty_string(fstree, fsx_fake):
    fsx_fake.add_dict(fstree)
    assert fsx.os.path.exists('') == False