Пример #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))
Пример #2
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
        );
Пример #3
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')