Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • flashcode/msgcheck
1 result
Show changes
Commits on Source (5)
Loading
Loading
@@ -6,7 +6,8 @@
 
== Version 2.9 (under dev)
 
* remove C printf formatters for spell checking
* add option "-n" (or "--skip-noqa") to not check "noqa"-commented lines (issue #2, issue #7)
* remove C and Python string formatters for spell checking (issue #3)
 
== Version 2.8 (2014-12-07)
 
Loading
Loading
Loading
Loading
@@ -47,6 +47,7 @@ Options:
* `-h`, `--help`: display help message and exit
* `-c`, `--no-compile`: do not check compilation of file (with `msgfmt -c`)
* `-f`, `--fuzzy`: check fuzzy strings
* `-n`, `--skip-noqa`: do not check "noqa"-commented lines
* `-l`, `--no-lines`: do not check number of lines
* `-p`, `--no-punct`: do not check punctuation at end of strings
* `-s id|str`, `--spelling id|str`: check spelling (`id` = source messages,
Loading
Loading
Loading
Loading
@@ -65,6 +65,8 @@ The script returns:
help='do not check compilation of file')
parser.add_argument('-f', '--fuzzy', action='store_true',
help='check fuzzy strings')
parser.add_argument('-n', '--skip-noqa', action='store_true',
help='do not check "noqa"-commented lines')
parser.add_argument('-l', '--no-lines', action='store_true',
help='do not check number of lines')
parser.add_argument('-p', '--no-punct', action='store_true',
Loading
Loading
@@ -99,8 +101,7 @@ The script returns:
return parser
 
 
# pylint: disable=too-many-branches
def main():
def main(): # pylint: disable=too-many-branches
"""Main function."""
# parse arguments
parser = msgcheck_parser()
Loading
Loading
@@ -112,7 +113,7 @@ def main():
 
# create checker and set boolean options
po_check = PoCheck()
for option in ('no_compile', 'fuzzy', 'no_lines', 'no_punct',
for option in ('no_compile', 'fuzzy', 'skip_noqa', 'no_lines', 'no_punct',
'no_whitespace', 'no_whitespace_eol', 'extract'):
if args.__dict__[option]:
po_check.set_check(option.lstrip('no_'),
Loading
Loading
Loading
Loading
@@ -42,12 +42,10 @@ except ImportError:
from . utils import count_lines, replace_formatters
 
 
# pylint: disable=too-few-public-methods
class PoReport(object):
class PoReport(object): # pylint: disable=too-few-public-methods
"""A message in report (commonly an error in detected in gettext file)."""
 
# pylint: disable=too-many-arguments
def __init__(self, message, idmsg='', filename='-', line=0, mid='',
def __init__(self, message, idmsg='', filename='-', line=0, mid='', # pylint: disable=too-many-arguments
mstr='', fuzzy=False):
self.message = message
self.idmsg = idmsg
Loading
Loading
@@ -109,8 +107,7 @@ class PoMessage(object):
('%d files found', '%d fichiers trouvés')]
"""
 
# pylint: disable=too-many-arguments
def __init__(self, filename, line, msg, charset, fuzzy, fmt):
def __init__(self, filename, line, msg, charset, fuzzy, fmt, noqa): # pylint: disable=too-many-arguments
"""Build a PO message."""
self.filename = filename
self.line = line
Loading
Loading
@@ -136,6 +133,7 @@ class PoMessage(object):
self.messages.append((msg.get('msgid', ''), msg.get('msgstr', '')))
self.fuzzy = fuzzy
self.fmt = fmt
self.noqa = noqa
 
def check_lines(self):
"""
Loading
Loading
@@ -297,7 +295,7 @@ class PoFile(object):
}
self.msgs = []
 
def _add_message(self, numline_msgid, fuzzy, fmt, msg):
def _add_message(self, numline_msgid, fuzzy, fmt, noqa, msg): # pylint: disable=too-many-arguments
"""
Add a message from PO file in list of messages.
"""
Loading
Loading
@@ -314,15 +312,16 @@ class PoFile(object):
if match:
self.props['charset'] = match.group(1)
self.msgs.append(PoMessage(self.filename, numline_msgid, msg,
self.props['charset'], fuzzy, fmt))
self.props['charset'], fuzzy, fmt, noqa))
 
def read(self):
def read(self): # pylint: disable=too-many-locals
"""
Read messages in PO file.
"""
self.msgs = []
numline, numline_msgid = (0, 0)
fuzzy, msgfuzzy = (False, False)
noqa, msgnoqa = (False, False)
fmt, msgfmt = (None, None)
msg = {}
msgcurrent = ''
Loading
Loading
@@ -337,6 +336,7 @@ class PoFile(object):
match = re.search(r'([a-z-]+)-format', line, re.IGNORECASE)
fmt = match.group(1) if match else None
if line.startswith('#'):
noqa = 'noqa' in line
continue
if line.startswith('msg'):
match = re.match(
Loading
Loading
@@ -351,9 +351,12 @@ class PoFile(object):
self._add_message(numline_msgid,
msgfuzzy,
msgfmt,
msgnoqa,
msg)
msgfuzzy = fuzzy
msgnoqa = noqa
fuzzy = False
noqa = False
msgfmt = fmt
fmt = None
msg = {}
Loading
Loading
@@ -364,6 +367,7 @@ class PoFile(object):
self._add_message(numline_msgid,
msgfuzzy,
msgfmt,
msgnoqa,
msg)
 
def compile(self):
Loading
Loading
@@ -389,6 +393,7 @@ class PoCheck(object):
self.checks = {
'compile': True,
'fuzzy': False,
'skip_noqa': False,
'lines': True,
'punct': True,
'whitespace': True,
Loading
Loading
@@ -478,7 +483,10 @@ class PoCheck(object):
 
# check all messages
check_fuzzy = self.checks['fuzzy']
skip_noqa = self.checks['skip_noqa']
for msg in po_file.msgs:
if skip_noqa and msg.noqa:
continue
if msg.fuzzy and not check_fuzzy:
continue
if self.checks['extract']:
Loading
Loading
Loading
Loading
@@ -38,7 +38,7 @@ STR_FORMATTERS.update({
'python': (
(r'[\%]{2}', '%'),
(r'\%([.\d]+)?[bcdeEfFgGnosxX]', r''),
(r'\%(\(([^)]*)\))([.\d]+)?[bcdeEfFgGnosxX]', r'\g<2>'),
(r'\%(\([^)]*\))([.\d]+)?[bcdeEfFgGnosxX]', r''),
(r'\{([^\:\}]*)?(:[^\}]*)?\}', r''),
),
})
Loading
Loading
Loading
Loading
@@ -48,6 +48,7 @@ msgstr "Test 2 sur deux lignes.\nLigne 2.\nLigne 3."
msgid "Tested 1."
msgstr "Testé 1"
 
#, noqa
msgid "Tested 2"
msgstr "Testé 2."
 
Loading
Loading
Loading
Loading
@@ -34,8 +34,7 @@ def local_path(filename):
return os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
 
 
# pylint: disable=too-many-public-methods
class TestMsgCheck(unittest.TestCase):
class TestMsgCheck(unittest.TestCase): # pylint: disable=too-many-public-methods
"""Tests on msgcheck."""
 
def test_compilation(self):
Loading
Loading
@@ -96,6 +95,17 @@ class TestMsgCheck(unittest.TestCase):
# the file has 11 errors (with the fuzzy string)
self.assertEqual(len(result[0][1]), 11)
 
def test_checks_noqa(self):
"""Test checks on a gettext file ignoring `noqa`-commented lines."""
po_check = PoCheck()
po_check.set_check('skip_noqa', True)
result = po_check.check_files([local_path('fr_errors.po')])
# be sure we have one file in result
self.assertEqual(len(result), 1)
# the file has 9 errors (`noqa` was skipped)
self.assertEqual(len(result[0][1]), 9)
def test_replace_formatters_c(self):
"""Test removal of formatters in a C string."""
self.assertEqual(replace_formatters('%s', 'c'), '')
Loading
Loading
@@ -117,8 +127,8 @@ class TestMsgCheck(unittest.TestCase):
self.assertEqual(replace_formatters('%b', 'python'), '')
self.assertEqual(replace_formatters('%%', 'python'), '%')
self.assertEqual(replace_formatters('%.02f', 'python'), '')
self.assertEqual(replace_formatters('%(sth)s', 'python'), 'sth')
self.assertEqual(replace_formatters('%(sth)02f', 'python'), 'sth')
self.assertEqual(replace_formatters('%(sth)s', 'python'), '')
self.assertEqual(replace_formatters('%(sth)02f', 'python'), '')
# str.format()
conditions = (
('First, thou shalt count to {0}',
Loading
Loading