From 3f9cc77e3098a4d023eb28d00124593f96683a5d Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Sat, 31 Dec 2016 17:48:21 +0000 Subject: [PATCH] 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. --- morituri/common/config.py | 2 +- morituri/test/test_common_config.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/morituri/common/config.py b/morituri/common/config.py index d9229e6..66e2399 100644 --- a/morituri/common/config.py +++ b/morituri/common/config.py @@ -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)) diff --git a/morituri/test/test_common_config.py b/morituri/test/test_common_config.py index 2930c1f..a90f8a1 100644 --- a/morituri/test/test_common_config.py +++ b/morituri/test/test_common_config.py @@ -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)