def test_raises_an_error_when_no_value_and_no_default_value( self, mock_log): config = self.make_section_config({}) section = SectionConfig('Name', config, {}, Mock()) with self.assertRaises(ValueError): section.get('option') self.assertTrue(mock_log.warning.called)
def test_warns_when_value_is_wrong_type(self, mock_log): config = self.make_section_config({'option': 'text'}) section = SectionConfig('Name', config, {'option': 42}, Mock()) value = section.get('option') self.assertTrue(mock_log.warning.called) # It should fall back to default value as 'text' is not an int self.assertEqual(42, value)
def test_returns_empty_list_from_previous_empty_configuration(self): # Config from GTG 0.2.4 config = self.make_section_config({ 'opened_tasks': ','}) section = SectionConfig('Name', config, {'opened_tasks': []}, Mock()) value = section.get('opened_tasks') self.assertEqual([], value)
def test_warns_when_value_is_wrong_type(self, mock_log): config = self.make_section_config({"option": "text"}) section = SectionConfig("Name", config, {"option": 42}, Mock()) value = section.get("option") self.assertTrue(mock_log.warning.called) # It should fall back to default value as 'text' is not an int self.assertEqual(42, value)
def test_returns_list_of_tuples(self): # Splitting only by ',' caused bugs # - https://bugs.launchpad.net/gtg/+bug/1218093 # - https://bugs.launchpad.net/gtg/+bug/1216807 config = self.make_section_config({"collapsed_tasks": "('0@1', '6@1'),('0@1', '8@1', '3@1', '5@1')"}) section = SectionConfig("Name", config, {"collapsed_tasks": []}, Mock()) value = section.get("collapsed_tasks") self.assertEqual(["('0@1', '6@1')", "('0@1', '8@1', '3@1', '5@1')"], value)
def test_returns_list_of_tuples(self): # Splitting only by ',' caused bugs # - https://bugs.launchpad.net/gtg/+bug/1218093 # - https://bugs.launchpad.net/gtg/+bug/1216807 config = self.make_section_config( {'collapsed_tasks': "('0@1', '6@1'),('0@1', '8@1', '3@1', '5@1')"}) section = SectionConfig('Name', config, {'collapsed_tasks': []}, Mock()) value = section.get('collapsed_tasks') self.assertEqual(["('0@1', '6@1')", "('0@1', '8@1', '3@1', '5@1')"], value)
def test_warns_when_no_default_value_is_provided(self, mock_log): config = self.make_section_config({'option': '1'}) section = SectionConfig('Name', config, {}, Mock()) value = section.get('option') self.assertEqual('1', value)
def test_returns_empty_list_for_empty_value(self): config = self.make_section_config({'option': ''}) section = SectionConfig('Name', config, {'option': []}, Mock()) value = section.get('option') self.assertEqual([], value)
def test_returns_string_when_expected_string(self): config = self.make_section_config({'option': 'Hello'}) section = SectionConfig('Name', config, {'option': 'World'}, Mock()) value = section.get('option') self.assertEqual(str, type(value)) self.assertEqual('Hello', value)
def test_returns_bool_when_expected_bool(self): config = self.make_section_config({"option": "False"}) section = SectionConfig("Name", config, {"option": False}, Mock()) value = section.get("option") self.assertEqual(bool, type(value)) self.assertEqual(False, value)
def test_warns_when_no_default_value_is_provided(self, mock_log): config = self.make_section_config({"option": "1"}) section = SectionConfig("Name", config, {}, Mock()) value = section.get("option") self.assertTrue(mock_log.warning.called) self.assertEqual("1", value)
def test_raises_an_error_when_no_value_and_no_default_value(self, mock_log): config = self.make_section_config({}) section = SectionConfig("Name", config, {}, Mock()) with self.assertRaises(ValueError): section.get("option") self.assertTrue(mock_log.warning.called)
def test_returns_empty_list_from_previous_empty_configuration(self): # Config from GTG 0.2.4 config = self.make_section_config({"opened_tasks": ","}) section = SectionConfig("Name", config, {"opened_tasks": []}, Mock()) value = section.get("opened_tasks") self.assertEqual([], value)
def test_returns_empty_list_for_empty_value(self): config = self.make_section_config({"option": ""}) section = SectionConfig("Name", config, {"option": []}, Mock()) value = section.get("option") self.assertEqual([], value)
def test_returns_string_when_expected_string(self): config = self.make_section_config({"option": "Hello"}) section = SectionConfig("Name", config, {"option": "World"}, Mock()) value = section.get("option") self.assertEqual(str, type(value)) self.assertEqual("Hello", value)
def test_returns_int_when_expected_int(self): config = self.make_section_config({'option': '42'}) section = SectionConfig('Name', config, {'option': 42}, Mock()) value = section.get('option') self.assertEqual(int, type(value)) self.assertEqual(42, value)
def test_returns_bool_when_expected_bool(self): config = self.make_section_config({'option': 'False'}) section = SectionConfig('Name', config, {'option': False}, Mock()) value = section.get('option') self.assertEqual(bool, type(value)) self.assertEqual(False, value)
def test_returns_int_when_expected_int(self): config = self.make_section_config({"option": "42"}) section = SectionConfig("Name", config, {"option": 42}, Mock()) value = section.get("option") self.assertEqual(int, type(value)) self.assertEqual(42, value)