コード例 #1
0
    def test_unknown_protocol(self):
        """ unknown protocol """

        # Open an HTTP document resource.
        rm = ResourceManager()

        with self.assertRaises(ValueError):
            rm.file("bogus://foo/bar/baz")
コード例 #2
0
    def test_no_such_http_resource(self):
        """ no such http resource """

        # Open an HTTP document resource.
        rm = ResourceManager()

        with self.assertRaises(NoSuchResourceError):
            rm.file("http://localhost:1234/bogus.dat")
コード例 #3
0
    def test_no_such_file_resource(self):
        """ no such file resource """

        rm = ResourceManager()

        # Open a file resource.
        with self.assertRaises(NoSuchResourceError):
            rm.file("file://../bogus.py")
コード例 #4
0
    def test_http_resource(self):
        """ http resource """

        # Open an HTTP document resource.
        rm = ResourceManager()

        f = rm.file("http://localhost:1234/file.dat")
        self.assertNotEqual(f, None)
        contents = f.read()
        f.close()

        self.assertEqual(contents, "This is a test file.\n")
コード例 #5
0
    def test_http_resource(self):
        """ http resource """

        # Open an HTTP document resource.
        rm = ResourceManager()

        f = rm.file("http://localhost:1234/file.dat")
        self.assertNotEqual(f, None)
        contents = f.read()
        f.close()

        self.assertEquals(contents, "This is a test file.\n")

        return
コード例 #6
0
    def test_package_resource(self):
        """ package resource """

        rm = ResourceManager()

        # Open a package resource.
        f = rm.file("pkgfile://envisage.resource/api.py")
        self.assertNotEqual(f, None)
        contents = f.read()
        f.close()

        # Get the bytes of the 'api.py' file.
        resource = files("envisage.resource") / "api.py"
        with resource.open("rb") as g:
            self.assertEqual(g.read(), contents)
コード例 #7
0
    def test_file_resource(self):
        """ file resource """

        rm = ResourceManager()

        # Get the filename of the 'api.py' file.
        filename = resource_filename('envisage.resource', 'api.py')

        # Open a file resource.
        f = rm.file('file://' + filename)
        self.assertNotEqual(f, None)
        contents = f.read()
        f.close()

        # Open the api file via the file system.
        with open(filename, 'rb') as g:
            self.assertEqual(g.read(), contents)
コード例 #8
0
    def test_package_resource(self):
        """ package resource """

        rm = ResourceManager()

        # Open a package resource.
        f = rm.file("pkgfile://envisage.resource/api.py")
        self.assertNotEqual(f, None)
        contents = f.read()
        f.close()

        # Get the filename of the 'api.py' file.
        filename = resource_filename("envisage.resource", "api.py")

        # Open the api file via the file system.
        with open(filename, "rb") as g:
            self.assertEqual(g.read(), contents)
コード例 #9
0
    def test_package_resource(self):
        """ package resource """

        rm = ResourceManager()

        # Open a package resource.
        f = rm.file('pkgfile://envisage.resource/api.py')
        self.assertNotEqual(f, None)
        contents = f.read()
        f.close()

        # Get the filename of the 'api.py' file.
        filename = resource_filename('envisage.resource', 'api.py')

        # Open the api file via the file system.
        g = open(filename, 'rb')
        self.assertEqual(g.read(), contents)
        g.close()
コード例 #10
0
    def test_file_resource(self):
        """ file resource """

        rm = ResourceManager()

        # Get the filename of the 'api.py' file.
        resource = files("envisage.resource") / "api.py"
        with as_file(resource) as path:

            # Open a file resource.
            f = rm.file(f"file://{path}")
            self.assertNotEqual(f, None)
            contents = f.read()
            f.close()

            # Open the api file via the file system.
            with open(path, "rb") as g:
                self.assertEqual(g.read(), contents)
コード例 #11
0
    def test_no_such_file_resource(self):
        """ no such file resource """

        rm = ResourceManager()

        # Open a file resource.
        self.assertRaises(NoSuchResourceError, rm.file, 'file://../bogus.py')

        return
コード例 #12
0
    def test_unknown_protocol(self):
        """ unknown protocol """

        # Open an HTTP document resource.
        rm = ResourceManager()

        self.assertRaises(ValueError, rm.file, 'bogus://foo/bar/baz')

        return
