Ticket #6198: pythonpath-contains-6198.patch

File pythonpath-contains-6198.patch, 1.4 KB (added by ephess, 4 years ago)
  • twisted/python/modules.py

     
    708708                return module
    709709        raise KeyError(modname)
    710710
     711    def __contains__(self, module):
     712        """
     713        Check to see whether or not a module exists on my sysPath.
    711714
     715        @param module: The module to look for on my sysPath
     716        """
     717        try:
     718            self.__getitem__(module)
     719            return True
     720        except KeyError:
     721            return False
     722
    712723    def __repr__(self):
    713724        """
    714725        Display my sysPath and moduleDict in a string representation.
  • twisted/test/test_modules.py

     
    492492            "(PEP 302 violation - check your local configuration).")
    493493        self.assertEqual(len(warnings), 1)
    494494        self.assertEqual(thisModule.name, __name__)
     495
     496
     497    def test_containsModule(self):
     498        """
     499        PythonPath should support the __contains__ API to check whether or not
     500        a particular module is on this path.
     501        """
     502        thePath = modules.PythonPath()
     503        self.assertIn('os', thePath)
     504        self.assertNotIn('bogusModule', thePath)