Пример #1
0
 def setUp(self):
     self.check = PythonFormatCheck()
Пример #2
0
class PythonFormatCheckTest(TestCase):
    def setUp(self):
        self.check = PythonFormatCheck()

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

    def test_format(self):
        self.assertFalse(self.check.check_format(
            u'%s string',
            u'%s string',
            MockUnit('python_format'),
            0,
            False
        ))

    def test_percent_format(self):
        self.assertFalse(self.check.check_format(
            u'%d%% string',
            u'%d%% string',
            MockUnit('python_percent_format'),
            0,
            False
        ))

    def test_named_format(self):
        self.assertFalse(self.check.check_format(
            u'%(name)s string',
            u'%(name)s string',
            MockUnit('python_named_format'),
            0,
            False
        ))

    def test_missing_format(self):
        self.assertTrue(self.check.check_format(
            u'%s string',
            u'string',
            MockUnit('python_missing_format'),
            0,
            False
        ))

    def test_missing_named_format(self):
        self.assertTrue(self.check.check_format(
            u'%(name)s string',
            u'string',
            MockUnit('python_missing_named_format'),
            0,
            False
        ))

    def test_missing_named_format_ignore(self):
        self.assertFalse(self.check.check_format(
            u'%(name)s string',
            u'string',
            MockUnit('python_missing_named_format'),
            0,
            True
        ))

    def test_wrong_format(self):
        self.assertTrue(self.check.check_format(
            u'%s string',
            u'%c string',
            MockUnit('python_wrong_format'),
            0,
            False
        ))

    def test_reordered_format(self):
        self.assertTrue(self.check.check_format(
            u'%s %d string',
            u'%d %s string',
            MockUnit('python_wrong_format'),
            0,
            False
        ))

    def test_wrong_named_format(self):
        self.assertTrue(self.check.check_format(
            u'%(name)s string',
            u'%(jmeno)s string',
            MockUnit('python_wrong_named_format'),
            0,
            False
        ))

    def test_reordered_named_format(self):
        self.assertFalse(self.check.check_format(
            u'%(name)s %(foo)s string',
            u'%(foo)s %(name)s string',
            MockUnit('python_reordered_named_format'),
            0,
            False
        ))

    def test_reordered_named_format_long(self):
        self.assertFalse(self.check.check_format(
            u'%(count)d strings into %(languages)d languages %(percent)d%%',
            u'%(languages)d dil içinde %(count)d satır %%%(percent)d',
            MockUnit('python_reordered_named_format_long'),
            0,
            False
        ))
Пример #3
0
class PythonFormatCheckTest(CheckTestCase):
    check = PythonFormatCheck()

    def setUp(self):
        super(PythonFormatCheckTest, self).setUp()
        self.test_highlight = (
            'python-format',
            '%sstring%d',
            [(0, 2, u'%s'), (8, 10, u'%d')],
        )

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

    def test_format(self):
        self.assertFalse(
            self.check.check_format('%s string', '%s string', False))

    def test_percent_format(self):
        self.assertFalse(
            self.check.check_format('%d%% string', '%d%% string', False))

    def test_named_format(self):
        self.assertFalse(
            self.check.check_format('%(name)s string', '%(name)s string',
                                    False))

    def test_missing_format(self):
        self.assertTrue(self.check.check_format('%s string', 'string', False))

    def test_missing_named_format(self):
        self.assertTrue(
            self.check.check_format('%(name)s string', 'string', False))

    def test_missing_named_format_ignore(self):
        self.assertFalse(
            self.check.check_format('%(name)s string', 'string', True))

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

    def test_reordered_format(self):
        self.assertTrue(
            self.check.check_format('%s %d string', '%d %s string', False))

    def test_wrong_named_format(self):
        self.assertTrue(
            self.check.check_format('%(name)s string', '%(jmeno)s string',
                                    False))

    def test_reordered_named_format(self):
        self.assertFalse(
            self.check.check_format('%(name)s %(foo)s string',
                                    '%(foo)s %(name)s string', False))

    def test_reordered_named_format_long(self):
        self.assertFalse(
            self.check.check_format(
                '%(count)d strings into %(languages)d languages %(percent)d%%',
                '%(languages)d dil içinde %(count)d satır %%%(percent)d',
                False))
