Changeset 135
- Timestamp:
- 2002-03-30 21:50:25 (7 years ago)
- Files:
-
- trunk/_mock_ftplib.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/_mock_ftplib.py
r133 r135 30 30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 31 32 # $Id: _mock_ftplib.py,v 1.1 2 2002/03/30 21:20:28schwa Exp $32 # $Id: _mock_ftplib.py,v 1.13 2002/03/30 21:50:25 schwa Exp $ 33 33 34 34 """ … … 312 312 DEBUG = 0 313 313 314 # Use a global dictionary of the form {path: mock_file, ...} 315 # to make "volatile" mock files accessible. This is used for 316 # testing the contents of a file after an FTPHost.upload call. 317 mock_files = {} 318 319 def content_of(path): 320 return mock_files[path].getvalue() 321 314 322 class MockFile(StringIO.StringIO): 315 323 """ … … 317 325 objects (not for _FTPFile objects themselves!). 318 326 """ 319 def __init__(self, content=''): 327 def __init__(self, path, content=''): 328 global mock_files 329 mock_files[path] = self 320 330 StringIO.StringIO.__init__(self, content) 321 331 … … 330 340 self._value_after_close = StringIO.StringIO.getvalue(self) 331 341 StringIO.StringIO.close(self) 332 342 333 343 334 344 class MockSocket: … … 337 347 MockSession.transfercmd. 338 348 """ 339 def __init__(self, mock_file_content=''):349 def __init__(self, path, mock_file_content=''): 340 350 if DEBUG: 341 351 print 'File content: *%s*' % mock_file_content 352 self.file_path = path 342 353 self.mock_file_content = mock_file_content 343 354 344 355 def makefile(self, mode): 345 return MockFile(self. mock_file_content)356 return MockFile(self.file_path, self.mock_file_content) 346 357 347 358 def close(self): … … 432 443 # fail if path isn't available (this name is hard-coded here 433 444 # and has to be used for the corresponding tests) 434 if cmd == 'RETR' and path == 'notthere':445 if (cmd, path) == ('RETR', 'notthere'): 435 446 raise ftplib.error_perm 436 return MockSocket( self.mock_file_content)437 447 return MockSocket(path, self.mock_file_content) 448
