SHOW:
|
|
- or go back to the newest paste.
1 | - | class StringIOTest(unittest.TestCase): |
1 | + | import unittest |
2 | ||
3 | - | def setUp(self): |
3 | + | def primes(max_n): |
4 | - | self.buf = StringIO.StringIO(u'Żółw') |
4 | + | found = [2, 3] |
5 | for candidate in xrange(4, max_n + 1): | |
6 | - | def tearDown(self): |
6 | + | for prime in found: |
7 | - | self.buf.close() |
7 | + | if not candidate % prime: |
8 | import pdb; pdb.set_trace() | |
9 | - | def test_buf(self): |
9 | + | break |
10 | - | self.assertEqual(self.buf.getvalue(), u'Żółw') |
10 | + | else: |
11 | - | self.buf.seek(0) |
11 | + | found.append(candidate) |
12 | - | self.assertEqual(self.buf.read(), u'Żółw') |
12 | + | return found |
13 | ||
14 | - | def test_buf_seek(self): |
14 | + | class PrimeTest(unittest.TestCase): |
15 | - | self.buf.seek(2) |
15 | + | |
16 | - | self.assertEqual(self.buf.read(), u'łw') |
16 | + | def test_primes(self): |
17 | actual = primes(20) | |
18 | self.assertEqual(actual, [2, 3, 5, 7, 11, 13, 17, 19]) | |
19 | ||
20 | if __name__ == '__main__': | |
21 | unittest.main() |