Пример #4
0
 def setUp(self):
     self.check = PythonFormatCheck()
Пример #5
0
class PythonFormatCheckTest(TestCase):
    def setUp(self):
        self.check = PythonFormatCheck()

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

    def test_format(self):
        self.assertFalse(
            self.check.check_format(u'%s string', u'%s string',
                                    MockUnit('python_format'), 0, False))

    def test_percent_format(self):
        self.assertFalse(
            self.check.check_format(u'%d%% string', u'%d%% string',
                                    MockUnit('python_percent_format'), 0,
                                    False))

    def test_named_format(self):
        self.assertFalse(
            self.check.check_format(u'%(name)s string', u'%(name)s string',
                                    MockUnit('python_named_format'), 0, False))

    def test_missing_format(self):
        self.assertTrue(
            self.check.check_format(u'%s string', u'string',
                                    MockUnit('python_missing_format'), 0,
                                    False))

    def test_missing_named_format(self):
        self.assertTrue(
            self.check.check_format(u'%(name)s string', u'string',
                                    MockUnit('python_missing_named_format'), 0,
                                    False))

    def test_missing_named_format_ignore(self):
        self.assertFalse(
            self.check.check_format(u'%(name)s string', u'string',
                                    MockUnit('python_missing_named_format'), 0,
                                    True))

    def test_wrong_format(self):
        self.assertTrue(
            self.check.check_format(u'%s string', u'%c string',
                                    MockUnit('python_wrong_format'), 0, False))

    def test_reordered_format(self):
        self.assertTrue(
            self.check.check_format(u'%s %d string', u'%d %s string',
                                    MockUnit('python_wrong_format'), 0, False))

    def test_wrong_named_format(self):
        self.assertTrue(
            self.check.check_format(u'%(name)s string', u'%(jmeno)s string',
                                    MockUnit('python_wrong_named_format'), 0,
                                    False))

    def test_reordered_named_format(self):
        self.assertFalse(
            self.check.check_format(u'%(name)s %(foo)s string',
                                    u'%(foo)s %(name)s string',
                                    MockUnit('python_reordered_named_format'),
                                    0, False))

    def test_reordered_named_format_long(self):
        self.assertFalse(
            self.check.check_format(
                u'%(count)d strings into %(languages)d languages %(percent)d%%',
                u'%(languages)d dil içinde %(count)d satır %%%(percent)d',
                MockUnit('python_reordered_named_format_long'), 0, False))
Пример #6
0
class PythonFormatCheckTest(TestCase):
    def setUp(self):
        self.check = PythonFormatCheck()

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

    def test_format(self):
        self.assertFalse(self.check.check_format(
            u'%s string',
            u'%s string',
            Unit('python_format'),
            0,
            False
        ))

    def test_percent_format(self):
        self.assertFalse(self.check.check_format(
            u'%d%% string',
            u'%d%% string',
            Unit('python_percent_format'),
            0,
            False
        ))

    def test_named_format(self):
        self.assertFalse(self.check.check_format(
            u'%(name)s string',
            u'%(name)s string',
            Unit('python_named_format'),
            0,
            False
        ))

    def test_missing_format(self):
        self.assertTrue(self.check.check_format(
            u'%s string',
            u'string',
            Unit('python_missing_format'),
            0,
            False
        ))

    def test_missing_named_format(self):
        self.assertTrue(self.check.check_format(
            u'%(name)s string',
            u'string',
            Unit('python_missing_named_format'),
            0,
            False
        ))

    def test_missing_named_format_ignore(self):
        self.assertFalse(self.check.check_format(
            u'%(name)s string',
            u'string',
            Unit('python_missing_named_format'),
            0,
            True
        ))

    def test_wrong_format(self):
        self.assertTrue(self.check.check_format(
            u'%s string',
            u'%c string',
            Unit('python_wrong_format'),
            0,
            False
        ))

    def test_wrong_named_format(self):
        self.assertTrue(self.check.check_format(
            u'%(name)s string',
            u'%(jmeno)s string',
            Unit('python_wrong_named_format'),
            0,
            False
        ))