mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 23:26:43 +00:00
Port to Python 3.
This commit is contained in:
parent
bde2f1394d
commit
79ae478a48
@ -1,6 +1,16 @@
|
|||||||
"""
|
"""
|
||||||
Tests for allmydata.util.dictutil.
|
Tests for allmydata.util.dictutil.
|
||||||
|
|
||||||
|
Ported to Python 3.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from future.utils import PY2
|
||||||
|
if PY2:
|
||||||
|
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
@ -37,7 +47,7 @@ class DictUtil(unittest.TestCase):
|
|||||||
# we put the serialized form in the auxdata
|
# we put the serialized form in the auxdata
|
||||||
d.set_with_aux("key", ("filecap", "metadata"), "serialized")
|
d.set_with_aux("key", ("filecap", "metadata"), "serialized")
|
||||||
|
|
||||||
self.failUnlessEqual(d.keys(), ["key"])
|
self.failUnlessEqual(list(d.keys()), ["key"])
|
||||||
self.failUnlessEqual(d["key"], ("filecap", "metadata"))
|
self.failUnlessEqual(d["key"], ("filecap", "metadata"))
|
||||||
self.failUnlessEqual(d.get_aux("key"), "serialized")
|
self.failUnlessEqual(d.get_aux("key"), "serialized")
|
||||||
def _get_missing(key):
|
def _get_missing(key):
|
||||||
@ -55,7 +65,7 @@ class DictUtil(unittest.TestCase):
|
|||||||
d.set_with_aux("key2", "value2", "aux2")
|
d.set_with_aux("key2", "value2", "aux2")
|
||||||
self.failUnlessEqual(sorted(d.keys()), ["key", "key2"])
|
self.failUnlessEqual(sorted(d.keys()), ["key", "key2"])
|
||||||
del d["key2"]
|
del d["key2"]
|
||||||
self.failUnlessEqual(d.keys(), ["key"])
|
self.failUnlessEqual(list(d.keys()), ["key"])
|
||||||
self.failIf("key2" in d)
|
self.failIf("key2" in d)
|
||||||
self.failUnlessRaises(KeyError, _get_missing, "key2")
|
self.failUnlessRaises(KeyError, _get_missing, "key2")
|
||||||
self.failUnlessEqual(d.get("key2"), None)
|
self.failUnlessEqual(d.get("key2"), None)
|
||||||
|
@ -21,6 +21,7 @@ PORTED_MODULES = [
|
|||||||
"allmydata.util.base32",
|
"allmydata.util.base32",
|
||||||
"allmydata.util.base62",
|
"allmydata.util.base62",
|
||||||
"allmydata.util.deferredutil",
|
"allmydata.util.deferredutil",
|
||||||
|
"allmydata.util.dictutil",
|
||||||
"allmydata.util.hashutil",
|
"allmydata.util.hashutil",
|
||||||
"allmydata.util.humanreadable",
|
"allmydata.util.humanreadable",
|
||||||
"allmydata.util.mathutil",
|
"allmydata.util.mathutil",
|
||||||
@ -41,6 +42,7 @@ PORTED_TEST_MODULES = [
|
|||||||
"allmydata.test.test_base32",
|
"allmydata.test.test_base32",
|
||||||
"allmydata.test.test_base62",
|
"allmydata.test.test_base62",
|
||||||
"allmydata.test.test_deferredutil",
|
"allmydata.test.test_deferredutil",
|
||||||
|
"allmydata.test.test_dictutil",
|
||||||
"allmydata.test.test_hashtree",
|
"allmydata.test.test_hashtree",
|
||||||
"allmydata.test.test_hashutil",
|
"allmydata.test.test_hashutil",
|
||||||
"allmydata.test.test_humanreadable",
|
"allmydata.test.test_humanreadable",
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
"""
|
"""
|
||||||
Tools to mess with dicts.
|
Tools to mess with dicts.
|
||||||
|
|
||||||
|
Ported to Python 3.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from future.utils import PY2
|
||||||
|
if PY2:
|
||||||
|
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
class DictOfSets(dict):
|
class DictOfSets(dict):
|
||||||
def add(self, key, value):
|
def add(self, key, value):
|
||||||
@ -10,7 +21,7 @@ class DictOfSets(dict):
|
|||||||
self[key] = set([value])
|
self[key] = set([value])
|
||||||
|
|
||||||
def update(self, otherdictofsets):
|
def update(self, otherdictofsets):
|
||||||
for key, values in otherdictofsets.iteritems():
|
for key, values in otherdictofsets.items():
|
||||||
if key in self:
|
if key in self:
|
||||||
self[key].update(values)
|
self[key].update(values)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user