[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/VFS/tests - __init__.py:1.1.2.2 testOSFileSystem.py:1.1.2.4
Shane Hathaway
shane@cvs.zope.org
Thu, 4 Apr 2002 13:45:58 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Server/VFS/tests
In directory cvs.zope.org:/tmp/cvs-serv17993/VFS/tests
Modified Files:
Tag: Zope3-Server-Branch
__init__.py testOSFileSystem.py
Log Message:
Just fixed line endings. No carriage returns.
=== Zope3/lib/python/Zope/Server/VFS/tests/__init__.py 1.1.2.1 => 1.1.2.2 ===
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
-#
+#
##############################################################################
"""
=== Zope3/lib/python/Zope/Server/VFS/tests/testOSFileSystem.py 1.1.2.3 => 1.1.2.4 ===
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-
-$Id$
-"""
-
-
-import unittest
-import os
-import stat
-import tempfile
-
-from Interface.Verify import verifyClass
-from Zope.Server.VFS.IReadFileSystem import IReadFileSystem
-from Zope.Server.VFS.IWriteFileSystem import IWriteFileSystem
-
-from Zope.Server.VFS.OSFileSystem import OSFileSystem
-
-class OSFileSystemTest(unittest.TestCase):
- """This test is constructed in a way that it builds up a directory
- structure, whcih is removed at the end.
- """
-
- filesystem_class = OSFileSystem
- root = None
-
- def setUp(self):
- if self.root is None:
- self.root = tempfile.mktemp()
- self.filesystem = self.filesystem_class(self.root)
-
- os.mkdir(self.root)
-
-
- def tearDown(self):
- os.rmdir(self.root)
-
-
- def testNormalize(self):
-
- self.assertEqual(self.filesystem.normalize('/foo/bar//'), '/foo/bar')
- self.assertEqual(self.filesystem.normalize('/foo//bar'), '/foo/bar')
- self.assertEqual(self.filesystem.normalize('///foo/bar'), '/foo/bar')
- self.assertEqual(self.filesystem.normalize('///foo//bar////'),
- '/foo/bar')
-
- self.assertEqual(self.filesystem.normalize('../foo/bar'), '/')
- self.assertEqual(self.filesystem.normalize('..'), '/')
- self.assertEqual(self.filesystem.normalize('/..'), '/')
- self.assertEqual(self.filesystem.normalize('/foo/..'), '/')
- self.assertEqual(self.filesystem.normalize('/foo/../bar'), '/bar')
- self.assertEqual(self.filesystem.normalize('../../'), '/')
-
- self.assertEqual(self.filesystem.normalize('///../foo/bar'), '/foo/bar')
- self.assertEqual(self.filesystem.normalize('/foo/..///'), '/')
- self.assertEqual(self.filesystem.normalize('///foo/..//bar'), '/bar')
- self.assertEqual(self.filesystem.normalize('..///../'), '/')
-
-
- def testTranslate(self):
-
- self.assertEqual(self.filesystem.root, self.root)
-
- self.assertEqual(self.filesystem.translate('/foo/'),
- self.filesystem.path_module.join(self.root, 'foo'))
- self.assertEqual(self.filesystem.translate('/foo/bar'),
- self.filesystem.path_module.join(self.root,
- 'foo', 'bar'))
- self.assertEqual(self.filesystem.translate('foo/bar'),
- self.filesystem.path_module.join(self.root,
- 'foo', 'bar'))
-
- def testExists(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('test')
- self.failUnless(self.filesystem.exists('foo'))
- os.remove(path)
-
-
- def testIsDir(self):
- path = os.path.join(self.root, 'foo')
- os.mkdir(path)
- self.failUnless(self.filesystem.isdir('foo'))
- os.rmdir(path)
-
-
- def testIsFile(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('test')
- self.failUnless(self.filesystem.isfile('foo'))
- os.remove(path)
-
-
- def testListDir(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('test')
- self.assertEqual(self.filesystem.listdir('/', 0).more(),
- 'foo\r\n')
- os.remove(path)
-
-
- def testLongify(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('test')
- stat_info = os.stat(path)
- result = self.filesystem.longify(('foo', stat_info))
- self.failUnless(result.endswith('foo'))
- os.remove(path)
-
-
- def testOpen(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('writing test')
- self.assertEqual(self.filesystem.open('foo', 'r').read(), 'writing test')
- os.remove(path)
-
-
- def testStat(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('writing test')
- self.assertEqual(self.filesystem.stat('foo'), os.stat(path))
- os.remove(path)
-
-
- def testChmod(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('writing test')
- mode = 6*2**6 + 4*2**3 + 4*2**0 # 644
- self.filesystem.chmod('foo', mode)
- self.assertEqual(('%o' %os.stat(path)[stat.ST_MODE])[-3:], '644')
- os.remove(path)
-
-
- def testChown(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('writing test')
- self.filesystem.chown('foo', 500, 500)
- self.assertEqual(os.stat(path)[stat.ST_UID], 500)
- self.assertEqual(os.stat(path)[stat.ST_GID], 500)
- os.remove(path)
-
-
- def testLink(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('writing test')
- self.filesystem.link('foo', 'foo1')
- self.failUnless(os.path.exists(path+'1'))
- os.remove(path)
- os.remove(path+'1')
-
-
- def testMkdir(self):
- path = os.path.join(self.root, 'foo')
- self.filesystem.mkdir('foo')
- self.failUnless(os.path.exists(path))
- self.failUnless(os.path.isdir(path))
- os.rmdir(path)
-
-
- def testFifo(self):
- path = os.path.join(self.root, 'foo')
- self.filesystem.mkfifo(path)
- self.failUnless(os.path.exists(path))
- os.remove(path)
-
-
- def testRemove(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('writing test')
- self.filesystem.remove('foo')
- self.failIf(os.path.exists(path))
-
-
- def testRmdir(self):
- path = os.path.join(self.root, 'foo')
- os.mkdir(path)
- self.filesystem.rmdir('foo')
- self.failIf(os.path.exists(path))
-
-
- def testRename(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('writing test')
- self.filesystem.rename('foo', 'foo1')
- self.failUnless(os.path.exists(path+'1'))
- os.remove(path+'1')
-
-
- def testSymlink(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('writing test')
- self.filesystem.symlink('foo', 'foo1')
- self.failUnless(os.path.exists(path+'1'))
- os.remove(path)
- os.remove(path+'1')
-
-
- def testUnlink(self):
- path = os.path.join(self.root, 'foo')
- open(path, 'w').write('writing test')
- self.filesystem.unlink('foo')
- self.failIf(os.path.exists(path))
-
-
- def testWrite(self):
- path = os.path.join(self.root, 'foo')
- file = open(path, 'w')
- self.assertEqual(self.filesystem.write(file.fileno(), 'foo bar'), 7)
- file.close()
- os.remove(path)
-
-
- def testInterface(self):
- self.failUnless(
- IReadFileSystem.isImplementedByInstancesOf(self.filesystem_class))
- self.failUnless(verifyClass(IReadFileSystem, self.filesystem_class))
-
- self.failUnless(
- IWriteFileSystem.isImplementedByInstancesOf(self.filesystem_class))
- self.failUnless(verifyClass(IWriteFileSystem, self.filesystem_class))
-
-
-def test_suite():
- loader = unittest.TestLoader()
- return loader.loadTestsFromTestCase(OSFileSystemTest)
-
-if __name__=='__main__':
- unittest.TextTestRunner().run( test_suite() )
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+
+import unittest
+import os
+import stat
+import tempfile
+
+from Interface.Verify import verifyClass
+from Zope.Server.VFS.IReadFileSystem import IReadFileSystem
+from Zope.Server.VFS.IWriteFileSystem import IWriteFileSystem
+
+from Zope.Server.VFS.OSFileSystem import OSFileSystem
+
+class OSFileSystemTest(unittest.TestCase):
+ """This test is constructed in a way that it builds up a directory
+ structure, whcih is removed at the end.
+ """
+
+ filesystem_class = OSFileSystem
+ root = None
+
+ def setUp(self):
+ if self.root is None:
+ self.root = tempfile.mktemp()
+ self.filesystem = self.filesystem_class(self.root)
+
+ os.mkdir(self.root)
+
+
+ def tearDown(self):
+ os.rmdir(self.root)
+
+
+ def testNormalize(self):
+
+ self.assertEqual(self.filesystem.normalize('/foo/bar//'), '/foo/bar')
+ self.assertEqual(self.filesystem.normalize('/foo//bar'), '/foo/bar')
+ self.assertEqual(self.filesystem.normalize('///foo/bar'), '/foo/bar')
+ self.assertEqual(self.filesystem.normalize('///foo//bar////'),
+ '/foo/bar')
+
+ self.assertEqual(self.filesystem.normalize('../foo/bar'), '/')
+ self.assertEqual(self.filesystem.normalize('..'), '/')
+ self.assertEqual(self.filesystem.normalize('/..'), '/')
+ self.assertEqual(self.filesystem.normalize('/foo/..'), '/')
+ self.assertEqual(self.filesystem.normalize('/foo/../bar'), '/bar')
+ self.assertEqual(self.filesystem.normalize('../../'), '/')
+
+ self.assertEqual(self.filesystem.normalize('///../foo/bar'), '/foo/bar')
+ self.assertEqual(self.filesystem.normalize('/foo/..///'), '/')
+ self.assertEqual(self.filesystem.normalize('///foo/..//bar'), '/bar')
+ self.assertEqual(self.filesystem.normalize('..///../'), '/')
+
+
+ def testTranslate(self):
+
+ self.assertEqual(self.filesystem.root, self.root)
+
+ self.assertEqual(self.filesystem.translate('/foo/'),
+ self.filesystem.path_module.join(self.root, 'foo'))
+ self.assertEqual(self.filesystem.translate('/foo/bar'),
+ self.filesystem.path_module.join(self.root,
+ 'foo', 'bar'))
+ self.assertEqual(self.filesystem.translate('foo/bar'),
+ self.filesystem.path_module.join(self.root,
+ 'foo', 'bar'))
+
+ def testExists(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('test')
+ self.failUnless(self.filesystem.exists('foo'))
+ os.remove(path)
+
+
+ def testIsDir(self):
+ path = os.path.join(self.root, 'foo')
+ os.mkdir(path)
+ self.failUnless(self.filesystem.isdir('foo'))
+ os.rmdir(path)
+
+
+ def testIsFile(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('test')
+ self.failUnless(self.filesystem.isfile('foo'))
+ os.remove(path)
+
+
+ def testListDir(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('test')
+ self.assertEqual(self.filesystem.listdir('/', 0).more(),
+ 'foo\r\n')
+ os.remove(path)
+
+
+ def testLongify(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('test')
+ stat_info = os.stat(path)
+ result = self.filesystem.longify(('foo', stat_info))
+ self.failUnless(result.endswith('foo'))
+ os.remove(path)
+
+
+ def testOpen(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('writing test')
+ self.assertEqual(self.filesystem.open('foo', 'r').read(), 'writing test')
+ os.remove(path)
+
+
+ def testStat(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('writing test')
+ self.assertEqual(self.filesystem.stat('foo'), os.stat(path))
+ os.remove(path)
+
+
+ def testChmod(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('writing test')
+ mode = 6*2**6 + 4*2**3 + 4*2**0 # 644
+ self.filesystem.chmod('foo', mode)
+ self.assertEqual(('%o' %os.stat(path)[stat.ST_MODE])[-3:], '644')
+ os.remove(path)
+
+
+ def testChown(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('writing test')
+ self.filesystem.chown('foo', 500, 500)
+ self.assertEqual(os.stat(path)[stat.ST_UID], 500)
+ self.assertEqual(os.stat(path)[stat.ST_GID], 500)
+ os.remove(path)
+
+
+ def testLink(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('writing test')
+ self.filesystem.link('foo', 'foo1')
+ self.failUnless(os.path.exists(path+'1'))
+ os.remove(path)
+ os.remove(path+'1')
+
+
+ def testMkdir(self):
+ path = os.path.join(self.root, 'foo')
+ self.filesystem.mkdir('foo')
+ self.failUnless(os.path.exists(path))
+ self.failUnless(os.path.isdir(path))
+ os.rmdir(path)
+
+
+ def testFifo(self):
+ path = os.path.join(self.root, 'foo')
+ self.filesystem.mkfifo(path)
+ self.failUnless(os.path.exists(path))
+ os.remove(path)
+
+
+ def testRemove(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('writing test')
+ self.filesystem.remove('foo')
+ self.failIf(os.path.exists(path))
+
+
+ def testRmdir(self):
+ path = os.path.join(self.root, 'foo')
+ os.mkdir(path)
+ self.filesystem.rmdir('foo')
+ self.failIf(os.path.exists(path))
+
+
+ def testRename(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('writing test')
+ self.filesystem.rename('foo', 'foo1')
+ self.failUnless(os.path.exists(path+'1'))
+ os.remove(path+'1')
+
+
+ def testSymlink(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('writing test')
+ self.filesystem.symlink('foo', 'foo1')
+ self.failUnless(os.path.exists(path+'1'))
+ os.remove(path)
+ os.remove(path+'1')
+
+
+ def testUnlink(self):
+ path = os.path.join(self.root, 'foo')
+ open(path, 'w').write('writing test')
+ self.filesystem.unlink('foo')
+ self.failIf(os.path.exists(path))
+
+
+ def testWrite(self):
+ path = os.path.join(self.root, 'foo')
+ file = open(path, 'w')
+ self.assertEqual(self.filesystem.write(file.fileno(), 'foo bar'), 7)
+ file.close()
+ os.remove(path)
+
+
+ def testInterface(self):
+ self.failUnless(
+ IReadFileSystem.isImplementedByInstancesOf(self.filesystem_class))
+ self.failUnless(verifyClass(IReadFileSystem, self.filesystem_class))
+
+ self.failUnless(
+ IWriteFileSystem.isImplementedByInstancesOf(self.filesystem_class))
+ self.failUnless(verifyClass(IWriteFileSystem, self.filesystem_class))
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase(OSFileSystemTest)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )