Esempio n. 1
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))
Esempio n. 2
0
 def setUp(self):
     self.check = PythonBraceFormatCheck()
Esempio n. 3
0
class PythonBraceFormatCheckTest(TestCase):
    def setUp(self):
        self.check = PythonBraceFormatCheck()

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

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

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

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

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

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

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

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

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

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

    def test_wrong_attribute_format(self):
        self.assertTrue(self.check.check_format(
            u'{s.foo} string',
            u'{s.bar} string',
            MockUnit('python_brace_wrong_attribute_format'),
            0,
            False
        ))
Esempio n. 4
0
 def setUp(self):
     self.check = PythonBraceFormatCheck()
Esempio n. 5
0
class PythonBraceFormatCheckTest(TestCase):
    def setUp(self):
        self.check = PythonBraceFormatCheck()

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

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

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

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

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

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

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

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

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

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

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