twisted.trial.runner.filenameToModule

Here are the examples of the python api twisted.trial.runner.filenameToModule taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

14 Examples 7

Example 1

Project: mythbox Source File: test_loader.py
Function: test_filenamematchespackage
    def test_filenameMatchesPackage(self):
        filename = os.path.join(self.parent, 'goodpackage.py')
        fd = open(filename, 'w')
        fd.write(packages.testModule)
        fd.close()
        try:
            module = runner.filenameToModule(filename)
            self.failUnlessEqual(filename, module.__file__)
        finally:
            os.remove(filename)

Example 2

Project: mythbox Source File: test_loader.py
    def test_directory(self):
        """
        Test loader against a filesystem directory. It should handle
        'path' and 'path/' the same way.
        """
        path  = util.sibpath(__file__, 'goodDirectory')
        os.mkdir(path)
        f = file(os.path.join(path, '__init__.py'), "w")
        f.close()
        try:
            module = runner.filenameToModule(path)
            self.assert_(module.__name__.endswith('goodDirectory'))
            module = runner.filenameToModule(path + os.path.sep)
            self.assert_(module.__name__.endswith('goodDirectory'))
        finally:
            shutil.rmtree(path)

Example 3

Project: SubliminalCollaborator Source File: test_loader.py
Function: test_filenamematchespackage
    def test_filenameMatchesPackage(self):
        filename = os.path.join(self.parent, 'goodpackage.py')
        fd = open(filename, 'w')
        fd.write(packages.testModule)
        fd.close()
        try:
            module = runner.filenameToModule(filename)
            self.assertEqual(filename, module.__file__)
        finally:
            os.remove(filename)

Example 4

Project: mythbox Source File: test_loader.py
Function: test_not_file
    def test_notFile(self):
        self.failUnlessRaises(ValueError,
                              runner.filenameToModule, 'doesntexist')

Example 5

Project: mythbox Source File: test_loader.py
    def test_moduleInPath(self):
        sample1 = runner.filenameToModule(util.sibpath(__file__, 'sample.py'))
        import sample as sample2
        self.failUnlessEqual(sample2, sample1)

Example 6

Project: mythbox Source File: test_loader.py
Function: test_modulenotinpath
    def test_moduleNotInPath(self):
        """
        If passed the path to a file containing the implementation of a
        module within a package which is not on the import path,
        L{runner.filenameToModule} returns a module object loosely
        resembling the module defined by that file anyway.
        """
        # "test_sample" isn't actually the name of this module.  However,
        # filenameToModule can't seem to figure that out.  So clean up this
        # mis-named module.  It would be better if this weren't necessary
        # and filenameToModule either didn't exist or added a correctly
        # named module to sys.modules.
        self.addCleanup(sys.modules.pop, 'test_sample', None)

        self.mangleSysPath(self.oldPath)
        sample1 = runner.filenameToModule(
            os.path.join(self.parent, 'goodpackage', 'test_sample.py'))
        self.mangleSysPath(self.newPath)
        from goodpackage import test_sample as sample2
        self.failUnlessEqual(os.path.splitext(sample2.__file__)[0],
                             os.path.splitext(sample1.__file__)[0])

Example 7

Project: mythbox Source File: test_loader.py
Function: test_packageinpath
    def test_packageInPath(self):
        package1 = runner.filenameToModule(os.path.join(self.parent,
                                                        'goodpackage'))
        import goodpackage
        self.failUnlessEqual(goodpackage, package1)

Example 8

Project: mythbox Source File: test_loader.py
Function: test_packagenotinpath
    def test_packageNotInPath(self):
        """
        If passed the path to a directory which represents a package which
        is not on the import path, L{runner.filenameToModule} returns a
        module object loosely resembling the package defined by that
        directory anyway.
        """
        # "__init__" isn't actually the name of the package!  However,
        # filenameToModule is pretty stupid and decides that is its name
        # after all.  Make sure it gets cleaned up.  See the comment in
        # test_moduleNotInPath for possible courses of action related to
        # this.
        self.addCleanup(sys.modules.pop, "__init__")

        self.mangleSysPath(self.oldPath)
        package1 = runner.filenameToModule(
            os.path.join(self.parent, 'goodpackage'))
        self.mangleSysPath(self.newPath)
        import goodpackage
        self.failUnlessEqual(os.path.splitext(goodpackage.__file__)[0],
                             os.path.splitext(package1.__file__)[0])

Example 9

Project: mythbox Source File: test_loader.py
    def test_directoryNotPackage(self):
        self.failUnlessRaises(ValueError, runner.filenameToModule,
                              util.sibpath(__file__, 'directory'))

Example 10

Project: mythbox Source File: test_loader.py
    def test_filenameNotPython(self):
        self.failUnlessRaises(ValueError, runner.filenameToModule,
                              util.sibpath(__file__, 'notpython.py'))

Example 11

Project: SubliminalCollaborator Source File: test_loader.py
    def test_moduleInPath(self):
        sample1 = runner.filenameToModule(util.sibpath(__file__, 'sample.py'))
        import sample as sample2
        self.assertEqual(sample2, sample1)

Example 12

Project: SubliminalCollaborator Source File: test_loader.py
    def test_moduleNotInPath(self):
        """
        If passed the path to a file containing the implementation of a
        module within a package which is not on the import path,
        L{runner.filenameToModule} returns a module object loosely
        resembling the module defined by that file anyway.
        """
        # "test_sample" isn't actually the name of this module.  However,
        # filenameToModule can't seem to figure that out.  So clean up this
        # mis-named module.  It would be better if this weren't necessary
        # and filenameToModule either didn't exist or added a correctly
        # named module to sys.modules.
        self.addCleanup(sys.modules.pop, 'test_sample', None)

        self.mangleSysPath(self.oldPath)
        sample1 = runner.filenameToModule(
            os.path.join(self.parent, 'goodpackage', 'test_sample.py'))
        self.mangleSysPath(self.newPath)
        from goodpackage import test_sample as sample2
        self.assertEqual(os.path.splitext(sample2.__file__)[0],
                             os.path.splitext(sample1.__file__)[0])

Example 13

Project: SubliminalCollaborator Source File: test_loader.py
Function: test_packageinpath
    def test_packageInPath(self):
        package1 = runner.filenameToModule(os.path.join(self.parent,
                                                        'goodpackage'))
        import goodpackage
        self.assertEqual(goodpackage, package1)

Example 14

Project: SubliminalCollaborator Source File: test_loader.py
    def test_packageNotInPath(self):
        """
        If passed the path to a directory which represents a package which
        is not on the import path, L{runner.filenameToModule} returns a
        module object loosely resembling the package defined by that
        directory anyway.
        """
        # "__init__" isn't actually the name of the package!  However,
        # filenameToModule is pretty stupid and decides that is its name
        # after all.  Make sure it gets cleaned up.  See the comment in
        # test_moduleNotInPath for possible courses of action related to
        # this.
        self.addCleanup(sys.modules.pop, "__init__")

        self.mangleSysPath(self.oldPath)
        package1 = runner.filenameToModule(
            os.path.join(self.parent, 'goodpackage'))
        self.mangleSysPath(self.newPath)
        import goodpackage
        self.assertEqual(os.path.splitext(goodpackage.__file__)[0],
                             os.path.splitext(package1.__file__)[0])