contents of tests/test_misc.py
at revision 61 (original) (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 | # -*- coding: utf-8 -*- # # Blackherd Misc Unit Tests # Copyright (C) 2010 Milko Krachounov # # This file is part of Blackherd # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, # copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following # conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # from __future__ import with_statement import blackherd.misc as misc from nose.tools import assert_equal, assert_raises, assert_not_equal import re import os import inspect import tempfile import shutil try: import cStringIO as StringIO except ImportError: import StringIO from .utils import CallableObject, \ ARGS_SET_1, KWARGS_SET_1, ARGS_SET_2, KWARGS_SET_2, \ ARGS_SET_3, KWARGS_SET_3, ARGS_SET_4, KWARGS_SET_4, \ ARGS_SET_5, KWARGS_SET_5 class Descriptor1(object): def __get__(self, instance, owner): return 1, instance, owner class Descriptor2(object): def __get__(self, instance, owner): return 2, instance, owner class BaseClass1(object): pass class BaseClass2(object): pass class D1B1(BaseClass1, Descriptor1): pass class D2B2(BaseClass2, Descriptor2): pass class D2B2x(D2B2, Descriptor1): pass class D2B2xx(D2B2x): pass class D1B1x(D1B1): pass class DescriptorTest(D1B1x, D2B2xx): pass example_text = \ """Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.""" def test_descriptor_get(): cls = type('cls', (), {}) ob = cls() descriptor = DescriptorTest() assert_equal(misc.descriptor_get(descriptor, ob, cls), (2, ob, cls)) assert_equal(misc.descriptor_get(descriptor, ob), (2, ob, cls)) assert_equal(misc.descriptor_get(descriptor, None, cls), (2, None, cls)) descriptor = BaseClass1() assert misc.descriptor_get(descriptor, ob, cls) is descriptor class TestProxyFileObject(): def setup(self): self.strio = StringIO.StringIO() self.on_read = CallableObject() self.on_read_strio = StringIO.StringIO() self.on_read.on_call = self.on_read_strio.write self.on_write = CallableObject() self.on_write_strio = StringIO.StringIO() self.on_write.on_call = self.on_write_strio.write def test_phase_one(self): proxy = misc.ProxyFileObject(self.strio, on_read=self.on_read, on_write=self.on_write) lines = example_text.splitlines(True) proxy.write(lines[0]) proxy.write(lines[1]) assert_equal(self.on_read.times_called, 0) assert_equal(self.on_write.times_called, 2) proxy.writelines(lines[2:]) assert_equal(self.on_read.times_called, 0) assert_equal(self.on_write.times_called, len(lines)) assert_equal(self.on_write_strio.getvalue(), example_text) assert_equal(self.strio.getvalue(), example_text) proxy.seek(0) result = [] result.append(proxy.readline()) assert_equal(self.on_read.times_called, 1) result.extend(proxy.readlines()) assert_equal(self.on_read.times_called, len(lines)) assert_equal(self.on_write.times_called, len(lines)) assert_equal(self.on_read_strio.getvalue(), example_text) assert_equal(result, lines) assert not proxy.closed assert not self.strio.closed proxy.close() assert_raises(ValueError, proxy.write, "abc") assert_raises(ValueError, self.strio.write, "abc") assert proxy.closed assert self.strio.closed def test_phase_two(self): with misc.ProxyFileObject(self.strio, on_read=self.on_read, on_write=self.on_write) as proxy: assert iter(proxy) is proxy lines = example_text.splitlines(True) proxy.writelines(lines) proxy.seek(0) result = [] for line in proxy: result.append(line) assert_equal(self.strio.getvalue(), example_text) assert_equal(self.on_read_strio.getvalue(), example_text) assert_equal(result, lines) assert_equal(self.on_read.times_called, len(lines)) assert_equal(self.on_write.times_called, len(lines)) assert not proxy.closed assert not self.strio.closed assert_raises(ValueError, proxy.write, "abc") assert_raises(ValueError, self.strio.write, "abc") assert proxy.closed assert self.strio.closed def test_phase_three(self): lines = example_text.splitlines(True) exception = Exception() try: with misc.ProxyFileObject(self.strio, on_read=self.on_read, on_write=self.on_write) as proxy: proxy.writelines(lines) proxy.seek(0) size = len(example_text) // 4 result = proxy.read(size) assert_equal(result, example_text[:size]) assert_equal(self.on_read_strio.getvalue(), example_text[:size]) result = proxy.read(size) assert_equal(result, example_text[size:size * 2]) assert_equal(self.on_read_strio.getvalue(), example_text[:size * 2]) assert_equal(self.on_read.times_called, 2) assert not proxy.closed assert not self.strio.closed raise exception except Exception, e: if e is not exception: raise else: raise AssertionError("Exception swallowed") assert proxy.closed assert self.strio.closed assert_raises(ValueError, proxy.write, "abc") assert_raises(ValueError, self.strio.write, "abc") assert_raises(ValueError, proxy.read) assert_raises(ValueError, self.strio.read) def test_phase_four(self): with misc.ProxyFileObject(self.strio, on_read=self.on_read, on_write=self.on_write) as proxy: proxy.write(example_text) proxy.seek(0) result = proxy.read() assert_equal(result, example_text) assert_equal(self.on_write_strio.getvalue(), example_text) assert_equal(self.on_read_strio.getvalue(), example_text) assert_equal(self.on_read.times_called, 1) def test_without_callbacks(self): with misc.ProxyFileObject(self.strio) as proxy: lines = example_text.splitlines(True) proxy.write(lines[0]) assert_equal(self.strio.getvalue(), lines[0]) proxy.writelines(lines[1:]) assert_equal(self.strio.getvalue(), example_text) proxy.seek(0) result = [] result.append(proxy.readline()) assert_equal(result[0], lines[0]) result.extend(proxy.readlines()) assert_equal(result[0], lines[0]) proxy.seek(0) assert_equal(proxy.read(), example_text) proxy.seek(0) size = len(example_text) // 4 assert_equal(proxy.read(size), example_text[:size]) assert_equal(proxy.read(size), example_text[size:size * 2]) proxy.seek(0) result = [] for line in proxy: result.append(line) assert_equal(result, lines) def test_softspace(self): proxy = misc.ProxyFileObject(self.strio) assert proxy.softspace == self.strio.softspace proxy.softspace = 1 assert proxy.softspace == self.strio.softspace == 1 proxy.softspace = 0 assert proxy.softspace == self.strio.softspace == 0 self.strio.softspace = 1 assert proxy.softspace == self.strio.softspace == 1 def test_fileno(self): class File(object): def fileno(self): return 17276 file = File() assert_equal(misc.ProxyFileObject(file, allow_direct=True).fileno(), file.fileno()) assert_raises(IOError, misc.ProxyFileObject(file).fileno) assert_raises(IOError, misc.ProxyFileObject(file, allow_direct=False).fileno) def test_fake_close(self): with misc.ProxyFileObject(self.strio, fake_close=True): pass assert not self.strio.closed misc.ProxyFileObject(self.strio, fake_close=True).close() assert not self.strio.closed misc.ProxyFileObject(self.strio, fake_close=False).close() assert self.strio.closed def test_seek(self): class FileObject(object): def seek(self, *args, **kwargs): self.args = args self.kwargs = kwargs arg0 = object() arg1 = object() fileobj = FileObject() misc.ProxyFileObject(fileobj).seek(arg0, arg1) assert_equal(fileobj.args, (arg0, arg1)) assert_equal(fileobj.kwargs, {}) def test_exceptions(self): proxy = misc.ProxyFileObject(self.strio) assert type(proxy).__enter__(proxy) is proxy proxy.close() assert_raises(ValueError, type(proxy).__enter__, proxy) def test_repr(self): repr(misc.ProxyFileObject(self.strio)) def test_method_dispatch_map(): something = object() callable_ob = CallableObject() class A(object): def __init__(self): self.args1 = None self.kwargs1 = None self.args2 = None self.kwargs2 = None self.args3 = None self.kwargs3 = None methodmap = misc.MethodDispatchMap() assert not methodmap @methodmap.add('apple') def orange(self, *args, **kwargs): self.args1 = args self.kwargs1 = kwargs assert methodmap @methodmap.add() def peach(self, *args, **kwargs): self.args2 = args self.kwargs2 = kwargs @methodmap.add('banana') def fruit(self): pass @methodmap.add() def cherry(self): pass def berry(self, *args, **kwargs): self.args3 = args self.kwargs3 = kwargs assert_equal(len(methodmap), 4) assert 'apple' in methodmap assert 'cherry' in methodmap assert 'bonobo' not in methodmap methodmap['raspberry'] = berry assert_equal(len(methodmap), 5) del methodmap['cherry'] del methodmap['banana'] assert_equal(len(methodmap), 3) assert methodmap assert methodmap['apple'] is orange assert methodmap.get('peach') is peach assert methodmap.get('raspberry') is berry assert methodmap.get('grape') is None assert methodmap.get('fruit', something) is something assert_equal(set(methodmap), set(['apple', 'peach', 'raspberry'])) map_object = staticmethod(methodmap) assert A.methodmap is A.map_object ob = A() ob.methodmap['apple'](*ARGS_SET_1, **KWARGS_SET_1) assert_equal(ob.args1, ARGS_SET_1) assert_equal(ob.kwargs1, KWARGS_SET_1) ob.methodmap['peach'](*ARGS_SET_2, **KWARGS_SET_2) assert_equal(ob.args2, ARGS_SET_2) assert_equal(ob.kwargs2, KWARGS_SET_2) ob.methodmap['raspberry'](*ARGS_SET_3, **KWARGS_SET_3) assert_equal(ob.args3, ARGS_SET_3) assert_equal(ob.kwargs3, KWARGS_SET_3) methodmap_copy = A.methodmap.copy() method = misc.descriptor_get(methodmap_copy, ob, A)['apple'] method(*ARGS_SET_4, **KWARGS_SET_4) assert_equal(ob.args1, ARGS_SET_4) assert_equal(ob.kwargs1, KWARGS_SET_4) del methodmap_copy['apple'] assert_not_equal(set(A.methodmap), set(methodmap_copy)) methodmap_copy.clear() assert_equal(list(methodmap_copy), []) assert 'apple' in ob.methodmap assert 'tangerine' not in ob.methodmap assert ob.methodmap assert not misc.descriptor_get(methodmap_copy, ob, A) assert_equal(len(ob.methodmap), 3) assert_equal(set(ob.methodmap), set(['apple', 'peach', 'raspberry'])) ob.methodmap.get('peach', lambda: None)(*ARGS_SET_5, **KWARGS_SET_5) assert_equal(ob.args2, ARGS_SET_5) assert_equal(ob.kwargs2, KWARGS_SET_5) ob.methodmap.get('larry', callable_ob)(*ARGS_SET_1, **KWARGS_SET_3) assert_equal(callable_ob.args, ARGS_SET_1) assert_equal(callable_ob.kwargs, KWARGS_SET_3) repr(ob.methodmap) repr(A.methodmap) def test_doc_maker(): ob1 = object() class A(object): @misc.doc_maker(ob1) def x(self): return self ob2 = A() assert A.x is ob1 assert ob2.x is ob2 repr(vars(A)['x']) def test_overwriter(): tempdir = tempfile.mkdtemp(prefix=u'bhunittest') try: tempname = tempfile.mktemp(dir=tempdir) for i, mode in enumerate(['w', 'wb']): text1, text2 = example_text.splitlines()[i % 2:i % 2 + 2] with open(tempname, mode) as f: f.write(text1) assert_equal(open(tempname).read(), text1) # Test writing and mode with misc.Overwriter(tempname, mode) as f: f.write(text2) assert_equal(f.mode, mode) assert_equal(open(tempname).read(), text2) # Test correct overwrite with misc.Overwriter(tempname, mode) as f: f.write(text1) f.flush() assert_equal(open(tempname).read(), text2) assert_equal(open(tempname).read(), text1) # Test correct backup with misc.Overwriter(tempname, mode, '~') as f: f.write(text2) assert_equal(open(tempname).read(), text2) assert_equal(open(tempname + '~').read(), text1) # Test correct bailout on error try: e1 = ValueError() with misc.Overwriter(tempname, mode) as f: f.write(text1) f.flush() raise e1 except ValueError, e2: if e2 is not e1: raise assert_equal(open(tempname).read(), text2) # Test truncate with misc.Overwriter(tempname, mode) as f: pass assert_equal(open(tempname).read(), '') # Test input sanitation assert_raises(ValueError, misc.Overwriter, tempname, mode, 'b' + os.sep + 'b') if os.altsep: assert_raises(ValueError, misc.Overwriter, tempname, mode, 'b' + os.altsep + 'b') known_files = [os.path.basename(tempname), os.path.basename(tempname + '~')] assert_equal(os.listdir(tempdir), known_files) finally: shutil.rmtree(tempdir) def test_expanded_doc(): def func(arg1, arg2, arg3=None): pass func.__doc__ = example_text alt_text = example_text[::-1] alt_name = 'munc' class SomeCls(object): pass funclike_ob = SomeCls() funclike_ob.__doc__ = func.__doc__ funclike_ob.__name__ = func.__name__ ob_with_doc = SomeCls() ob_with_doc.__doc__ = func.__doc__ ob_without_doc = SomeCls() ob_without_doc.__doc__ = None shallow_ob = object() variants = [{}] variants = [dict(d, **kw) for d in variants for kw in [{}, {'force': True}, {'force': False}]] variants = [dict(d, **kw) for d in variants for kw in [{}, {'doc': None}, {'doc': alt_text}]] variants = [dict(d, **kw) for d in variants for kw in [{}, {'name': None}, {'name': alt_name}]] variants = [dict(d, **kw) for d in variants for kw in [{}, {'prefix': ''}, {'prefix': example_text}]] for kwargs in variants: prefix = kwargs.get('prefix', '') prefix = re.sub('\s+', ' ', prefix) text = kwargs.get('doc') if text is None: text = example_text text = re.sub('\s+', ' ', text) name = kwargs.get('name') if name is None: name = func.__name__ forced = bool(kwargs.get('force') or kwargs.get('prefix')) custom_doc = bool(kwargs.get('doc')) doc = misc.expanded_doc(func, **kwargs) doc = re.sub('\s+', ' ', doc) argspec = inspect.formatargspec(*inspect.getargspec(func)) argspec = name + argspec + ' ' assert_equal(doc.strip(), (prefix + argspec + text).strip()) doc = misc.expanded_doc(funclike_ob, **kwargs) doc = re.sub('\s+', ' ', doc) if not forced: assert_equal(doc.strip(), text.strip()) continue if kwargs.get('force'): argspec = name + '(...)' else: argspec = '' assert_equal(doc.strip(), (prefix + argspec + ' ' + text).strip()) doc = misc.expanded_doc(ob_with_doc, **kwargs) doc = re.sub('\s+', ' ', doc) assert doc.strip().endswith(text.strip()) assert doc.strip().startswith(prefix.strip()) for ob in [ob_without_doc, shallow_ob]: doc = misc.expanded_doc(ob, **kwargs) if doc is not None: doc = re.sub('\s+', ' ', doc) if custom_doc: assert doc.strip().endswith(text.strip()) else: if not forced: assert doc is None if kwargs.get('prefix'): assert doc.strip().startswith(prefix.strip()) def test_expanded_doc_kwonly_args(): prefix = "abc\ndef" kwonlyargs = ['c', ('d', 6)] doc = "foobar" argspec = '(a, b=5, *args, c, d=6, **kwargs)' def func(a, b=5, *args, **kwargs): pass func.__doc__ = doc result = misc.expanded_doc(func, prefix=prefix, added_kwonlyargs=kwonlyargs) assert_equal(result.strip(), "%sfunc%s\n\n%s" % (prefix, argspec, doc)) argspec = '(a, b=5, *, c, d=6, **kwargs)' def func(a, b=5, **kwargs): pass func.__doc__ = doc result = misc.expanded_doc(func, prefix=prefix, added_kwonlyargs=kwonlyargs) assert_equal(result.strip(), "%sfunc%s\n\n%s" % (prefix, argspec, doc)) saved_functions = {} def save_to(d): def decorator(func): try: name = func.__name__ except AttributeError: name = misc.descriptor_get(func, object(), object).__name__ d[name] = func return func return decorator class _InheritDocBase(object): def attr1(self): """Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do""" @staticmethod def attr2(self): """eiusmod tempor incididunt ut labore et dolore magna aliqua.""" @classmethod def attr3(self): """Ut enim ad minim veniam, quis nostrud exercitation ullamco""" @property def attr4(self): """nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in""" @staticmethod def attr5(self): """reprehenderit in voluptate velit esse cillum dolore eu fugiat""" @classmethod def attr6(self): """pariatur. Excepteur sint occaecat cupidatat non proident, sunt in""" @property def attr7(self): """culpa qui officia deserunt mollit anim id est laborum.""" def _attr8_get(self): """NO DOCSTRING!Q!!!!""" def attr8(self): """Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget""" class TestInheritDoc(_InheritDocBase): functions = {} attributes = {} exception = Exception() @misc.inheritdoc @save_to(attributes) @save_to(functions) def attr1(self, value): self.attr1_value = value @misc.inheritdoc @save_to(attributes) @staticmethod @save_to(functions) def attr2(value): TestInheritDoc.attr2_value = value @misc.inheritdoc @save_to(attributes) @classmethod @save_to(functions) def attr3(cls, value): cls.attr3_value = value @save_to(functions) def _attr4_get(self): return self.attr4_value @save_to(functions) def _attr4_set(self, value): self.attr4_value = value @save_to(functions) def _attr4_del(self): raise self.exception attr4 = property(_attr4_get, _attr4_set, _attr4_del) attr4 = misc.inheritdoc(attr4) @misc.inheritdoc @save_to(attributes) @save_to(functions) def attr5(self, value): self.attr5_value = value @save_to(attributes) @staticmethod @misc.inheritdoc @save_to(functions) def attr6(value): TestInheritDoc.attr6_value = value @save_to(attributes) @classmethod @misc.inheritdoc @save_to(functions) def attr7(cls, value): cls.attr7_value = value @misc.inheritdoc @save_to(functions) def _attr8_get(self): return self.attr8_value @save_to(functions) def _attr8_set(self, value): self.attr8_value = value @save_to(functions) def _attr8_del(self): raise self.exception attr8 = property(_attr8_get, _attr8_set, _attr8_del) properties = [4, 8] def test_docstrings(self): cls = type(self) for i in xrange(1, 9): attr = getattr(cls, 'attr%d' % i) sattr = getattr(super(TestInheritDoc, cls), 'attr%d' % i) assert_equal(attr.__doc__, sattr.__doc__) def test_functionality(self): for i in xrange(1, 9): name = 'attr%d' % i ob = object() if i in self.properties: setattr(self, name, ob) assert getattr(self, name) is ob try: delattr(self, name) except Exception, e: if e is not self.exception: raise else: raise AssertionError("Exception swallowed") else: getattr(self, name)(ob) assert getattr(self, "%s_value" % name) is ob def test_equivalence(self): cls = type(self) for i in xrange(1, 9): name = 'attr%d' % i if i in self.properties: attr = getattr(cls, name) getter = self.functions['_%s_get' % name] setter = self.functions['_%s_set' % name] deleter = self.functions['_%s_del' % name] assert attr.fget is getter assert attr.fset is setter assert attr.fdel is deleter else: func = getattr(self, name) func = getattr(func, 'im_func', func) assert func is self.functions[name], func attr = vars(cls)[name] assert attr is self.attributes[name], attr misc.flagmethods(TestInheritDoc) |
---|