コード例 #1
0
    def testGetDefault(self):
        params = InputParameters()
        params.add('foo', default=42)
        params.set('foo', 54)
        self.assertEqual(params.getDefault('foo'), 42)

        with self.assertLogs(level='WARNING') as log:
            self.assertIsNone(params.getDefault('bar'))
        self.assertEqual(len(log.output), 1)
        self.assertIn("The parameter 'bar' does not exist", log.output[0])
コード例 #2
0
    def testSetDefault(self):
        params = InputParameters()
        params.add('foo')
        self.assertIsNone(params.get('foo'))
        params.setDefault('foo', 1980)
        self.assertEqual(params.get('foo'), 1980)

        params.add('bar', default=1980)
        params.setDefault('bar', 1949)
        self.assertEqual(params.get('bar'), 1980)
        self.assertEqual(params.getDefault('bar'), 1949)

        with self.assertLogs(level='WARNING') as log:
            params.setDefault('other', 1980)
        self.assertEqual(len(log.output), 1)
        self.assertIn("The parameter 'other' does not exist", log.output[0])