def testOptionalDefaults(self): class device(object): def __init__(self, name): self.name = name def __cmp__(self, other): return cmp(self.name, other.name) d1 = device('a') d2 = device('b') d3 = device('c') devices = [d1, d2, d3] to_find = device('f') self.assertEqual( 'dummy', find(devices, to_find, default=optional({'name': 'dummy'})).name) x = find(devices, to_find, default=optional({'alma': []})) self.assertEqual(x['alma'], []) self.assertEqual(x['banan'], None)
from mandatory import problem_1, problem_2, problem_3 from optional import main as optional if __name__ == '__main__': problem_1() problem_2() problem_3() optional()
def testOptionalDefaults(self): o = optional({'alma': 42, 'banan': lambda x: x+1}) self.assertIsInstance(o.some_attr, none) self.assertEqual(o.alma, 42) self.assertEqual(o.banan(42), 43)
def testOptional(self): o = optional() self.assertIsInstance(o.some_attr, none) self.assertIsNone(o.some_attr())