Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 def test_can_set_value(self):
     config = self.make_section_config({})
     save_mock = Mock()
     section = SectionConfig('Name', config, {}, save_mock)
     section.set('option', 42)
     self.assertEqual('42', config['option'])
     # Automatically saved value
     save_mock.assert_any_call()
Ejemplo n.º 6
0
 def test_can_set_tuple(self):
     config = self.make_section_config({})
     save_mock = Mock()
     section = SectionConfig("Name", config, {}, save_mock)
     section.set("list", (1, 2))
     self.assertEqual("1,2", config["list"])
     # Automatically saved value
     save_mock.assert_any_call()
Ejemplo n.º 7
0
 def test_can_set_list(self):
     config = self.make_section_config({})
     save_mock = Mock()
     section = SectionConfig("Name", config, {}, save_mock)
     section.set("list", [1, True, "Hello"])
     self.assertEqual("1,True,Hello", config["list"])
     # Automatically saved value
     save_mock.assert_any_call()
Ejemplo n.º 8
0
 def test_can_set_value(self):
     config = self.make_section_config({})
     save_mock = Mock()
     section = SectionConfig("Name", config, {}, save_mock)
     section.set("option", 42)
     self.assertEqual("42", config["option"])
     # Automatically saved value
     save_mock.assert_any_call()
Ejemplo n.º 9
0
 def test_can_set_list(self):
     config = self.make_section_config({})
     save_mock = Mock()
     section = SectionConfig('Name', config, {}, save_mock)
     section.set('list', [1, True, 'Hello'])
     self.assertEqual('1,True,Hello', config['list'])
     # Automatically saved value
     save_mock.assert_any_call()
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 def test_can_set_tuple(self):
     config = self.make_section_config({})
     save_mock = Mock()
     section = SectionConfig('Name', config, {}, save_mock)
     section.set('list', (1, 2))
     self.assertEqual('1,2', config['list'])
     # Automatically saved value
     save_mock.assert_any_call()
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
 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)
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 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)
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
 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)
Ejemplo n.º 20
0
 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)
Ejemplo n.º 21
0
 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)
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
 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)
Ejemplo n.º 24
0
 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)