Persist False value for defeat_cache correctly

If cdparanoia can't work around the audio caching of a drive,
defeats_cache = False is written to the config.  However, when it is
read back the string 'False' ends up being converted to True (as it is
not an empty string).

This corrects the behaviour when reading the value back and adds tests
to make sure that both True and False can be correctly retrieved from
the config.
This commit is contained in:
Matt Robinson
2016-12-31 17:48:21 +00:00
parent 976e1bdca2
commit 3f9cc77e30
2 changed files with 18 additions and 2 deletions

View File

@@ -113,7 +113,7 @@ class Config:
section = self._findDriveSection(vendor, model, release)
try:
return bool(self._parser.get(section, 'defeats_cache'))
return self._parser.get(section, 'defeats_cache') == 'True'
except ConfigParser.NoOptionError:
raise KeyError("Could not find defeats_cache for %s/%s/%s" % (
vendor, model, release))

View File

@@ -9,7 +9,7 @@ from morituri.common import config
from morituri.test import common as tcommon
class OffsetTestCase(tcommon.TestCase):
class ConfigTestCase(tcommon.TestCase):
def setUp(self):
fd, self._path = tempfile.mkstemp(suffix=u'.morituri.test.config')
@@ -50,3 +50,19 @@ class OffsetTestCase(tcommon.TestCase):
offset = self._config.getReadOffset(
'Slimtype', 'eSAU208 2 ', 'ML03')
self.assertEquals(offset, 6)
def testDefeatsCache(self):
self.assertRaises(KeyError, self._config.getDefeatsCache,
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self._config.setDefeatsCache(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05', False)
defeats = self._config.getDefeatsCache(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self.assertEquals(defeats, False)
self._config.setDefeatsCache(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05', True)
defeats = self._config.getDefeatsCache(
'PLEXTOR ', 'DVDR PX-L890SA', '1.05')
self.assertEquals(defeats, True)