當前位置: 首頁>>代碼示例>>Python>>正文


Python LintConfig.set_general_option方法代碼示例

本文整理匯總了Python中gitlint.config.LintConfig.set_general_option方法的典型用法代碼示例。如果您正苦於以下問題:Python LintConfig.set_general_option方法的具體用法?Python LintConfig.set_general_option怎麽用?Python LintConfig.set_general_option使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gitlint.config.LintConfig的用法示例。


在下文中一共展示了LintConfig.set_general_option方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_set_general_option_negative

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import set_general_option [as 別名]
    def test_set_general_option_negative(self):
        config = LintConfig()

        with self.assertRaisesRegex(LintConfigError, "'foo' is not a valid gitlint option"):
            config.set_general_option("foo", "bar")

        # try setting _config_path, this is a real attribute of LintConfig, but the code should prevent it from
        # being set
        with self.assertRaisesRegex(LintConfigError, "'_config_path' is not a valid gitlint option"):
            config.set_general_option("_config_path", "bar")

        # invalid verbosity`
        incorrect_values = [-1, "foo"]
        for value in incorrect_values:
            expected_msg = r"Option 'verbosity' must be a positive integer \(current value: '{0}'\)".format(value)
            with self.assertRaisesRegex(LintConfigError, expected_msg):
                config.verbosity = value

        incorrect_values = [4]
        for value in incorrect_values:
            with self.assertRaisesRegex(LintConfigError, "Option 'verbosity' must be set between 0 and 3"):
                config.verbosity = value

        # invalid ignore_merge_commits
        incorrect_values = [-1, 4, "foo"]
        for value in incorrect_values:
            with self.assertRaisesRegex(LintConfigError,
                                        r"Option 'ignore-merge-commits' must be either 'true' or 'false'"):
                config.ignore_merge_commits = value

        # invalid ignore -> not here because ignore is a ListOption which converts everything to a string before
        # splitting which means it it will accept just about everything

        # invalid debug
        with self.assertRaisesRegex(LintConfigError, r"Option 'debug' must be either 'true' or 'false'"):
            config.debug = "foobar"

        # invalid extra-path
        with self.assertRaisesRegex(LintConfigError,
                                    r"Option extra-path must be an existing directory \(current value: 'foo/bar'\)"):
            config.extra_path = "foo/bar"

        # invalid target
        with self.assertRaisesRegex(LintConfigError,
                                    r"Option target must be an existing directory \(current value: 'foo/bar'\)"):
            config.target = "foo/bar"
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:48,代碼來源:test_config.py

示例2: test_extra_path

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import set_general_option [as 別名]
    def test_extra_path(self):
        config = LintConfig()

        config.set_general_option("extra-path", self.get_rule_rules_path())
        self.assertEqual(config.extra_path, self.get_rule_rules_path())
        actual_rule = config.get_rule('TUC1')
        self.assertTrue(actual_rule.user_defined)
        self.assertEqual(str(type(actual_rule)), "<class 'my_commit_rules.MyUserCommitRule'>")
        self.assertEqual(actual_rule.id, 'TUC1')
        self.assertEqual(actual_rule.name, 'my-user-commit-rule')
        self.assertEqual(actual_rule.target, None)
        expected_rule_option = IntOption('violation-count', 1, "Number of violations to return")
        self.assertListEqual(actual_rule.options_spec, [expected_rule_option])
        self.assertDictEqual(actual_rule.options, {'violation-count': expected_rule_option})

        # reset value (this is a different code path)
        config.set_general_option("extra-path", self.SAMPLES_DIR)
        self.assertEqual(config.extra_path, self.SAMPLES_DIR)
        self.assertIsNone(config.get_rule("TUC1"))
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:21,代碼來源:test_config.py

示例3: test_set_general_option_negative

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import set_general_option [as 別名]
    def test_set_general_option_negative(self):
        config = LintConfig()

        with self.assertRaisesRegexp(LintConfigError, "'foo' is not a valid gitlint option"):
            config.set_general_option("foo", "bar")

        # invalid verbosity
        incorrect_values = [-1, "foo"]
        for value in incorrect_values:
            expected_msg = r"Option 'verbosity' must be a positive integer \(current value: '{0}'\)".format(value)
            with self.assertRaisesRegexp(LintConfigError, expected_msg):
                config.verbosity = value

        incorrect_values = [4]
        for value in incorrect_values:
            with self.assertRaisesRegexp(LintConfigError, "Option 'verbosity' must be set between 0 and 3"):
                config.verbosity = value

        # invalid ignore_merge_commits
        incorrect_values = [-1, 4, "foo"]
        for value in incorrect_values:
            with self.assertRaisesRegexp(LintConfigError,
                                         r"Option 'ignore-merge-commits' must be either 'true' or 'false'"):
                config.ignore_merge_commits = value
開發者ID:cimarron-pistoncloud,項目名稱:gitlint,代碼行數:26,代碼來源:test_config.py

示例4: test_set_general_option

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import set_general_option [as 別名]
    def test_set_general_option(self):
        config = LintConfig()

        # Check that default general options are correct
        self.assertTrue(config.ignore_merge_commits)
        self.assertEqual(config.verbosity, 3)
        active_rule_classes = [type(rule) for rule in config.rules]
        self.assertListEqual(active_rule_classes, config.default_rule_classes)

        # Check that we can change the general options
        # ignore
        config.set_general_option("ignore", "title-trailing-whitespace, B2")
        expected_ignored_rules = set([rules.BodyTrailingWhitespace, rules.TitleTrailingWhitespace])
        active_rule_classes = set(type(rule) for rule in config.rules)  # redetermine active rule classes
        expected_active_rule_classes = set(config.default_rule_classes) - expected_ignored_rules
        self.assertSetEqual(active_rule_classes, expected_active_rule_classes)

        # verbosity
        config.set_general_option("verbosity", 1)
        self.assertEqual(config.verbosity, 1)

        # ignore_merge_commit
        config.set_general_option("ignore-merge-commits", "false")
        self.assertFalse(config.ignore_merge_commits)
開發者ID:cimarron-pistoncloud,項目名稱:gitlint,代碼行數:26,代碼來源:test_config.py

示例5: test_set_general_option

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import set_general_option [as 別名]
    def test_set_general_option(self):
        config = LintConfig()

        # Check that default general options are correct
        self.assertTrue(config.ignore_merge_commits)
        self.assertFalse(config.debug)
        self.assertEqual(config.verbosity, 3)
        active_rule_classes = tuple(type(rule) for rule in config.rules)
        self.assertTupleEqual(active_rule_classes, config.default_rule_classes)

        # ignore - set by string
        config.set_general_option("ignore", "title-trailing-whitespace, B2")
        self.assertEqual(config.ignore, ["title-trailing-whitespace", "B2"])

        # ignore - set by list
        config.set_general_option("ignore", ["T1", "B3"])
        self.assertEqual(config.ignore, ["T1", "B3"])

        # verbosity
        config.set_general_option("verbosity", 1)
        self.assertEqual(config.verbosity, 1)

        # ignore_merge_commit
        config.set_general_option("ignore-merge-commits", "false")
        self.assertFalse(config.ignore_merge_commits)

        # debug
        config.set_general_option("debug", "true")
        self.assertTrue(config.debug)

        # target
        config.set_general_option("target", self.SAMPLES_DIR)
        self.assertEqual(config.target, self.SAMPLES_DIR)
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:35,代碼來源:test_config.py


注:本文中的gitlint.config.LintConfig.set_general_option方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。