def testTypeAdapter(self): f = TestFixture() a = adapterOnField(f, 'sampleInt') a.set(a.parse("123456")) self.assertEquals(123456, f.sampleInt) self.assertEquals("-234567", str(a.parse("-234567"))) a = adapterOnMethod(f, "pi") # we do not currently support creating an adapter from a method declaration # a = adapterOnMethod(f, f.__class__.pi) self.assert_(abs(3.14159 - a.invoke()) < 0.00001) self.assertEquals(3.14159862, a.invoke()) a = adapterOnField(f, 'sampleString') a.set(a.parse("xyzzy")) self.assertEquals('xyzzy', f.sampleString) a = adapterOnField(f, 'sampleFloat') a.set(a.parse("6.02e23")) # not sure what the 1e17 is supposed to be here. If it's the epsilon, # the Python version of xUnit does not support it. We can get a # similar effect by inserting a .precision into _typeDict. self.assertEquals(6.02e23, f.sampleFloat) #, 1e17
def testTypeAdapter(self): f = TestFixture() a = adapterOnField(f, "sampleInt") a.set(a.parse("123456")) self.assertEquals(123456, f.sampleInt) self.assertEquals("-234567", str(a.parse("-234567"))) a = adapterOnMethod(f, "pi") # we do not currently support creating an adapter from a method declaration # a = adapterOnMethod(f, f.__class__.pi) self.assert_(abs(3.14159 - a.invoke()) < 0.00001) self.assertEquals(3.14159862, a.invoke()) a = adapterOnField(f, "sampleString") a.set(a.parse("xyzzy")) self.assertEquals("xyzzy", f.sampleString) a = adapterOnField(f, "sampleFloat") a.set(a.parse("6.02e23")) # not sure what the 1e17 is supposed to be here. If it's the epsilon, # the Python version of xUnit does not support it. We can get a # similar effect by inserting a .precision into _typeDict. self.assertEquals(6.02e23, f.sampleFloat) # , 1e17
def testTypeAdapter2(self): # only the phrases that aren't included in the first test f = TestFixture() a = adapterOnField(f, "sampleInteger") a.set(a.parse("54321")) self.assertEquals("54321", str(f.sampleInteger)) # This phrase will never work on Python, since Python does not have a # single character type. ## a = adapterOnField(f, "ch") ## a.set(a.parse("abc")) ## self.assertEquals('a', f.ch) a = adapterOnField(f, "name") a.set(a.parse("xyzzy")) self.assertEquals("xyzzy", f.name) a = adapterOnField(f, "sampleFloat") a.set(a.parse("6.02e23")) self.assertEquals(6.02e23, f.sampleFloat, 1e17) a = adapterOnField(f, "sampleArray") a.set(a.parse("1,2,3")) self.assertEquals(1, f.sampleArray[0]) self.assertEquals(2, f.sampleArray[1]) self.assertEquals(3, f.sampleArray[2]) # following test doesn't work because I'm using the native str() # self.assertEquals("1, 2, 3", a.toString(f.sampleArray)) self.assertEquals("[1, 2, 3]", a.toString(f.sampleArray)) self.assertEquals(a.equals([1, 2, 3], f.sampleArray), 1) # we do not currently have a generic date adapter. # a = TypeAdapterOnField(f, "sampleDate") # date = Date(49,4,26) # a.set(a.parse(DateFormat.getDateInstance().format(date))) # self.assertEquals(date, f.sampleDate) a = adapterOnField(f, "sampleByte") a.set(a.parse("123")) self.assertEquals(123, f.sampleByte) a = adapterOnField(f, "sampleShort") a.set(a.parse("12345")) self.assertEquals(12345, f.sampleShort)
def bindField(self, name): classObj = self.getTargetClass() return adapterOnField(self, name, targetClass=classObj)
def assertBooleanTypeAdapterParses(self, f, booleanString, assertedValue): booleanAdapter = adapterOnField(f, "sampleBoolean") result = booleanAdapter.parse(booleanString) assert result == assertedValue