Esempio n. 1
0
    def testLocateThrowsAnExceptionIfTheFileDoesNotExists(self):
        """@expectedException InvalidArgumentException

        """

        try:
            loader = FileLocator([__DIR__ + '/Fixtures'])

            loader.locate('foobar.xml', __DIR__)

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, InvalidArgumentException))
Esempio n. 2
0
    def __init__(self, kernel, path=None, paths = None):
        """
        """
        if paths is None:
            paths = list();
        assert isinstance(kernel, FileResourceLocatorInterface);
        self.__kernel = kernel;
        self.__path = path;

        if path:
            paths.append(path);

        BaseFileLocator.__init__(self, paths=paths);
Esempio n. 3
0
    def locate(self, name, currentPath=None, first=True):
        if name.startswith("@"):
            return self.__kernel.locateResource(name, self.__path, first);

        return BaseFileLocator.locate(
            self,
            name,
            currentPath=currentPath,
            first=first
        );
Esempio n. 4
0
    def load(self, configs, container):
        """Responds to the app.config configuration parameter.

        @param configs: list
        @param container: ContainerBuilder
        """
        assert isinstance(configs, list)
        assert isinstance(container, ContainerBuilder)

        loader = YamlFileLoader(
            container, FileLocator(dirname(__file__) + "/../Resources/config"))

        loader.load("services.yml")

        configuration = self.getConfiguration(configs, container)
        config = self._processConfiguration(configuration, configs)

        container.setParameter('kernel.default_locale',
                               config['default_locale'])
Esempio n. 5
0
    def testLocate(self):

        loader = FileLocator(__DIR__ + '/Fixtures')

        self.assertEqual(
            __DIR__ + os.path.sep + 'test_file_locator.py',
            loader.locate('test_file_locator.py', __DIR__),
            '->locate() returns the absolute filename if the file exists in the given path'
        )

        self.assertEqual(
            __DIR__ + '/Fixtures' + os.path.sep + 'foo.xml',
            loader.locate('foo.xml', __DIR__),
            '->locate() returns the absolute filename if the file exists in one of the paths given in the constructor'
        )

        self.assertEqual(
            __DIR__ + '/Fixtures' + os.path.sep + 'foo.xml',
            loader.locate(__DIR__ + '/Fixtures' + os.path.sep + 'foo.xml',
                          __DIR__),
            '->locate() returns the absolute filename if the file exists in one of the paths given in the constructor'
        )

        loader = FileLocator(
            [__DIR__ + '/Fixtures', __DIR__ + '/Fixtures/Again'])

        self.assertEqual([
            __DIR__ + '/Fixtures' + os.path.sep + 'foo.xml',
            __DIR__ + '/Fixtures/Again' + os.path.sep + 'foo.xml'
        ], loader.locate('foo.xml', __DIR__, False),
                         '->locate() returns an array of absolute filenames')

        self.assertEqual([
            __DIR__ + '/Fixtures' + os.path.sep + 'foo.xml',
            __DIR__ + '/Fixtures/Again' + os.path.sep + 'foo.xml'
        ], loader.locate('foo.xml', __DIR__ + '/Fixtures', False),
                         '->locate() returns an array of absolute filenames')

        loader = FileLocator(__DIR__ + '/Fixtures/Again')

        self.assertEqual([
            __DIR__ + '/Fixtures' + os.path.sep + 'foo.xml',
            __DIR__ + '/Fixtures/Again' + os.path.sep + 'foo.xml'
        ], loader.locate('foo.xml', __DIR__ + '/Fixtures', False),
                         '->locate() returns an array of absolute filenames')
Esempio n. 6
0
 def test(path):
     loader = FileLocator([])
     self.assertTrue(
         getattr(loader, '_FileLocator__isAbsolutePath')(path),
         '->isAbsolutePath() returns True for an absolute path')