コード例 #13
0
    def test_file_resource(self):
        """ file resource """

        rm = ResourceManager()

        # Get the filename of the 'api.py' file.
        filename = resource_filename("envisage.resource", "api.py")

        # Open a file resource.
        f = rm.file("file://" + filename)
        self.assertNotEqual(f, None)
        contents = f.read()
        f.close()

        # Open the api file via the file system.
        with open(filename, "rb") as g:
            self.assertEqual(g.read(), contents)

        return
コード例 #14
0
    def test_no_such_http_resource(self):
        """ no such http resource """

        # Open an HTTP document resource.
        rm = ResourceManager()

        self.failUnlessRaises(NoSuchResourceError, rm.file,
                              'http://localhost:1234/bogus.dat')

        return
コード例 #15
0
    def test_package_resource(self):
        """ package resource """

        rm = ResourceManager()

        # Open a package resource.
        f = rm.file("pkgfile://envisage.resource/api.py")
        self.assertNotEqual(f, None)
        contents = f.read()
        f.close()

        # Get the filename of the 'api.py' file.
        filename = resource_filename("envisage.resource", "api.py")

        # Open the api file via the file system.
        g = open(filename, "rb")
        self.assertEqual(g.read(), contents)
        g.close()

        return
コード例 #16
0
    def test_file_resource(self):
        """ file resource """

        rm = ResourceManager()

        # Get the filename of the 'api.py' file.
        filename = resource_filename('envisage.resource', 'api.py')

        # Open a file resource.
        f = rm.file('file://' + filename)
        self.assertNotEqual(f, None)
        contents = f.read()
        f.close()

        # Open the api file via the file system.
        g = file(filename, 'rb')
        self.assertEqual(g.read(), contents)
        g.close()

        return
コード例 #17
0
ファイル: core_plugin.py プロジェクト: enthought/envisage
    def _load_preferences(self, preferences):
        """ Load all contributed preferences into a preferences node. """

        # Enthought library imports.
        from envisage.resource.api import ResourceManager

        # We add the plugin preferences to the default scope. The default scope
        # is a transient scope which means that (quite nicely ;^) we never
        # save the actual default plugin preference values. They will only get
        # saved if a value has been set in another (persistent) scope - which
        # is exactly what happens in the preferences UI.
        default = self.application.preferences.node("default/")

        # The resource manager is used to find the preferences files.
        resource_manager = ResourceManager()
        for resource_name in preferences:
            f = resource_manager.file(resource_name)
            try:
                default.load(f)

            finally:
                f.close()
コード例 #18
0
    def test_no_such_package_resource(self):
        """ no such package resource """

        rm = ResourceManager()

        # Open a package resource.
        self.assertRaises(NoSuchResourceError, rm.file,
                          'pkgfile://envisage.resource/bogus.py')

        self.assertRaises(NoSuchResourceError, rm.file,
                          'pkgfile://completely.bogus/bogus.py')

        return
コード例 #19
0
ファイル: core_plugin.py プロジェクト: enthought/envisage
    def _load_preferences(self, preferences):
        """ Load all contributed preferences into a preferences node. """

        # Enthought library imports.
        from envisage.resource.api import ResourceManager

        # We add the plugin preferences to the default scope. The default scope
        # is a transient scope which means that (quite nicely ;^) we never
        # save the actual default plugin preference values. They will only get
        # saved if a value has been set in another (persistent) scope - which
        # is exactly what happens in the preferences UI.
        default = self.application.preferences.node('default/')

        # The resource manager is used to find the preferences files.
        resource_manager = ResourceManager()
        for resource_name in preferences:
            f = resource_manager.file(resource_name)
            try:
                default.load(f)

            finally:
                f.close()

        return
コード例 #20
0
    def test_no_such_package_resource(self):
        """ no such package resource """

        rm = ResourceManager()

        # Open a package resource.
        with self.assertRaises(NoSuchResourceError):
            rm.file("pkgfile://envisage.resource/bogus.py")

        with self.assertRaises(NoSuchResourceError):
            rm.file("pkgfile://completely.bogus/bogus.py")