예제 #1
0
def boilerplate():
    """ Watchdog wrapper only calls this once to eliminate recurring performance impact.

    - Generate Markdown documentation files.
    - Generate HTML documentation files. (This location is important since it allows encoded css to be included
      in the documentation files.)
    - Generate reStructuredText documentation files.

    :return: None

    """
    if settings.logging_enabled:
        log.enable()

    if settings.hide_css_errors:
        cssutils.log.setLevel(logging.CRITICAL)

    # Generate Markdown documentation files.
    if settings.markdown_docs:
        markdown_file = GenericFile(                                        # Document forbidden clashing aliases.
            file_directory=settings.markdown_directory,
            file_name='clashing_aliases',
            extension='.md'
        )
        markdown_file.write(str(clashing_alias_markdown))
        markdown_file = GenericFile(                                        # Document allowed property aliases.
            file_directory=settings.markdown_directory,
            file_name='property_aliases',
            extension='.md'
        )
        markdown_file.write(str(property_alias_markdown))

    # Generate HTML documentation files. (This location is important since it allows encoded css to be included
    # in the documentation files.)
    if settings.html_docs:
        html_file = GenericFile(                                            # Document forbidden clashing aliases.
            file_directory=settings.project_directory,
            file_name='clashing_aliases',
            extension='.html'
        )
        html_file.write(str(clashing_alias_html))
        html_file = GenericFile(                                            # Document allowed property aliases.
            file_directory=settings.project_directory,
            file_name='property_aliases',
            extension='.html'
        )
        html_file.write(str(property_alias_html))

    # Generate reStructuredText documentation files.
    if settings.rst_docs:
        print('\nDocumentation Directory:', str(settings.docs_directory))     # str() is required for Python2
        rst_file = GenericFile(file_directory=settings.docs_directory, file_name='clashing_aliases', extension='.rst')
        rst_file.write(str(clashing_alias_rst))
        rst_file = GenericFile(file_directory=settings.docs_directory, file_name='property_aliases', extension='.rst')
        rst_file.write(str(property_alias_rst))
예제 #2
0
    def test_enable_logging_log_to_console_disabled(self):
        settings.logging_enabled = False
        settings.log_to_console = True  # Should produce no effect.
        settings.log_to_file = True  # Should produce no effect.
        expected_console_output = "Logging disabled because settings.logging_enabled is False.\n"

        saved_stdout = sys.stdout  # Monitor console
        try:
            out = StringIO()
            sys.stdout = out

            log.enable()

            output = out.getvalue()

            self.assertTrue(expected_console_output == output, msg=expected_console_output + "\noutput:\n" + output)
        finally:
            sys.stdout = saved_stdout
예제 #3
0
    def test_enable_logging_log_to_console_enabled(self):
        expected = "Console logging enabled.\n"
        settings.logging_enabled = True
        settings.log_to_console = True
        settings.log_to_file = False
        settings.logging_level = logging.DEBUG

        saved_stdout = sys.stdout  # Monitor console
        try:
            out = StringIO()
            sys.stdout = out

            log.enable()

            output = out.getvalue()

            self.assertTrue(output.endswith(expected), msg=expected + "\noutput:\n" + output)
        finally:
            sys.stdout = saved_stdout
예제 #4
0
    def test_enable_logging_log_to_file_enabled(self):
        settings.logging_enabled = True
        settings.log_to_console = False
        settings.log_to_file = True
        settings.log_directory = unittest_file_path(folder="log")  # Create the log directory inside of unit_tests.
        settings.logging_level = logging.DEBUG
        log_file_path = path.join(settings.log_directory, settings.log_file_name)
        expected = "Rotating file logging enabled." + "\nLog file location: " + log_file_path + "\n"

        if path.isfile(log_file_path):  # Clear log file.
            with open(log_file_path, "w"):
                pass

        log.enable()

        self.assertTrue(path.isfile(log_file_path), msg=log_file_path)  # Log file exists.

        with open(log_file_path, "r") as _file:
            file_as_string = _file.read()

        self.assertTrue(file_as_string.endswith(expected), msg=file_as_string)  # Contents match.
예제 #5
0
    def test_enable_logging_log_to_console_and_file_enabled(self):
        settings.logging_enabled = True
        settings.log_to_console = True
        settings.log_to_file = True
        settings.logging_level = logging.DEBUG
        settings.log_directory = unittest_file_path(folder="log")  # Create the log directory inside of unit_tests.
        log_file_path = path.join(settings.log_directory, settings.log_file_name)
        expected_console_output = "Console logging enabled."
        expected_console_and_file_output = (
            "Rotating file logging enabled." + "\nLog file location: " + log_file_path + "\n"
        )

        if path.isfile(log_file_path):  # Clear log file.
            with open(log_file_path, "w"):
                pass

        saved_stdout = sys.stdout  # Monitor console
        try:
            out = StringIO()
            sys.stdout = out

            log.enable()

            output = out.getvalue()

            self.assertTrue(expected_console_output in output, msg=expected_console_output + "\noutput:\n" + output)
            self.assertTrue(
                output.endswith(expected_console_and_file_output),
                msg=expected_console_and_file_output + "\noutput:\n" + output,
            )
        finally:
            sys.stdout = saved_stdout

        self.assertTrue(path.isfile(log_file_path), msg=log_file_path)  # Log file exists.

        with open(log_file_path, "r") as _file:
            file_as_string = _file.read()

        self.assertTrue(file_as_string.endswith(expected_console_and_file_output), msg=file_as_string)  # Contents match
예제 #6
0
    def test_logging_level_INFO(self):
        not_expected = "Console logging enabled.\n"
        info_message = "Testing 123. This should get logged."
        settings.logging_enabled = True
        settings.log_to_console = True
        settings.log_to_file = False
        settings.logging_level = logging.INFO

        saved_stdout = sys.stdout  # Monitor console
        try:
            out = StringIO()
            sys.stdout = out

            log.enable()
            logging.info(msg=info_message)

            output = out.getvalue()

            self.assertFalse(output.endswith(not_expected), msg=not_expected + "\noutput:\n" + output)
            self.assertTrue(info_message in output, msg=info_message + "\noutput:\n" + output)
        finally:
            sys.stdout = saved_stdout