diff --git a/nss_cache/caches/caches_test.py b/nss_cache/caches/caches_test.py index c7b37514..85c72870 100644 --- a/nss_cache/caches/caches_test.py +++ b/nss_cache/caches/caches_test.py @@ -81,11 +81,14 @@ class TestCache(unittest.TestCase): def testWriteMap(self): cache_map = caches.Cache({}, config.MAP_PASSWORD, None) - with mock.patch.object(cache_map, 'Write') as write, mock.patch.object(cache_map, 'Verify') as verify, mock.patch.object(cache_map, '_Commit') as commit: + with mock.patch.object(cache_map, 'Write') as write, mock.patch.object( + cache_map, + 'Verify') as verify, mock.patch.object(cache_map, + '_Commit') as commit: write.return_value = 'entries_written' verify.return_value = True self.assertEqual(0, cache_map.WriteMap('writable_map')) - + if __name__ == '__main__': unittest.main() diff --git a/nss_cache/caches/files_test.py b/nss_cache/caches/files_test.py index 09662cf0..0e4c9856 100644 --- a/nss_cache/caches/files_test.py +++ b/nss_cache/caches/files_test.py @@ -90,7 +90,8 @@ def testWritePasswdEntry(self): map_entry.shell = '/bin/bash' cache._WriteData(file_mock, map_entry) - file_mock.write.assert_called_with(b'root:x:0:0:Rootsy:/root:/bin/bash\n') + file_mock.write.assert_called_with( + b'root:x:0:0:Rootsy:/root:/bin/bash\n') def testWriteGroupEntry(self): """We correctly write a typical entry in /etc/group format.""" @@ -128,7 +129,8 @@ def testWriteNetgroupEntry(self): map_entry.entries = 'unix_admins noc_monkeys (-,zero_cool,)' cache._WriteData(file_mock, map_entry) - file_mock.write.assert_called_with(b'administrators unix_admins noc_monkeys (-,zero_cool,)\n') + file_mock.write.assert_called_with( + b'administrators unix_admins noc_monkeys (-,zero_cool,)\n') def testWriteAutomountEntry(self): """We correctly write a typical entry in /etc/auto.* format.""" @@ -141,7 +143,8 @@ def testWriteAutomountEntry(self): map_entry.location = 'fileserver:/scratch' cache._WriteData(file_mock, map_entry) - file_mock.write.assert_called_with(b'scratch -tcp,rw,intr,bg fileserver:/scratch\n') + file_mock.write.assert_called_with( + b'scratch -tcp,rw,intr,bg fileserver:/scratch\n') file_mock = mock.create_autospec(sys.stdout) map_entry = automount.AutomountMapEntry() diff --git a/nss_cache/lock_test.py b/nss_cache/lock_test.py index aa4c414c..f8628ee9 100644 --- a/nss_cache/lock_test.py +++ b/nss_cache/lock_test.py @@ -82,14 +82,16 @@ def testHandleArgumentsProperly(self): def testDestructorUnlocks(self): yes = lock.PidFile() - with mock.patch.object(yes, 'Locked') as locked, mock.patch.object(yes, 'Unlock') as unlock: + with mock.patch.object(yes, 'Locked') as locked, mock.patch.object( + yes, 'Unlock') as unlock: locked.return_value = True yes.__del__() # Destructor should unlock unlock.assert_called_once() no = lock.PidFile() - with mock.patch.object(no, 'Locked') as locked, mock.patch.object(yes, 'Unlock') as unlock: + with mock.patch.object(no, 'Locked') as locked, mock.patch.object( + yes, 'Unlock') as unlock: locked.return_value = False no.__del__() # No unlock needed if already not locked. @@ -119,11 +121,13 @@ def testLockCreatesPidfiles(self): def testLockLocksWithFcntl(self): locker = lock.PidFile(pid='PID') - with mock.patch.object(locker, '_file') as f, mock.patch('fcntl.lockf') as lockf: + with mock.patch.object( + locker, '_file') as f, mock.patch('fcntl.lockf') as lockf: locker.Lock() self.assertTrue(locker._locked) - lockf.assert_called_once_with(locker._file, fcntl.LOCK_EX | fcntl.LOCK_NB) + lockf.assert_called_once_with(locker._file, + fcntl.LOCK_EX | fcntl.LOCK_NB) def testLockStoresPid(self): locker = lock.PidFile(filename=self.filename, pid='PID') @@ -140,31 +144,40 @@ def testLockStoresPid(self): def testLockTrapsPermissionDeniedOnly(self): locker = lock.PidFile() with mock.patch.object(locker, '_Open') as open: - open.side_effect = [IOError(errno.EACCES, ''), IOError(errno.EIO, '')] + open.side_effect = [ + IOError(errno.EACCES, ''), + IOError(errno.EIO, '') + ] self.assertEqual(False, locker.Lock()) self.assertRaises(IOError, locker.Lock) def testForceLockTerminatesAndClearsLock(self): locker = lock.PidFile(pid='PID') - with mock.patch.object(locker, 'SendTerm'), mock.patch.object(locker, 'ClearLock'), mock.patch.object(locker, '_file') as f: + with mock.patch.object(locker, 'SendTerm'), mock.patch.object( + locker, 'ClearLock'), mock.patch.object(locker, '_file') as f: with mock.patch('fcntl.lockf') as lockf: # This is a little weird due to recursion. # The first time through lockf throws an error and we retry the lock. # The 2nd time through we should fail, because lockf will still throw # an error, so we expect False back and the above mock objects # invoked. - lockf.side_effect = [IOError(errno.EAGAIN, ''), IOError(errno.EAGAIN, '')] + lockf.side_effect = [ + IOError(errno.EAGAIN, ''), + IOError(errno.EAGAIN, '') + ] self.assertFalse(locker.Lock(force=True)) - lockf.assert_has_calls((mock.call(locker._file, fcntl.LOCK_EX | fcntl.LOCK_NB), - mock.call(locker._file, fcntl.LOCK_EX | fcntl.LOCK_NB))) + lockf.assert_has_calls( + (mock.call(locker._file, fcntl.LOCK_EX | fcntl.LOCK_NB), + mock.call(locker._file, fcntl.LOCK_EX | fcntl.LOCK_NB))) def testSendTermMatchesCommandAndSendsTerm(self): locker = lock.PidFile() # Program mocks mock_re = mock.create_autospec(re.Pattern) mock_re.match.return_value = True - with mock.patch('re.compile') as regexp, mock.patch('os.kill') as kill, mock.patch.object(locker, '_file') as f: + with mock.patch('re.compile') as regexp, mock.patch( + 'os.kill') as kill, mock.patch.object(locker, '_file') as f: f.read.return_value = '1234' regexp.return_value = mock_re @@ -191,7 +204,8 @@ def testSendTermMatchesCommandAndSendsTerm(self): def testSendTermNoPid(self): locker = lock.PidFile() - with mock.patch.object(locker, '_file') as f, mock.patch('os.kill') as kill: + with mock.patch.object(locker, + '_file') as f, mock.patch('os.kill') as kill: f.read.return_value = '\n' locker.PROC = self.workdir locker.SendTerm() @@ -200,7 +214,8 @@ def testSendTermNoPid(self): def testSendTermNonePid(self): locker = lock.PidFile() - with mock.patch.object(locker, '_file') as f, mock.patch('os.kill') as kill: + with mock.patch.object(locker, + '_file') as f, mock.patch('os.kill') as kill: f.read.return_value = None locker.PROC = self.workdir locker.SendTerm() @@ -209,7 +224,8 @@ def testSendTermNonePid(self): def testSendTermTrapsENOENT(self): locker = lock.PidFile() - with mock.patch.object(locker, '_file') as f, mock.patch('os.kill') as kill, mock.patch('builtins.open') as mock_open: + with mock.patch.object(locker, '_file') as f, mock.patch( + 'os.kill') as kill, mock.patch('builtins.open') as mock_open: f.read.return_value = '1234\n' mock_open.side_effect = IOError(errno.ENOENT, '') # self.workdir/1234/cmdline should not exist :) diff --git a/nss_cache/util/timestamps_test.py b/nss_cache/util/timestamps_test.py index 773c767c..a380049b 100644 --- a/nss_cache/util/timestamps_test.py +++ b/nss_cache/util/timestamps_test.py @@ -67,7 +67,7 @@ def testReadTimestampInFuture(self): with mock.patch('time.gmtime') as gmtime: gmtime.return_value = now ts = timestamps.ReadTimestamp(ts_filename) - self.assertEqual(now, ts) + self.assertEqual(now, ts) def testWriteTimestamp(self): ts_filename = os.path.join(self.workdir, 'tsw')