github.com/google/grumpy@v0.0.0-20171122020858-3ec87959189c/testing/class_test.py (about) 1 # Copyright 2016 Google Inc. All Rights Reserved. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 16 class Foo(object): 17 18 a = 3 19 assert a == 3 20 21 def bar(self): 22 assert isinstance(self, Foo) 23 return 'bar' 24 25 baz = bar 26 27 28 assert Foo.a == 3 29 30 Foo.a = 4 31 assert Foo.a == 4 32 33 foo = Foo() 34 assert isinstance(foo, Foo) 35 assert foo.a == 4 36 foo.a = 5 37 assert foo.a == 5 38 assert Foo.a == 4 39 assert foo.bar() == 'bar' 40 assert foo.baz() == 'bar' 41 42 foo.b = 10 43 del foo.b 44 assert not hasattr(foo, 'b') 45 try: 46 del foo.b 47 except AttributeError: 48 pass 49 else: 50 raise AssertionError