def unsetEnvironment(self): """ Change the Python environment back to what it was before the test was started. """ invalidateImportCaches() sys.modules.clear() sys.modules.update(self.savedModules) sys.path[:] = self.savedPath
def setUp(self, parent=None): invalidateImportCaches() self.oldPath = sys.path[:] self.newPath = sys.path[:] if parent is None: parent = self.mktemp() PackageTest.setUp(self, parent) self.newPath.append(self.parent) self.mangleSysPath(self.newPath)
def test_deployedMode(self): """ The C{dropin.cache} file may not be writable: the cache should still be attainable, but an error should be logged to show that the cache couldn't be updated. """ # Generate the cache plugin.getCache(self.module) cachepath = self.package.child("dropin.cache") # Add a new plugin FilePath(__file__).sibling("plugin_extra1.py").copyTo( self.package.child("pluginextra.py")) invalidateImportCaches() os.chmod(self.package.path, 0o500) # Change the right of dropin.cache too for windows os.chmod(cachepath.path, 0o400) self.addCleanup(os.chmod, self.package.path, 0o700) self.addCleanup(os.chmod, cachepath.path, 0o700) # Start observing log events to see the warning events = [] addObserver(events.append) self.addCleanup(removeObserver, events.append) cache = plugin.getCache(self.module) # The new plugin should be reported self.assertIn("pluginextra", cache) self.assertIn(self.originalPlugin, cache) # Make sure something was logged about the cache. expected = "Unable to write to plugin cache %s: error number %d" % ( cachepath.path, errno.EPERM, ) for event in events: if expected in textFromEventDict(event): break else: self.fail("Did not observe unwriteable cache warning in log " "events: %r" % (events, ))
def test_deployedMode(self): """ The C{dropin.cache} file may not be writable: the cache should still be attainable, but an error should be logged to show that the cache couldn't be updated. """ # Generate the cache plugin.getCache(self.module) cachepath = self.package.child('dropin.cache') # Add a new plugin FilePath(__file__).sibling('plugin_extra1.py' ).copyTo(self.package.child('pluginextra.py')) invalidateImportCaches() os.chmod(self.package.path, 0o500) # Change the right of dropin.cache too for windows os.chmod(cachepath.path, 0o400) self.addCleanup(os.chmod, self.package.path, 0o700) self.addCleanup(os.chmod, cachepath.path, 0o700) # Start observing log events to see the warning events = [] addObserver(events.append) self.addCleanup(removeObserver, events.append) cache = plugin.getCache(self.module) # The new plugin should be reported self.assertIn('pluginextra', cache) self.assertIn(self.originalPlugin, cache) # Make sure something was logged about the cache. expected = "Unable to write to plugin cache %s: error number %d" % ( cachepath.path, errno.EPERM) for event in events: if expected in textFromEventDict(event): break else: self.fail( "Did not observe unwriteable cache warning in log " "events: %r" % (events,))
def setUp(self, parentDir=None): invalidateImportCaches() if parentDir is None: parentDir = self.mktemp() self.parent = parentDir self.createFiles(self.files, parentDir)