OLD | NEW |
1 import re | 1 import re |
2 import sys | 2 import sys |
3 import types | 3 import types |
4 import unittest | 4 import unittest |
5 import inspect | 5 import inspect |
6 import linecache | 6 import linecache |
7 import datetime | 7 import datetime |
8 import collections | 8 import collections |
9 from os.path import normcase | 9 from os.path import normcase |
10 | 10 |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 def test_findsource_binary(self): | 378 def test_findsource_binary(self): |
379 self.assertRaises(IOError, inspect.getsource, unicodedata) | 379 self.assertRaises(IOError, inspect.getsource, unicodedata) |
380 self.assertRaises(IOError, inspect.findsource, unicodedata) | 380 self.assertRaises(IOError, inspect.findsource, unicodedata) |
381 | 381 |
382 def test_findsource_code_in_linecache(self): | 382 def test_findsource_code_in_linecache(self): |
383 lines = ["x=1"] | 383 lines = ["x=1"] |
384 co = compile(lines[0], "_dynamically_created_file", "exec") | 384 co = compile(lines[0], "_dynamically_created_file", "exec") |
385 self.assertRaises(IOError, inspect.findsource, co) | 385 self.assertRaises(IOError, inspect.findsource, co) |
386 self.assertRaises(IOError, inspect.getsource, co) | 386 self.assertRaises(IOError, inspect.getsource, co) |
387 linecache.cache[co.co_filename] = (1, None, lines, co.co_filename) | 387 linecache.cache[co.co_filename] = (1, None, lines, co.co_filename) |
388 self.assertEquals(inspect.findsource(co), (lines,0)) | 388 self.assertEqual(inspect.findsource(co), (lines,0)) |
389 self.assertEquals(inspect.getsource(co), lines[0]) | 389 self.assertEqual(inspect.getsource(co), lines[0]) |
390 | 390 |
391 # Helper for testing classify_class_attrs. | 391 # Helper for testing classify_class_attrs. |
392 def attrs_wo_objs(cls): | 392 def attrs_wo_objs(cls): |
393 return [t[:3] for t in inspect.classify_class_attrs(cls)] | 393 return [t[:3] for t in inspect.classify_class_attrs(cls)] |
394 | 394 |
395 class TestClassesAndFunctions(unittest.TestCase): | 395 class TestClassesAndFunctions(unittest.TestCase): |
396 def test_newstyle_mro(self): | 396 def test_newstyle_mro(self): |
397 # The same w/ new-class MRO. | 397 # The same w/ new-class MRO. |
398 class A(object): pass | 398 class A(object): pass |
399 class B(A): pass | 399 class B(A): pass |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 def test_main(): | 858 def test_main(): |
859 run_unittest( | 859 run_unittest( |
860 TestDecorators, TestRetrievingSourceCode, TestOneliners, TestBuggyCases, | 860 TestDecorators, TestRetrievingSourceCode, TestOneliners, TestBuggyCases, |
861 TestInterpreterStack, TestClassesAndFunctions, TestPredicates, | 861 TestInterpreterStack, TestClassesAndFunctions, TestPredicates, |
862 TestGetcallargsFunctions, TestGetcallargsMethods, | 862 TestGetcallargsFunctions, TestGetcallargsMethods, |
863 TestGetcallargsUnboundMethods, TestGetattrStatic | 863 TestGetcallargsUnboundMethods, TestGetattrStatic |
864 ) | 864 ) |
865 | 865 |
866 if __name__ == "__main__": | 866 if __name__ == "__main__": |
867 test_main() | 867 test_main() |
OLD | NEW |