Re: [Pyobjc-dev] testing NSCell
Brought to you by:
ronaldoussoren
From: <bb...@ma...> - 2003-02-04 19:39:44
|
Tests committed as 'test_nscell.py' in Lib/AppKit/test/. I refactored the tests slightly... have a look, they have been comitted. There is definitely a bug -- but it may be fallout from using an NSCell outside of a true application [NSCell is one of the "weird ones", IIRC]. Specifically, -floatValue and -intValue are always returning 0. >>> from AppKit import * >>> c = NSCell.alloc().init() >>> c.setIntValue_(5) >>> c.intValue() 0 >>> c.stringValue() '' >>> c.setStringValue_('5') >>> c.intValue() 5 >>> c.stringValue() '5' >>> Huh? Specific problem appears to be with setIntValue_()... how odd. str(), unicode(), int(), and float() should not work directly on a cell instance. A Cell is not really a data container. It is a thing that draws stuff [and may support editing/clicking]. That it can contain data is one of its features, but not a primary feature and not intended for persistence [example: a single cell may be used to draw all of the geographic cells in a single column of a table view]. As such, you should generally use the *Value() query methods. Of course, with that said, it would be trivial to add mappings between the various *Value() methods and the appropriate __python method__. Something like... CONVENIENCE_METHODS['floatValue'] = ( ('__float__', lambda self: self.floatValue()), ) While trivial, I'm not really sure we *should* add such convenience hooks -- I'm exactly on the fence. What is the Properly Pythonic answer? b.bum On Tuesday, Feb 4, 2003, at 14:16 US/Eastern, David Eppstein wrote: > Which if any of the following tests should fail? Currently, they all > do. > > import unittest > import objc > > from AppKit import NSCell > > class TestNSCell(unittest.TestCase): > cell = NSCell.alloc().init() > > def testString(self): > s = 'string' > self.cell.setStringValue_(s) > assert(self.cell.stringValue() == s) > assert(str(self.cell) == s) > > def testUnicode(self): > u = u'\xc3\xbc\xc3\xb1\xc3\xae\xc3\xa7\xc3\xb8d\xc3\xa8' > self.cell.setStringValue_(u) > assert(self.cell.stringValue() == u) > assert(unicode(self.cell) == u) > > def testInt(self): > i = 17 > self.cell.setIntValue_(i) > assert(self.cell.intValue() == i) > assert(int(self.cell) == i) > > def testFloat(self): > f = 3.14159 > self.cell.setFloatValue_(f) > assert(self.cell.floatValue() == f) > assert(float(self.cell) == f) > > def suite(): > suite = unittest.TestSuite() > suite.addTest(unittest.makeSuite(TestNSCell)) > return suite > > if __name__ == '__main__': > unittest.main( ) > > -- > David Eppstein UC Irvine Dept. of Information & Computer Science > epp...@ic... http://www.ics.uci.edu/~eppstein/ > > > > ------------------------------------------------------- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! > http://www.vasoftware.com > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > b.bum No Chunks... ... No Foul! |