Beispiel #1
0
class TestHolocron(HolocronTestCase):

    def setUp(self):
        self.app = Holocron({
            'ext': {
                'enabled': [],
            },
        })

    def test_user_settings(self):
        """
        Tests creating an instance with custom settings: check for settings
        overriding.
        """
        app = Holocron({
            'sitename': 'Luke Skywalker',
            'paths': {
                'content': 'path/to/content',
            },
        })

        conf = copy.deepcopy(app.default_conf)
        conf['sitename'] = 'Luke Skywalker'
        conf['paths']['content'] = 'path/to/content'

        self.assertEqual(app.conf, conf)

    def test_add_converter(self):
        """
        Tests converter registration process.
        """
        class TestConverter(abc.Converter):
            extensions = ['.tst', '.test']

            def to_html(self, text):
                return {}, text

        # test registration process
        converter = TestConverter()
        self.assertEqual(len(self.app._converters), 0)
        self.app.add_converter(converter)
        self.assertEqual(len(self.app._converters), 2)

        self.assertIn('.tst', self.app._converters)
        self.assertIn('.test', self.app._converters)

        self.assertIs(self.app._converters['.tst'], converter)
        self.assertIs(self.app._converters['.test'], converter)

        # test protection from double registration
        self.app.add_converter(TestConverter())
        self.assertIs(self.app._converters['.tst'], converter)
        self.assertIs(self.app._converters['.test'], converter)

        # test force registration
        new_converter = TestConverter()
        self.app.add_converter(new_converter, _force=True)
        self.assertIs(self.app._converters['.tst'], new_converter)
        self.assertIs(self.app._converters['.test'], new_converter)

    def test_add_generator(self):
        """
        Tests generator registration process.
        """
        class TestGenerator(abc.Generator):
            def generate(self, text):
                pass

        # test registration process
        generator = TestGenerator()
        self.assertEqual(len(self.app._generators), 0)
        self.app.add_generator(generator)
        self.assertEqual(len(self.app._generators), 1)
        self.assertIn(generator, self.app._generators)

        # test double registration is allowed
        new_generator = TestGenerator()
        self.app.add_generator(new_generator)
        self.assertEqual(len(self.app._generators), 2)
        self.assertIn(new_generator, self.app._generators)

    @mock.patch('holocron.app.mkdir')
    @mock.patch('holocron.app.iterfiles')
    def test_run(self, iterfiles, mkdir):
        """
        Tests build process.
        """
        iterfiles.return_value = ['doc_a', 'doc_b', 'doc_c']
        self.app.__class__.document_factory = mock.Mock()
        self.app._copy_theme = mock.Mock()
        self.app._generators = {
            mock.Mock(): mock.Mock(),
            mock.Mock(): mock.Mock(),
        }

        self.app.run()

        # check iterfiles call signature
        iterfiles.assert_called_with(
            self.app.conf['paths']['content'], '[!_.]*', True)

        # check mkdir create ourpur dir
        mkdir.assert_called_with(self.app.conf['paths.output'])

        # check that generators was used
        for generator in self.app._generators:
            self.assertEqual(generator.generate.call_count, 1)

        self.app.__class__.document_factory.assert_has_calls([
            # check that document class was used to generate class instances
            mock.call('doc_a', self.app),
            mock.call('doc_b', self.app),
            mock.call('doc_c', self.app),
            # check that document instances were built
            mock.call().build(),
            mock.call().build(),
            mock.call().build(),
        ])
        self.assertEqual(self.app.__class__.document_factory.call_count, 3)

        # check that _copy_theme was called
        self.app._copy_theme.assert_called_once_with()

    @mock.patch('holocron.app.copy_tree')
    def test_copy_base_theme(self, mcopytree):
        """
        Tests that Holocron do copy default theme.
        """
        output = os.path.join(self.app.conf['paths.output'], 'static')
        theme = os.path.join(
            os.path.dirname(holocron.__file__), 'theme', 'static')

        self.app._copy_theme()

        mcopytree.assert_called_with(theme, output)

    @mock.patch('holocron.app.os.path.exists', return_value=True)
    @mock.patch('holocron.app.copy_tree')
    def test_copy_user_themes(self, mcopytree, _):
        """
        Tests that Holocron do copy user theme.
        """
        output = os.path.join(self.app.conf['paths.output'], 'static')
        theme = os.path.join(
            os.path.dirname(holocron.__file__), 'theme', 'static')

        self.app.add_theme('theme1')
        self.app.add_theme('theme2')
        self.app._copy_theme()

        self.assertEqual(mcopytree.call_args_list, [
            mock.call(theme, output),
            mock.call(os.path.join('theme1', 'static'), output),
            mock.call(os.path.join('theme2', 'static'), output),
        ])

    @mock.patch('holocron.app.os.path.exists', side_effect=[True, False])
    @mock.patch('holocron.app.copy_tree')
    def test_copy_user_themes_not_exist(self, mcopytree, _):
        """
        Tests that Holocron doesn't copy static if it's not exist.
        """
        output = os.path.join(self.app.conf['paths.output'], 'static')
        theme = os.path.join(
            os.path.dirname(holocron.__file__), 'theme', 'static')

        self.app.add_theme('theme1')
        self.app._copy_theme()

        self.assertEqual(mcopytree.call_args_list, [
            mock.call(theme, output),
        ])
