def test_returns_false_if_set_many_fails(self): file_path = self._get_config_file() config = ConfigReader(file_path) config.set_many({'name': 'one', 'number': '2'}) with self.subTest('Test returns false if data not in default section'): self.assertListEqual( [config.get('name'), config.get('number')], ['one', 2]) config.reload() with self.subTest(), self.assertRaises(MissingOptionError): config.get('number') data = OrderedDict([('people', 'true'), ('count', 30)]) config.set_many(data, section='demo') with self.subTest( 'Test returns false if data not in specified section'): self.assertDictEqual(config.get_items('demo'), data) config.close(save=True) with ConfigReader(file_path) as d, self.subTest(): self.assertEqual(d.get('people', section='demo'), 'true')
def test_returns_false_if_changes_not_written_to_file(self): file_path = fake.config_file(self.tempdir.path) config = ConfigReader(file_path) config.set('name', 'first') with ConfigReader(file_path) as d, self.subTest(0): with self.assertRaises(MissingOptionError): d.get('name') config.set('name', 'last', commit=True) config.close() d = ConfigReader(file_path) with self.subTest(1): self.assertEqual(d.get('name'), 'last') d.close()