views:

76

answers:

1

Given:

class A:
 pass
class B(A):
 pass

isinstance(B(), A) will return True.

BUT

class MyModel(db.Model):
    pass

isinstance(MyModel(), db.Model) returns False(surely True?).

What am I missing?

Edit: Ok, simplest test that fails- created a blank GAE project. Inside main.py I've defined:

from google.appengine.ext import db  

class MyModel(db.Model):  
    detail = db.StringProperty()  

Then I've created a test file (test_ami.py) which contains the following:

import unittest  
from main import MyModel  
from google.appengine.ext import db  

class TestAmI(unittest.TestCase):  
    def test_whatami(self):  
        m = MyModel()  
        self.assertEquals(True, isinstance(m, db.Model));  
        self.assertEquals(True, isinstance(MyModel(), db.Model));  

On the command line: nosetests --with-gae results in:
File "test_ami.py", line 8, in test_whatami self.assertEquals(True, isinstance(m, db.Model)) AssertionError: True != False

Line 8 is: self.assertEquals(True, isinstance(m, db.Model));

+3  A: 

isinstance(B(), A) will return True.

That seems unlikely, since in your class definition, B doesn't extend A.

isinstance(MyModel(), db.Model) returns False(surely True?).

Testing this on shell.appspot.com, it returns True, as expected.

Nick Johnson
sorry, typo edited. issue remains though.
bryanallott
As I say, testing this on shell.appspot.com returns the expected result, so clearly you're doing something different from the example you've shown. You should reduce your own code to the simplest test case that reproduces the problem.
Nick Johnson
simplest test that fails.. yes, great idea- done that. still failing.
bryanallott
It still works just fine on shell.appspot.com. Try eliminating the testing framework and other variables.
Nick Johnson
well, i kinda need it pass with the unittest in place.. it's where the anomaly raised it's head in the first place. interestingly, if i declare MyModel in the same file as TestAmI, it passes. looks like it might be time for a different question soon...?
bryanallott