Jeremy Hylton | b476d59 | 2009-03-26 21:34:20 +0000 | [diff] [blame^] | 1 | """Unit tests for code in urllib.response.""" |
| 2 | |
| 3 | import test.support |
| 4 | import urllib.response |
| 5 | import unittest |
| 6 | |
| 7 | class TestFile(object): |
| 8 | |
| 9 | def __init__(self): |
| 10 | self.closed = False |
| 11 | |
| 12 | def read(self, bytes): |
| 13 | pass |
| 14 | |
| 15 | def readline(self): |
| 16 | pass |
| 17 | |
| 18 | def close(self): |
| 19 | self.closed = True |
| 20 | |
| 21 | class Testaddbase(unittest.TestCase): |
| 22 | |
| 23 | # TODO(jhylton): Write tests for other functionality of addbase() |
| 24 | |
| 25 | def setUp(self): |
| 26 | self.fp = TestFile() |
| 27 | self.addbase = urllib.response.addbase(self.fp) |
| 28 | |
| 29 | def test_with(self): |
| 30 | def f(): |
| 31 | with self.addbase as spam: |
| 32 | pass |
| 33 | self.assertFalse(self.fp.closed) |
| 34 | f() |
| 35 | self.assertTrue(self.fp.closed) |
| 36 | self.assertRaises(ValueError, f) |
| 37 | |
| 38 | def test_main(): |
| 39 | test.support.run_unittest(Testaddbase) |
| 40 | |
| 41 | if __name__ == '__main__': |
| 42 | test_main() |