Beispiel #2
0
class TestHolocron(HolocronTestCase):
    def setUp(self):
        self.app = Holocron({
            'ext': {
                'enabled': [],
            },
        })

    def test_user_settings(self):
        """
        Tests creating an instance with custom settings: check for settings
        overriding.
        """
        app = Holocron({
            'sitename': 'Luke Skywalker',
            'paths': {
                'content': 'path/to/content',
            },
        })

        conf = copy.deepcopy(app.default_conf)
        conf['sitename'] = 'Luke Skywalker'
        conf['paths']['content'] = 'path/to/content'

        self.assertEqual(app.conf, conf)

    def test_add_converter(self):
        """
        Tests converter registration process.
        """
        class TestConverter(abc.Converter):
            extensions = ['.tst', '.test']

            def to_html(self, text):
                return {}, text

        # test registration process
        converter = TestConverter()
        self.assertEqual(len(self.app._converters), 0)
        self.app.add_converter(converter)
        self.assertEqual(len(self.app._converters), 2)

        self.assertIn('.tst', self.app._converters)
        self.assertIn('.test', self.app._converters)

        self.assertIs(self.app._converters['.tst'], converter)
        self.assertIs(self.app._converters['.test'], converter)

        # test protection from double registration
        self.app.add_converter(TestConverter())
        self.assertIs(self.app._converters['.tst'], converter)
        self.assertIs(self.app._converters['.test'], converter)

        # test force registration
        new_converter = TestConverter()
        self.app.add_converter(new_converter, _force=True)
        self.assertIs(self.app._converters['.tst'], new_converter)
        self.assertIs(self.app._converters['.test'], new_converter)

    def test_add_generator(self):
        """
        Tests generator registration process.
        """
        class TestGenerator(abc.Generator):
            def generate(self, text):
                pass

        # test registration process
        generator = TestGenerator()
        self.assertEqual(len(self.app._generators), 0)
        self.app.add_generator(generator)
        self.assertEqual(len(self.app._generators), 1)
        self.assertIn(generator, self.app._generators)

        # test double registration is allowed
        new_generator = TestGenerator()
        self.app.add_generator(new_generator)
        self.assertEqual(len(self.app._generators), 2)
        self.assertIn(new_generator, self.app._generators)

    @mock.patch('holocron.app.mkdir')
    @mock.patch('holocron.app.iterfiles')
    def test_run(self, iterfiles, mkdir):
        """
        Tests build process.
        """
        iterfiles.return_value = ['doc_a', 'doc_b', 'doc_c']
        self.app.__class__.document_factory = mock.Mock()
        self.app._copy_theme = mock.Mock()
        self.app._generators = {
            mock.Mock(): mock.Mock(),
            mock.Mock(): mock.Mock(),
        }

        self.app.run()

        # check iterfiles call signature
        iterfiles.assert_called_with(self.app.conf['paths']['content'],
                                     '[!_.]*', True)

        # check mkdir create ourpur dir
        mkdir.assert_called_with(self.app.conf['paths.output'])

        # check that generators was used
        for generator in self.app._generators:
            self.assertEqual(generator.generate.call_count, 1)

        self.app.__class__.document_factory.assert_has_calls([
            # check that document class was used to generate class instances
            mock.call('doc_a', self.app),
            mock.call('doc_b', self.app),
            mock.call('doc_c', self.app),
            # check that document instances were built
            mock.call().build(),
            mock.call().build(),
            mock.call().build(),
        ])
        self.assertEqual(self.app.__class__.document_factory.call_count, 3)

        # check that _copy_theme was called
        self.app._copy_theme.assert_called_once_with()

    @mock.patch('holocron.app.copy_tree')
    def test_copy_base_theme(self, mcopytree):
        """
        Tests that Holocron do copy default theme.
        """
        output = os.path.join(self.app.conf['paths.output'], 'static')
        theme = os.path.join(os.path.dirname(holocron.__file__), 'theme',
                             'static')

        self.app._copy_theme()

        mcopytree.assert_called_with(theme, output)

    @mock.patch('holocron.app.os.path.exists', return_value=True)
    @mock.patch('holocron.app.copy_tree')
    def test_copy_user_themes(self, mcopytree, _):
        """
        Tests that Holocron do copy user theme.
        """
        output = os.path.join(self.app.conf['paths.output'], 'static')
        theme = os.path.join(os.path.dirname(holocron.__file__), 'theme',
                             'static')

        self.app.add_theme('theme1')
        self.app.add_theme('theme2')
        self.app._copy_theme()

        self.assertEqual(mcopytree.call_args_list, [
            mock.call(theme, output),
            mock.call(os.path.join('theme1', 'static'), output),
            mock.call(os.path.join('theme2', 'static'), output),
        ])

    @mock.patch('holocron.app.os.path.exists', side_effect=[True, False])
    @mock.patch('holocron.app.copy_tree')
    def test_copy_user_themes_not_exist(self, mcopytree, _):
        """
        Tests that Holocron doesn't copy static if it's not exist.
        """
        output = os.path.join(self.app.conf['paths.output'], 'static')
        theme = os.path.join(os.path.dirname(holocron.__file__), 'theme',
                             'static')

        self.app.add_theme('theme1')
        self.app._copy_theme()

        self.assertEqual(mcopytree.call_args_list, [
            mock.call(theme, output),
        ])
