예제 #1
0
class PythonBraceFormatCheckTest(CheckTestCase):
    check = PythonBraceFormatCheck()

    def setUp(self):
        super().setUp()
        self.test_highlight = (
            "python-brace-format",
            "{0}string{1}",
            [(0, 3, "{0}"), (9, 12, "{1}")],
        )

    def test_no_format(self):
        self.assertFalse(
            self.check.check_format("strins", "string", False, None))

    def test_position_format(self):
        self.assertFalse(
            self.check.check_format("{} string {}", "{} string {}", False,
                                    None))

    def test_wrong_position_format(self):
        self.assertTrue(
            self.check.check_format("{} string", "{} string {}", False, None))

    def test_named_format(self):
        self.assertFalse(
            self.check.check_format("{s1} string {s2}", "{s1} string {s2}",
                                    False, None))

    def test_missing_format(self):
        self.assertTrue(
            self.check.check_format("{} string", "string", False, None))

    def test_missing_named_format(self):
        self.assertTrue(
            self.check.check_format("{s1} string", "string", False, None))

    def test_missing_named_format_ignore(self):
        self.assertFalse(
            self.check.check_format("{s} string", "string", True, None))

    def test_wrong_format(self):
        self.assertTrue(
            self.check.check_format("{s} string", "{c} string", False, None))

    def test_escaping(self):
        self.assertFalse(
            self.check.check_format("{{ string }}", "string", False, None))

    def test_attribute_format(self):
        self.assertFalse(
            self.check.check_format("{s.foo} string", "{s.foo} string", False,
                                    None))

    def test_wrong_attribute_format(self):
        self.assertTrue(
            self.check.check_format("{s.foo} string", "{s.bar} string", False,
                                    None))
예제 #2
0
class PythonBraceFormatCheckTest(CheckTestCase):
    check = PythonBraceFormatCheck()

    def setUp(self):
        super(PythonBraceFormatCheckTest, self).setUp()
        self.test_highlight = (
            'python-brace-format',
            '{0}string{1}',
            [(0, 3, u'{0}'), (9, 12, u'{1}')],
        )

    def test_no_format(self):
        self.assertFalse(self.check.check_format('strins', 'string', False))

    def test_position_format(self):
        self.assertFalse(
            self.check.check_format('{} string {}', '{} string {}', False))

    def test_wrong_position_format(self):
        self.assertTrue(
            self.check.check_format('{} string', '{} string {}', False))

    def test_named_format(self):
        self.assertFalse(
            self.check.check_format('{s1} string {s2}', '{s1} string {s2}',
                                    False))

    def test_missing_format(self):
        self.assertTrue(self.check.check_format('{} string', 'string', False))

    def test_missing_named_format(self):
        self.assertTrue(self.check.check_format('{s1} string', 'string',
                                                False))

    def test_missing_named_format_ignore(self):
        self.assertFalse(self.check.check_format('{s} string', 'string', True))

    def test_wrong_format(self):
        self.assertTrue(
            self.check.check_format('{s} string', '{c} string', False))

    def test_escaping(self):
        self.assertFalse(
            self.check.check_format('{{ string }}', 'string', False))

    def test_attribute_format(self):
        self.assertFalse(
            self.check.check_format('{s.foo} string', '{s.foo} string', False))

    def test_wrong_attribute_format(self):
        self.assertTrue(
            self.check.check_format('{s.foo} string', '{s.bar} string', False))