summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-02-17 00:05:46 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-02-17 00:05:46 (GMT)
commitdcbe46bc5bad217e934568cfe59e3e807501acc3 (patch)
tree291cacbf453efa7cb96092c02641a7cff1ce6f1a /Lib
parent7056cb286715e5d5768ef06100d1e5b77c1df6cc (diff)
parentb5c8f927829a1679c6748df84a6289fb68343e51 (diff)
downloadcpython-dcbe46bc5bad217e934568cfe59e3e807501acc3.zip
cpython-dcbe46bc5bad217e934568cfe59e3e807501acc3.tar.gz
cpython-dcbe46bc5bad217e934568cfe59e3e807501acc3.tar.bz2
Merge
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_types.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 3ee4c6b..de0aac2 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -2,6 +2,7 @@
from test.support import run_unittest, run_with_locale
import collections
+import pickle
import locale
import sys
import types
@@ -1077,9 +1078,19 @@ class SimpleNamespaceTests(unittest.TestCase):
ns2 = types.SimpleNamespace()
ns2.x = "spam"
ns2._y = 5
+ name = "namespace"
- self.assertEqual(repr(ns1), "namespace(w=3, x=1, y=2)")
- self.assertEqual(repr(ns2), "namespace(_y=5, x='spam')")
+ self.assertEqual(repr(ns1), "{name}(w=3, x=1, y=2)".format(name=name))
+ self.assertEqual(repr(ns2), "{name}(_y=5, x='spam')".format(name=name))
+
+ def test_equal(self):
+ ns1 = types.SimpleNamespace(x=1)
+ ns2 = types.SimpleNamespace()
+ ns2.x = 1
+
+ self.assertEqual(types.SimpleNamespace(), types.SimpleNamespace())
+ self.assertEqual(ns1, ns2)
+ self.assertNotEqual(ns2, types.SimpleNamespace())
def test_nested(self):
ns1 = types.SimpleNamespace(a=1, b=2)
@@ -1117,11 +1128,12 @@ class SimpleNamespaceTests(unittest.TestCase):
ns1.spam = ns1
ns2.spam = ns3
ns3.spam = ns2
+ name = "namespace"
+ repr1 = "{name}(c='cookie', spam={name}(...))".format(name=name)
+ repr2 = "{name}(spam={name}(spam={name}(...), x=1))".format(name=name)
- self.assertEqual(repr(ns1),
- "namespace(c='cookie', spam=namespace(...))")
- self.assertEqual(repr(ns2),
- "namespace(spam=namespace(spam=namespace(...), x=1))")
+ self.assertEqual(repr(ns1), repr1)
+ self.assertEqual(repr(ns2), repr2)
def test_as_dict(self):
ns = types.SimpleNamespace(spam='spamspamspam')
@@ -1144,6 +1156,14 @@ class SimpleNamespaceTests(unittest.TestCase):
self.assertIs(type(spam), Spam)
self.assertEqual(vars(spam), {'ham': 8, 'eggs': 9})
+ def test_pickle(self):
+ ns = types.SimpleNamespace(breakfast="spam", lunch="spam")
+
+ ns_pickled = pickle.dumps(ns)
+ ns_roundtrip = pickle.loads(ns_pickled)
+
+ self.assertEqual(ns, ns_roundtrip)
+
def test_main():
run_unittest(TypesTests, MappingProxyTests, ClassCreationTests,