def test_remove_raises_error_if_file_is_directory(fsx_fake, monkeypatch): fsx_fake.add_dir('/tmp/file') path = '/tmp/file' monkeypatch.setattr('sys.platform', 'win32') with pytest.raises(WindowsError) as exc: fsx.os.remove(path) monkeypatch.setattr('sys.platform', 'linux2') with pytest.raises(OSError): fsx.os.remove(path) monkeypatch.setattr('sys.platform', 'darwin') with pytest.raises(OSError): fsx.os.remove(path)
def test_ZipFile_write_creates_file_which_can_be_read( self, curdir, zipArchivePath, memberFilePath, expArchivePaths, expZipMemberName, fsx_fake): fsx_fake.add_dir(curdir) fsx_fake.add_file(memberFilePath, 'file-content') fsx.os.chdir(curdir) with fsx.zipfile.ZipFile(zipArchivePath, 'w') as file_: file_.write(memberFilePath) with fsx.zipfile.ZipFile(zipArchivePath, 'r') as file_: assert file_.namelist() == [expZipMemberName] assert file_.read(expZipMemberName) == six.b('file-content') for expArchivePath in expArchivePaths: assert fsx.os.path.exists(expArchivePath) == True
def test_add_dir_flips_fwdslashes_on_win(dirpath, exp, monkeypatch, fsx_fake): monkeypatch.setattr(sys, 'platform', 'win32') fsx_fake.add_dir(dirpath) assert fsx_fake.as_dict() == exp
def test_raises_if_path_is_directory(self, fsx_fake): fsx_fake.add_dir('X:/a') with pytest.raises(EnvironmentError): fsx.os.path.getsize('X:/a')
def test_isdir(path, files, dirs, type_, fsx_fake): [fsx_fake.add_file(item) for item in files] [fsx_fake.add_dir(item) for item in dirs] exp = type_ == 'd' assert exp == fsx.os.path.isdir(path)
def test_exists(path, files, dirs, type_, fsx_fake): [fsx_fake.add_file(item) for item in files] [fsx_fake.add_dir(item) for item in dirs] exp = type_ in ['f', 'd'] assert exp == fsx.os.path.exists(path)