예제 #1
0
def test_flag_format_env_variable():
    """Test flag formatting and env variable."""
    class OtherFlags(Enum):
        """Some flags to be used on the assertions below."""

        MULTI_WORD = 1
        SOME_OPTION = 2

    assert NitpickApp.format_flag(
        OtherFlags.MULTI_WORD) == "--nitpick-multi-word"
    os.environ["NITPICK_SOME_OPTION"] = "something"
    assert NitpickApp.format_env(
        OtherFlags.SOME_OPTION) == "NITPICK_SOME_OPTION"
    assert NitpickApp.get_env(OtherFlags.SOME_OPTION) == "something"
    assert NitpickApp.get_env(OtherFlags.MULTI_WORD) == ""
예제 #2
0
    def parse_options(option_manager: OptionManager, options, args):  # pylint: disable=unused-argument
        """Create the Nitpick app, set logging from the verbose flags, set offline mode.

        This function is called only once by flake8, so it's a good place to create the app.
        """
        log_mapping = {1: logging.INFO, 2: logging.DEBUG}
        logging.basicConfig(
            level=log_mapping.get(options.verbose, logging.WARNING))

        NitpickApp.create_app(
            offline=bool(options.nitpick_offline
                         or NitpickApp.get_env(NitpickApp.Flags.OFFLINE)))
        LOGGER.info("Offline mode: %s", NitpickApp.current().offline)