def test_getboolean(self, mock_getboolean): dcp = DefaultConfigParser() mock_getboolean.return_value = True self.assertEqual(dcp.getboolean("section", "option"), True) mock_getboolean.assert_called_with(dcp, "section", "option") mock_getboolean.reset_mock() self.assertEqual( dcp.getboolean("section", "option", default=False, other="test"), True) mock_getboolean.assert_called_with(dcp, "section", "option", other="test") for etype, err in [(ConfigParser.NoOptionError, ConfigParser.NoOptionError(None, None)), (ConfigParser.NoSectionError, ConfigParser.NoSectionError(None))]: mock_getboolean.side_effect = err mock_getboolean.reset_mock() self.assertEqual( dcp.getboolean("section", "option", default=False), False) mock_getboolean.assert_called_with(dcp, "section", "option") mock_getboolean.reset_mock() self.assertRaises(etype, dcp.getboolean, "section", "option") mock_getboolean.assert_called_with(dcp, "section", "option")
def test_get(self, mock_get): dcp = DefaultConfigParser() mock_get.return_value = "foo" self.assertEqual(dcp.get("section", "option"), "foo") mock_get.assert_called_with(dcp, "section", "option") mock_get.reset_mock() self.assertEqual( dcp.get("section", "option", default="bar", other="test"), "foo") mock_get.assert_called_with(dcp, "section", "option", other="test") for etype, err in [(ConfigParser.NoOptionError, ConfigParser.NoOptionError(None, None)), (ConfigParser.NoSectionError, ConfigParser.NoSectionError(None))]: mock_get.side_effect = err mock_get.reset_mock() self.assertEqual(dcp.get("section", "option", default="bar"), "bar") mock_get.assert_called_with(dcp, "section", "option") mock_get.reset_mock() self.assertRaises(etype, dcp.get, "section", "option") mock_get.assert_called_with(dcp, "section", "option")