diff options
author | Tomas Mlcoch <tmlcoch@redhat.com> | 2010-07-15 14:30:24 +0200 |
---|---|---|
committer | Will Woods <wwoods@redhat.com> | 2011-02-14 11:13:57 -0500 |
commit | 1b3452f91dfcd25b21911b86fc9aeab70b5625cd (patch) | |
tree | 26e673226f6164dc88ca17ee3e455f8faaa81327 /tests | |
parent | 66ed0b8603f4f64c5a6be9e7dac7dadef160635b (diff) | |
download | anaconda-1b3452f91dfcd25b21911b86fc9aeab70b5625cd.tar.gz anaconda-1b3452f91dfcd25b21911b86fc9aeab70b5625cd.tar.xz anaconda-1b3452f91dfcd25b21911b86fc9aeab70b5625cd.zip |
Improve of mock/disk.py.
Add __enter__() and __exit__() methods into TestFile class.
Rename "IO" to "TestFile".
Add destructor to TestFile and fix open mode "w".
Add destructor to TestFile and fix open for write.
Catch useless exception.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mock/disk.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/mock/disk.py b/tests/mock/disk.py index 39af5e8c3..1ff2a5c50 100644 --- a/tests/mock/disk.py +++ b/tests/mock/disk.py @@ -36,6 +36,18 @@ class DiskIO(object): def close(self): self.flush() return StringIO.close(self) + + def __del__(self): + try: + self.close() + except (AttributeError): + pass + + def __enter__(self): + return self + + def __exit__(self, *_): + self.close() class Dir(object): pass @@ -65,6 +77,9 @@ class DiskIO(object): content = self.fs.get(path, None) if content == self.Dir: raise IOError("[Errno 21] Is a directory: '%s'" % (path)) + elif mode == "w": + self.fs[path] = "" + f = self.TestFile(self.fs, path, self.fs[path]) elif not content and mode.startswith("w"): self.fs[path] = "" f = self.TestFile(self.fs, path, self.fs[path]) @@ -74,7 +89,7 @@ class DiskIO(object): f = self.TestFile(self.fs, path, content) f.seek(0, os.SEEK_END) else: - f = self.IO(self.fs, path, content) + f = self.TestFile(self.fs, path, content) return f |