Beispiel #3
0
class TestHolocron(HolocronTestCase):
    def setUp(self):
        self.app = Holocron({"ext": {"enabled": []}})

    def test_user_settings(self):
        """
        Tests creating an instance with custom settings: check for settings
        overriding.
        """
        app = Holocron({"sitename": "Luke Skywalker", "paths": {"content": "path/to/content"}})

        conf = copy.deepcopy(app.default_conf)
        conf["sitename"] = "Luke Skywalker"
        conf["paths"]["content"] = "path/to/content"

        self.assertEqual(app.conf, conf)

    def test_add_converter(self):
        """
        Tests converter registration process.
        """

        class TestConverter(abc.Converter):
            extensions = [".tst", ".test"]

            def to_html(self, text):
                return {}, text

        # test registration process
        converter = TestConverter()
        self.assertEqual(len(self.app._converters), 0)
        self.app.add_converter(converter)
        self.assertEqual(len(self.app._converters), 2)

        self.assertIn(".tst", self.app._converters)
        self.assertIn(".test", self.app._converters)

        self.assertIs(self.app._converters[".tst"], converter)
        self.assertIs(self.app._converters[".test"], converter)

        # test protection from double registration
        self.app.add_converter(TestConverter())
        self.assertIs(self.app._converters[".tst"], converter)
        self.assertIs(self.app._converters[".test"], converter)

        # test force registration
        new_converter = TestConverter()
        self.app.add_converter(new_converter, _force=True)
        self.assertIs(self.app._converters[".tst"], new_converter)
        self.assertIs(self.app._converters[".test"], new_converter)

    def test_add_generator(self):
        """
        Tests generator registration process.
        """

        class TestGenerator(abc.Generator):
            def generate(self, text):
                pass

        # test registration process
        generator = TestGenerator()
        self.assertEqual(len(self.app._generators), 0)
        self.app.add_generator(generator)
        self.assertEqual(len(self.app._generators), 1)
        self.assertIn(generator, self.app._generators)

        # test double registration is allowed
        new_generator = TestGenerator()
        self.app.add_generator(new_generator)
        self.assertEqual(len(self.app._generators), 2)
        self.assertIn(new_generator, self.app._generators)

    @mock.patch("holocron.app.mkdir")
    @mock.patch("holocron.app.iterfiles")
    def test_run(self, iterfiles, mkdir):
        """
        Tests build process.
        """
        iterfiles.return_value = ["doc_a", "doc_b", "doc_c"]
        self.app.__class__.document_factory = mock.Mock()
        self.app._copy_theme = mock.Mock()
        self.app._generators = {mock.Mock(): mock.Mock(), mock.Mock(): mock.Mock()}

        self.app.run()

        # check iterfiles call signature
        iterfiles.assert_called_with(self.app.conf["paths"]["content"], "[!_.]*", True)

        # check mkdir create ourpur dir
        mkdir.assert_called_with(self.app.conf["paths.output"])

        # check that generators was used
        for generator in self.app._generators:
            self.assertEqual(generator.generate.call_count, 1)

        self.app.__class__.document_factory.assert_has_calls(
            [
                # check that document class was used to generate class instances
                mock.call("doc_a", self.app),
                mock.call("doc_b", self.app),
                mock.call("doc_c", self.app),
                # check that document instances were built
                mock.call().build(),
                mock.call().build(),
                mock.call().build(),
            ]
        )
        self.assertEqual(self.app.__class__.document_factory.call_count, 3)

        # check that _copy_theme was called
        self.app._copy_theme.assert_called_once_with()

    @mock.patch("holocron.app.copy_tree")
    def test_copy_base_theme(self, mcopytree):
        """
        Tests that Holocron do copy default theme.
        """
        output = os.path.join(self.app.conf["paths.output"], "static")
        theme = os.path.join(os.path.dirname(holocron.__file__), "theme", "static")

        self.app._copy_theme()

        mcopytree.assert_called_with(theme, output)

    @mock.patch("holocron.app.os.path.exists", return_value=True)
    @mock.patch("holocron.app.copy_tree")
    def test_copy_user_themes(self, mcopytree, _):
        """
        Tests that Holocron do copy user theme.
        """
        output = os.path.join(self.app.conf["paths.output"], "static")
        theme = os.path.join(os.path.dirname(holocron.__file__), "theme", "static")

        self.app.add_theme("theme1")
        self.app.add_theme("theme2")
        self.app._copy_theme()

        self.assertEqual(
            mcopytree.call_args_list,
            [
                mock.call(theme, output),
                mock.call(os.path.join("theme1", "static"), output),
                mock.call(os.path.join("theme2", "static"), output),
            ],
        )

    @mock.patch("holocron.app.os.path.exists", side_effect=[True, False])
    @mock.patch("holocron.app.copy_tree")
    def test_copy_user_themes_not_exist(self, mcopytree, _):
        """
        Tests that Holocron doesn't copy static if it's not exist.
        """
        output = os.path.join(self.app.conf["paths.output"], "static")
        theme = os.path.join(os.path.dirname(holocron.__file__), "theme", "static")

        self.app.add_theme("theme1")
        self.app._copy_theme()

        self.assertEqual(mcopytree.call_args_list, [mock.call(theme, output)])