Example #1
0
class FileLoaderTestCase(unittest.TestCase):
    """ Test the ``FileLoader``.
    """
    def setUp(self):
        import os.path
        from wheezy.template.loader import FileLoader
        curdir = os.path.dirname(__file__)
        tmpldir = os.path.join(curdir, 'templates')
        self.loader = FileLoader(directories=[tmpldir])

    def test_list_names(self):
        """ Tests list_names.
        """
        assert ('shared/master.html', 'shared/snippet/script.html',
                'tmpl1.html') == self.loader.list_names()

    def test_load_existing(self):
        """ Tests load.
        """
        assert '' == self.loader.load('tmpl1.html')

    def test_load_not_found(self):
        """ Tests load if the name is not found.
        """
        assert None == self.loader.load('tmpl-x.html')

    def test_load_not_a_file(self):
        """ Tests load if the name is not a file.
        """
        assert not self.loader.load('shared/snippet')
Example #2
0
class FileLoaderTestCase(unittest.TestCase):
    """Test the ``FileLoader``."""
    def setUp(self) -> None:
        self.tmpldir = os.path.dirname(__file__)
        self.loader = FileLoader(directories=[self.tmpldir])

    @patch("os.walk")
    def test_get_template(self, mock_walk: Mock) -> None:
        mock_walk.return_value = [
            (
                self.tmpldir + "/",
                [".ignore", "shared"],
                [".ignore", "tmpl1.html"],
            ),
            (
                self.tmpldir + "/shared",
                [".ignore", "snippet"],
                ["master.html", ".ignore"],
            ),
            (
                self.tmpldir + "/shared/snippet",
                [".ignore"],
                [".ignore", "script.html"],
            ),
        ]
        assert (
            "shared/master.html",
            "shared/snippet/script.html",
            "tmpl1.html",
        ) == self.loader.list_names()

    def test_load_existing(self) -> None:
        """Tests load."""
        assert "" == self.loader.load("__init__.py")

    def test_load_not_found(self) -> None:
        """Tests load if the name is not found."""
        assert not self.loader.load("tmpl-x.html")

    def test_load_not_a_file(self) -> None:
        """Tests load if the name is not a file."""
        assert not self.loader.load("..")
Example #3
0
class FileLoaderTestCase(unittest.TestCase):
    """ Test the ``FileLoader``.
    """
    def setUp(self):
        import os.path
        from wheezy.template.loader import FileLoader
        self.tmpldir = os.path.dirname(__file__)
        self.loader = FileLoader(directories=[self.tmpldir])

    @patch('os.walk')
    def test_get_template(self, mock_walk):
        mock_walk.return_value = [
            (self.tmpldir + '/', ['.ignore',
                                  'shared'], ['.ignore', 'tmpl1.html']),
            (self.tmpldir + '/shared', ['.ignore',
                                        'snippet'], ['master.html',
                                                     '.ignore']),
            (self.tmpldir + '/shared/snippet', ['.ignore'],
             ['.ignore', 'script.html'])
        ]
        assert ('shared/master.html', 'shared/snippet/script.html',
                'tmpl1.html') == self.loader.list_names()

    def test_load_existing(self):
        """ Tests load.
        """
        assert '' == self.loader.load('__init__.py')

    def test_load_not_found(self):
        """ Tests load if the name is not found.
        """
        assert not self.loader.load('tmpl-x.html')

    def test_load_not_a_file(self):
        """ Tests load if the name is not a file.
        """
        assert not self.loader.load('..')