| 200 | | |
|---|
| 201 | | # def test_caching(self): |
|---|
| 202 | | # """Test if _FTPFile cache of FTPHost object works.""" |
|---|
| 203 | | # host = FTPHostWrapper(host_name, user, password) |
|---|
| 204 | | # self.assertEqual( len(host._children), 0 ) |
|---|
| 205 | | # path1 = host.path.join(self.testdir, '__test1.dat') |
|---|
| 206 | | # path2 = host.path.join(self.testdir, '__test2.dat') |
|---|
| 207 | | # # open one file and inspect cache |
|---|
| 208 | | # file1 = host.file(path1, 'w') |
|---|
| 209 | | # child1 = host._children[0] |
|---|
| 210 | | # self.assertEqual( len(host._children), 1 ) |
|---|
| 211 | | # self.failIf(child1._file.closed) |
|---|
| 212 | | # # open another file |
|---|
| 213 | | # file2 = host.file(path2, 'w') |
|---|
| 214 | | # child2 = host._children[1] |
|---|
| 215 | | # self.assertEqual( len(host._children), 2 ) |
|---|
| 216 | | # self.failIf(child2._file.closed) |
|---|
| 217 | | # # close first file |
|---|
| 218 | | # file1.close() |
|---|
| 219 | | # self.assertEqual( len(host._children), 2 ) |
|---|
| 220 | | # self.failUnless(child1._file.closed) |
|---|
| 221 | | # self.failIf(child2._file.closed) |
|---|
| 222 | | # # re-open first child's file |
|---|
| 223 | | # file1 = host.file(path1, 'w') |
|---|
| 224 | | # child1_1 = file1._host |
|---|
| 225 | | # # check if it's reused |
|---|
| 226 | | # self.failUnless(child1 is child1_1) |
|---|
| 227 | | # self.failIf(child1._file.closed) |
|---|
| 228 | | # self.failIf(child2._file.closed) |
|---|
| 229 | | # # close second file |
|---|
| 230 | | # file2.close() |
|---|
| 231 | | # self.failUnless(child2._file.closed) |
|---|
| 232 | | # # clean up |
|---|
| 233 | | # host.remove(path1) |
|---|
| 234 | | # host.remove(path2) |
|---|
| 235 | | # |
|---|
| | 200 | def test_caching(self): |
|---|
| | 201 | """Test if _FTPFile cache of FTPHost object works.""" |
|---|
| | 202 | host = ftp_host_factory() |
|---|
| | 203 | self.assertEqual( len(host._children), 0 ) |
|---|
| | 204 | path1 = 'path1' |
|---|
| | 205 | path2 = 'path2' |
|---|
| | 206 | # open one file and inspect cache |
|---|
| | 207 | file1 = host.file(path1, 'w') |
|---|
| | 208 | child1 = host._children[0] |
|---|
| | 209 | self.assertEqual( len(host._children), 1 ) |
|---|
| | 210 | self.failIf(child1._file.closed) |
|---|
| | 211 | # open another file |
|---|
| | 212 | file2 = host.file(path2, 'w') |
|---|
| | 213 | child2 = host._children[1] |
|---|
| | 214 | self.assertEqual( len(host._children), 2 ) |
|---|
| | 215 | self.failIf(child2._file.closed) |
|---|
| | 216 | # close first file |
|---|
| | 217 | file1.close() |
|---|
| | 218 | self.assertEqual( len(host._children), 2 ) |
|---|
| | 219 | self.failUnless(child1._file.closed) |
|---|
| | 220 | self.failIf(child2._file.closed) |
|---|
| | 221 | # re-open first child's file |
|---|
| | 222 | file1 = host.file(path1, 'w') |
|---|
| | 223 | child1_1 = file1._host |
|---|
| | 224 | # check if it's reused |
|---|
| | 225 | self.failUnless(child1 is child1_1) |
|---|
| | 226 | self.failIf(child1._file.closed) |
|---|
| | 227 | self.failIf(child2._file.closed) |
|---|
| | 228 | # close second file |
|---|
| | 229 | file2.close() |
|---|
| | 230 | self.failUnless(child2._file.closed) |
|---|
| | 231 | |
|---|