More passing tests on Python 3.

This commit is contained in:
Itamar Turner-Trauring 2020-12-09 13:50:15 -05:00
parent 6b8fd2f29d
commit 016240d6e6
2 changed files with 25 additions and 18 deletions

View File

@ -468,7 +468,7 @@ class DirectoryNode(object):
exists a child of the given name, False if not."""
name = normalize(namex)
d = self._read()
d.addCallback(lambda children: children.has_key(name))
d.addCallback(lambda children: name in children)
return d
def _get(self, children, name):
@ -569,7 +569,7 @@ class DirectoryNode(object):
# this takes URIs
a = Adder(self, overwrite=overwrite,
create_readonly_node=self._create_readonly_node)
for (namex, e) in entries.iteritems():
for (namex, e) in entries.items():
assert isinstance(namex, unicode), namex
if len(e) == 2:
writecap, readcap = e
@ -779,7 +779,7 @@ class DirectoryNode(object):
# in the nodecache) seem to consume about 2000 bytes.
dirkids = []
filekids = []
for name, (child, metadata) in sorted(children.iteritems()):
for name, (child, metadata) in sorted(children.items()):
childpath = path + [name]
if isinstance(child, UnknownNode):
walker.add_node(child, childpath)

View File

@ -1,4 +1,11 @@
"""Tests for the dirnode module."""
# from __future__ import absolute_import
# from __future__ import division
# from __future__ import print_function
# from __future__ import unicode_literals
from past.builtins import unicode, long
import six
import time
import unicodedata
@ -95,13 +102,13 @@ class Dirnode(GridTestMixin, unittest.TestCase,
self.failUnless(u)
cap_formats = []
if mdmf:
cap_formats = ["URI:DIR2-MDMF:",
"URI:DIR2-MDMF-RO:",
"URI:DIR2-MDMF-Verifier:"]
cap_formats = [b"URI:DIR2-MDMF:",
b"URI:DIR2-MDMF-RO:",
b"URI:DIR2-MDMF-Verifier:"]
else:
cap_formats = ["URI:DIR2:",
"URI:DIR2-RO",
"URI:DIR2-Verifier:"]
cap_formats = [b"URI:DIR2:",
b"URI:DIR2-RO",
b"URI:DIR2-Verifier:"]
rw, ro, v = cap_formats
self.failUnless(u.startswith(rw), u)
u_ro = n.get_readonly_uri()
@ -149,7 +156,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
self.failUnless(isinstance(subdir, dirnode.DirectoryNode))
self.subdir = subdir
new_v = subdir.get_verify_cap().to_string()
assert isinstance(new_v, str)
assert isinstance(new_v, bytes)
self.expected_manifest.append( ((u"subdir",), subdir.get_uri()) )
self.expected_verifycaps.add(new_v)
si = subdir.get_storage_index()
@ -182,7 +189,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
"largest-directory-children": 2,
"largest-immutable-file": 0,
}
for k,v in expected.iteritems():
for k,v in expected.items():
self.failUnlessReallyEqual(stats[k], v,
"stats[%s] was %s, not %s" %
(k, stats[k], v))
@ -272,8 +279,8 @@ class Dirnode(GridTestMixin, unittest.TestCase,
{ 'tahoe': {'linkcrtime': "bogus"}}))
d.addCallback(lambda res: n.get_metadata_for(u"c2"))
def _has_good_linkcrtime(metadata):
self.failUnless(metadata.has_key('tahoe'))
self.failUnless(metadata['tahoe'].has_key('linkcrtime'))
self.failUnless('tahoe' in metadata)
self.failUnless('linkcrtime' in metadata['tahoe'])
self.failIfEqual(metadata['tahoe']['linkcrtime'], 'bogus')
d.addCallback(_has_good_linkcrtime)
@ -918,7 +925,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
self.cap = cap
return dn.list()
d.addCallback(_created_small)
d.addCallback(lambda kids: self.failUnlessReallyEqual(kids.keys(), [u"o"]))
d.addCallback(lambda kids: self.failUnlessReallyEqual(list(kids.keys()), [u"o"]))
# now test n.create_subdirectory(mutable=False)
d.addCallback(lambda ign: c.create_dirnode())
@ -928,7 +935,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
d.addCallback(_check_kids)
d.addCallback(lambda ign: n.list())
d.addCallback(lambda children:
self.failUnlessReallyEqual(children.keys(), [u"subdir"]))
self.failUnlessReallyEqual(list(children.keys()), [u"subdir"]))
d.addCallback(lambda ign: n.get(u"subdir"))
d.addCallback(lambda sd: sd.list())
d.addCallback(_check_kids)
@ -1417,9 +1424,9 @@ class Packing(testutil.ReallyEqualMixin, unittest.TestCase):
def _check_children(self, children):
# Are all the expected child nodes there?
self.failUnless(children.has_key(u'file1'))
self.failUnless(children.has_key(u'file2'))
self.failUnless(children.has_key(u'file3'))
self.failUnless(u'file1' in children)
self.failUnless(u'file2' in children)
self.failUnless(u'file3' in children)
# Are the metadata for child 3 right?
file3_rocap = "URI:CHK:cmtcxq7hwxvfxan34yiev6ivhy:qvcekmjtoetdcw4kmi7b3rtblvgx7544crnwaqtiewemdliqsokq:3:10:5"