diff options
author | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2011-12-27 16:50:20 +0000 |
---|---|---|
committer | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2011-12-27 16:50:20 +0000 |
commit | 3b900b1c11d9b5fc247b9fdf6461bceea47e7950 (patch) | |
tree | 5c43bc973942a1c49f65a9d9a5edf468354753dc /fs/tests | |
parent | 754fcc98df0d379a92c7b9741505c257e09a532f (diff) | |
download | pyfilesystem-git-3b900b1c11d9b5fc247b9fdf6461bceea47e7950.tar.gz |
Python3 compatibility
Diffstat (limited to 'fs/tests')
-rw-r--r-- | fs/tests/__init__.py | 7 | ||||
-rw-r--r-- | fs/tests/test_importhook.py | 17 | ||||
-rw-r--r-- | fs/tests/test_watch.py | 2 | ||||
-rw-r--r-- | fs/tests/test_xattr.py | 13 | ||||
-rw-r--r-- | fs/tests/test_zipfs.py | 61 |
5 files changed, 52 insertions, 48 deletions
diff --git a/fs/tests/__init__.py b/fs/tests/__init__.py index dd4df46..3af1b99 100644 --- a/fs/tests/__init__.py +++ b/fs/tests/__init__.py @@ -297,8 +297,8 @@ class FSTestCases(object): self.assertRaises(ResourceInvalidError,self.fs.listdirinfo,"foo") def test_walk(self): - self.fs.setcontents('a.txt', 'hello') - self.fs.setcontents('b.txt', 'world') + self.fs.setcontents('a.txt', b('hello')) + self.fs.setcontents('b.txt', b('world')) self.fs.makeopendir('foo').setcontents('c', b('123')) sorted_walk = sorted([(d,sorted(fs)) for (d,fs) in self.fs.walk()]) self.assertEquals(sorted_walk, @@ -730,7 +730,8 @@ class FSTestCases(object): checkcontents("hello",b("12345")) def test_truncate_to_larger_size(self): - + print repr(self.fs) + print self.fs.__class__ with self.fs.open("hello","wb") as f: f.truncate(30) self.assertEquals(self.fs.getsize("hello"), 30) diff --git a/fs/tests/test_importhook.py b/fs/tests/test_importhook.py index e2d1564..4177b54 100644 --- a/fs/tests/test_importhook.py +++ b/fs/tests/test_importhook.py @@ -10,6 +10,7 @@ from fs.expose.importhook import FSImportHook from fs.tempfs import TempFS from fs.zipfs import ZipFS +from six import b class TestFSImportHook(unittest.TestCase): @@ -32,23 +33,23 @@ class TestFSImportHook(unittest.TestCase): sys.path_importer_cache.clear() def _init_modules(self,fs): - fs.setcontents("fsih_hello.py",dedent(""" + fs.setcontents("fsih_hello.py",b(dedent(""" message = 'hello world!' - """)) + """))) fs.makedir("fsih_pkg") - fs.setcontents("fsih_pkg/__init__.py",dedent(""" + fs.setcontents("fsih_pkg/__init__.py",b(dedent(""" a = 42 - """)) - fs.setcontents("fsih_pkg/sub1.py",dedent(""" + """))) + fs.setcontents("fsih_pkg/sub1.py",b(dedent(""" import fsih_pkg from fsih_hello import message a = fsih_pkg.a - """)) - fs.setcontents("fsih_pkg/sub2.pyc",self._getpyc(dedent(""" + """))) + fs.setcontents("fsih_pkg/sub2.pyc",self._getpyc(b(dedent(""" import fsih_pkg from fsih_hello import message a = fsih_pkg.a * 2 - """))) + """)))) def _getpyc(self,src): """Get the .pyc contents to match th given .py source code.""" diff --git a/fs/tests/test_watch.py b/fs/tests/test_watch.py index 613fe7a..22498df 100644 --- a/fs/tests/test_watch.py +++ b/fs/tests/test_watch.py @@ -178,7 +178,7 @@ class WatcherTestCases: while not isinstance(event,CLOSED): event = changes.next(timeout=1) # That should be the last event in the list - self.assertRaises(StopIteration,changes.next,timeout=1) + self.assertRaises(StopIteration,getattr(changes, "next"),timeout=1) changes.close() diff --git a/fs/tests/test_xattr.py b/fs/tests/test_xattr.py index 5100087..7be5560 100644 --- a/fs/tests/test_xattr.py +++ b/fs/tests/test_xattr.py @@ -11,6 +11,7 @@ from fs.path import * from fs.errors import * from fs.tests import FSTestCases +from six import b class XAttrTestCases: """Testcases for filesystems providing extended attribute support. @@ -26,11 +27,11 @@ class XAttrTestCases: self.assertEqual(self.fs.getxattr(p,"xattr1"),"value1") self.fs.delxattr(p,"xattr1") self.assertEqual(self.fs.getxattr(p,"xattr1"),None) - self.fs.setcontents("test.txt","hello") + self.fs.setcontents("test.txt",b("hello")) do_getsetdel("test.txt") self.assertRaises(ResourceNotFoundError,self.fs.getxattr,"test2.txt","xattr1") self.fs.makedir("mystuff") - self.fs.setcontents("/mystuff/test.txt","") + self.fs.setcontents("/mystuff/test.txt",b("")) do_getsetdel("mystuff") do_getsetdel("mystuff/test.txt") @@ -49,15 +50,15 @@ class XAttrTestCases: self.assertEquals(sorted(self.fs.listxattrs(p)),["attr2"]) self.fs.delxattr(p,"attr2") self.assertEquals(sorted(self.fs.listxattrs(p)),[]) - self.fs.setcontents("test.txt","hello") + self.fs.setcontents("test.txt",b("hello")) do_list("test.txt") self.fs.makedir("mystuff") - self.fs.setcontents("/mystuff/test.txt","") + self.fs.setcontents("/mystuff/test.txt",b("")) do_list("mystuff") do_list("mystuff/test.txt") def test_copy_xattrs(self): - self.fs.setcontents("a.txt","content") + self.fs.setcontents("a.txt",b("content")) self.fs.setxattr("a.txt","myattr","myvalue") self.fs.setxattr("a.txt","testattr","testvalue") self.fs.makedir("stuff") @@ -75,7 +76,7 @@ class XAttrTestCases: self.assertEquals(self.fs.getxattr("stuff","dirattr"),"a directory") def test_move_xattrs(self): - self.fs.setcontents("a.txt","content") + self.fs.setcontents("a.txt",b("content")) self.fs.setxattr("a.txt","myattr","myvalue") self.fs.setxattr("a.txt","testattr","testvalue") self.fs.makedir("stuff") diff --git a/fs/tests/test_zipfs.py b/fs/tests/test_zipfs.py index 3db5740..3056cbd 100644 --- a/fs/tests/test_zipfs.py +++ b/fs/tests/test_zipfs.py @@ -13,9 +13,10 @@ import shutil import fs.tests from fs.path import * +from fs import zipfs +from six import b -from fs import zipfs class TestReadZipFS(unittest.TestCase): def setUp(self): @@ -24,11 +25,11 @@ class TestReadZipFS(unittest.TestCase): self.zf = zipfile.ZipFile(self.temp_filename, "w") zf = self.zf - zf.writestr("a.txt", "Hello, World!") - zf.writestr("b.txt", "b") - zf.writestr("1.txt", "1") - zf.writestr("foo/bar/baz.txt", "baz") - zf.writestr("foo/second.txt", "hai") + zf.writestr("a.txt", b("Hello, World!")) + zf.writestr("b.txt", b("b")) + zf.writestr("1.txt", b("1")) + zf.writestr("foo/bar/baz.txt", b("baz")) + zf.writestr("foo/second.txt", b("hai")) zf.close() self.fs = zipfs.ZipFS(self.temp_filename, "r") @@ -50,18 +51,18 @@ class TestReadZipFS(unittest.TestCase): return contents def check_contents(path, expected): self.assert_(read_contents(path)==expected) - check_contents("a.txt", "Hello, World!") - check_contents("1.txt", "1") - check_contents("foo/bar/baz.txt", "baz") + check_contents("a.txt", b("Hello, World!")) + check_contents("1.txt", b("1")) + check_contents("foo/bar/baz.txt", b("baz")) def test_getcontents(self): def read_contents(path): return self.fs.getcontents(path) def check_contents(path, expected): self.assert_(read_contents(path)==expected) - check_contents("a.txt", "Hello, World!") - check_contents("1.txt", "1") - check_contents("foo/bar/baz.txt", "baz") + check_contents("a.txt", b("Hello, World!")) + check_contents("1.txt", b("1")) + check_contents("foo/bar/baz.txt", b("baz")) def test_is(self): self.assert_(self.fs.isfile('a.txt')) @@ -98,15 +99,15 @@ class TestWriteZipFS(unittest.TestCase): def makefile(filename, contents): if dirname(filename): zip_fs.makedir(dirname(filename), recursive=True, allow_recreate=True) - f = zip_fs.open(filename, 'w') + f = zip_fs.open(filename, 'wb') f.write(contents) f.close() - makefile("a.txt", "Hello, World!") - makefile("b.txt", "b") - makefile(u"\N{GREEK SMALL LETTER ALPHA}/\N{GREEK CAPITAL LETTER OMEGA}.txt", "this is the alpha and the omega") - makefile("foo/bar/baz.txt", "baz") - makefile("foo/second.txt", "hai") + makefile("a.txt", b("Hello, World!")) + makefile("b.txt", b("b")) + makefile(u"\N{GREEK SMALL LETTER ALPHA}/\N{GREEK CAPITAL LETTER OMEGA}.txt", b("this is the alpha and the omega")) + makefile("foo/bar/baz.txt", b("baz")) + makefile("foo/second.txt", b("hai")) zip_fs.close() @@ -123,11 +124,11 @@ class TestWriteZipFS(unittest.TestCase): def check_contents(filename, contents): zcontents = zf.read(filename.encode("CP437")) self.assertEqual(contents, zcontents) - check_contents("a.txt", "Hello, World!") - check_contents("b.txt", "b") - check_contents("foo/bar/baz.txt", "baz") - check_contents("foo/second.txt", "hai") - check_contents(u"\N{GREEK SMALL LETTER ALPHA}/\N{GREEK CAPITAL LETTER OMEGA}.txt", "this is the alpha and the omega") + check_contents("a.txt", b()"Hello, World!") + check_contents("b.txt", b("b")) + check_contents("foo/bar/baz.txt", b("baz")) + check_contents("foo/second.txt", b("hai")) + check_contents(u"\N{GREEK SMALL LETTER ALPHA}/\N{GREEK CAPITAL LETTER OMEGA}.txt", b("this is the alpha and the omega")) class TestAppendZipFS(TestWriteZipFS): @@ -141,19 +142,19 @@ class TestAppendZipFS(TestWriteZipFS): def makefile(filename, contents): if dirname(filename): zip_fs.makedir(dirname(filename), recursive=True, allow_recreate=True) - f = zip_fs.open(filename, 'w') + f = zip_fs.open(filename, 'wb') f.write(contents) f.close() - makefile("a.txt", "Hello, World!") - makefile("b.txt", "b") + makefile("a.txt", b("Hello, World!")) + makefile("b.txt", b("b")) zip_fs.close() zip_fs = zipfs.ZipFS(self.temp_filename, 'a') - makefile("foo/bar/baz.txt", "baz") - makefile(u"\N{GREEK SMALL LETTER ALPHA}/\N{GREEK CAPITAL LETTER OMEGA}.txt", "this is the alpha and the omega") - makefile("foo/second.txt", "hai") + makefile("foo/bar/baz.txt", b("baz")) + makefile(u"\N{GREEK SMALL LETTER ALPHA}/\N{GREEK CAPITAL LETTER OMEGA}.txt", b("this is the alpha and the omega")) + makefile("foo/second.txt", b("hai")) zip_fs.close() @@ -168,7 +169,7 @@ class TestZipFSErrors(unittest.TestCase): def test_bogus_zipfile(self): badzip = os.path.join(self.workdir,"bad.zip") f = open(badzip,"wb") - f.write("I'm not really a zipfile") + f.write(b("I'm not really a zipfile")) f.close() self.assertRaises(zipfs.ZipOpenError,zipfs.ZipFS,badzip) |