summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-03-09 08:44:18 +0000
committerRaymond Hettinger <python@rcn.com>2010-03-09 08:44:18 +0000
commit08090bf36ad25b6fd00fb0fa46368d98e7b3b317 (patch)
treec831aa2589f8659b86bfe6781f2f6672efb06089
parentf4803aa62312db223dd3c59f312b0dfeb8bdaa13 (diff)
downloadcpython-git-08090bf36ad25b6fd00fb0fa46368d98e7b3b317.tar.gz
Improve the basic example.
* Show both the decorator and regular form for assertRaises() * Use assertTrue() instead of assertIn() to teach useful minimal subset of the API
-rw-r--r--Doc/library/unittest.rst10
1 files changed, 7 insertions, 3 deletions
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
index 68ad8ccbf2..5a17d465c3 100644
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -116,14 +116,18 @@ Here is a short script to test three functions from the :mod:`random` module::
self.seq.sort()
self.assertEqual(self.seq, range(10))
+ # should raise an exception for an immutable sequence
+ self.assertRaises(TypeError, random.shuffle, (1,2,3))
+
def test_choice(self):
element = random.choice(self.seq)
- self.assertIn(element, self.seq)
+ self.assertTrue(element in self.seq)
def test_sample(self):
- self.assertRaises(ValueError, random.sample, self.seq, 20)
+ with self.assertRaises(ValueError):
+ random.sample(self.seq, 20)
for element in random.sample(self.seq, 5):
- self.assertIn(element, self.seq)
+ self.assertTrue(element in self.seq)
if __name__ == '__main__':
unittest.main()