def test_spelling_id_multilpe_pwl(): """ Test spelling on source messages (English) of gettext files using multiple personal word lists. """ po_check = PoCheck() pwl_files = [ local_path('pwl1.txt'), local_path('pwl2.txt'), ] po_check.set_spelling_options('id', None, pwl_files) result = po_check.check_files([local_path('fr_spelling_id.po')]) # be sure we have 1 file in result assert len(result) == 1 # the file has 2 spelling errors: "Thsi" and "errro" report = result[0][1] assert len(report) == 2 for i, word in enumerate(('Thsi', 'errro')): assert report[i].idmsg == 'spelling-id' assert isinstance(report[i].message, list) assert len(report[i].message) == 1 assert report[i].message[0] == word assert report[i].get_misspelled_words() == [word]
def test_spelling_str(): """Test spelling on translated messages of gettext files.""" po_check = PoCheck() pwl_files = [local_path('pwl1.txt')] po_check.set_spelling_options('str', None, pwl_files) result = po_check.check_files( [local_path('fr_spelling_str.po'), local_path('fr_language.po')]) # be sure we have 2 files in result assert len(result) == 2 # first file has 3 spelling errors: "CecX", "aabbcc" and "xxyyzz" errors = result[0][1] assert len(errors) == 4 for i, word in enumerate(('testtwo', 'CecX', 'aabbcc', 'xxyyzz')): assert errors[i].idmsg == 'spelling-str' assert isinstance(errors[i].message, list) assert len(errors[i].message) == 1 assert errors[i].message[0] == word # second file has 1 error: dict/language "xyz" not found errors = result[1][1] assert len(errors) == 1 assert errors[0].idmsg == 'dict'
def test_spelling_str_multiple_pwl(): """ Test spelling on translated messages of gettext files using multiple personal word lists. """ po_check = PoCheck() pwl_files = [ local_path('pwl1.txt'), local_path('pwl2.txt'), ] po_check.set_spelling_options('str', None, pwl_files) result = po_check.check_files( [local_path('fr_spelling_str.po'), local_path('fr_language.po')]) # be sure we have 2 files in result assert len(result) == 2 # first file has 3 spelling errors: "CecX", "aabbcc" and "xxyyzz" report = result[0][1] assert len(report) == 3 for i, word in enumerate(('CecX', 'aabbcc', 'xxyyzz')): assert report[i].idmsg == 'spelling-str' assert isinstance(report[i].message, list) assert len(report[i].message) == 1 assert report[i].message[0] == word assert report[i].get_misspelled_words() == [word] # second file has 1 error: dict/language "xyz" not found report = result[1][1] assert len(report) == 1 assert report[0].idmsg == 'dict'
def test_spelling_str_multiple_pwl(self): """ Test spelling on translated messages of gettext files using multiple personal word lists. """ po_check = PoCheck() pwl_files = [ local_path('pwl1.txt'), local_path('pwl2.txt'), ] po_check.set_spelling_options('str', None, pwl_files) result = po_check.check_files([local_path('fr_spelling_str.po'), local_path('fr_language.po')]) # be sure we have 2 files in result self.assertEqual(len(result), 2) # first file has 3 spelling errors: "CecX", "aabbcc" and "xxyyzz" errors = result[0][1] self.assertEqual(len(errors), 3) for i, word in enumerate(('CecX', 'aabbcc', 'xxyyzz')): self.assertEqual(errors[i].idmsg, 'spelling-str') self.assertTrue(isinstance(errors[i].message, list)) self.assertEqual(len(errors[i].message), 1) self.assertEqual(errors[i].message[0], word) # second file has 1 error: dict/language "xyz" not found errors = result[1][1] self.assertEqual(len(errors), 1) self.assertEqual(errors[0].idmsg, 'dict')
def test_spelling_bad_pwl(self): """Test spelling with a bad pwl option.""" po_check = PoCheck() try: po_check.set_spelling_options("str", None, local_path("pwl_does_not_exist.txt")) except IOError: pass # this exception is expected else: self.fail("No problem when using a non-existing pwl file!")
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_spelling_bad_pwl(self): """Test spelling with a bad pwl option.""" po_check = PoCheck() try: po_check.set_spelling_options('str', None, local_path('pwl_does_not_exist.txt')) except IOError: pass # this exception is expected else: self.fail('No problem when using a non-existing pwl file!')
def test_spelling_bad_pwl(self): """Test spelling with a bad pwl option.""" po_check = PoCheck() try: pwl_files = [local_path('pwl_does_not_exist.txt')] po_check.set_spelling_options('str', None, pwl_files) except IOError: pass # this exception is expected else: self.fail('No problem when using a non-existing pwl file!')
def test_checks_fuzzy(self): """Test checks on a gettext file including fuzzy strings.""" po_check = PoCheck() po_check.set_check('fuzzy', 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 11 errors (with the fuzzy string) self.assertEqual(len(result[0][1]), 11)
def test_checks_fuzzy(): """Test checks on a gettext file including fuzzy strings.""" po_check = PoCheck() po_check.set_check('fuzzy', True) result = po_check.check_files([local_path('fr_errors.po')]) # be sure we have one file in result assert len(result) == 1 # the file has 11 errors (with the fuzzy string) assert len(result[0][1]) == 11
def test_checks_noqa(): """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 assert len(result) == 1 # the file has 9 errors (`noqa` was skipped) assert len(result[0][1]) == 9
def test_spelling_id(self): """Test spelling on source messages (English) of gettext files.""" po_check = PoCheck() po_check.set_spelling_options('id', None, local_path('pwl.txt')) result = po_check.check_files([local_path('fr_spelling_id.po')]) # be sure we have 1 file in result self.assertEqual(len(result), 1) # the file has 2 spelling errors: "Thsi" and "errro" errors = result[0][1] self.assertEqual(len(errors), 2) for i, word in enumerate(('Thsi', 'errro')): self.assertEqual(errors[i].idmsg, 'spelling-id') self.assertTrue(isinstance(errors[i].message, list)) self.assertEqual(len(errors[i].message), 1) self.assertEqual(errors[i].message[0], word)
def test_spelling_id(self): """Test spelling on source messages (English) of gettext files.""" po_check = PoCheck() po_check.set_spelling_options("id", None, local_path("pwl.txt")) result = po_check.check_files([local_path("fr_spelling_id.po")]) # be sure we have 1 file in result self.assertEqual(len(result), 1) # the file has 2 spelling errors: "Thsi" and "errro" errors = result[0][1] self.assertEqual(len(errors), 2) for i, word in enumerate(("Thsi", "errro")): self.assertEqual(errors[i].idmsg, "spelling-id") self.assertTrue(isinstance(errors[i].message, list)) self.assertEqual(len(errors[i].message), 1) self.assertEqual(errors[i].message[0], word)
def test_checks(): """Test checks on gettext files.""" po_check = PoCheck() result = po_check.check_files( [local_path('fr.po'), local_path('fr_errors.po')]) # be sure we have 2 files in result assert len(result) == 2 # first file has no errors assert not result[0][1] # second file has 10 errors assert len(result[1][1]) == 10 # check first error report = result[1][1][0] assert report.message == 'number of lines: 2 in string, 1 in translation' assert report.idmsg == 'lines' assert 'fr_errors.po' in report.filename assert report.line == 42 assert report.mid == 'Test 1 on two lines.\nLine 2.' assert report.mstr == 'Test 1 sur deux lignes.' assert report.fuzzy is False assert ('fr_errors.po:42: [lines] number of lines: ' '2 in string, 1 in translation' in str(report)) # check last error report = result[1][1][9] assert report.message == \ 'different whitespace at end of a line: 1 in string, 0 in translation' assert report.idmsg == 'whitespace_eol' assert 'fr_errors.po' in report.filename assert report.line == 74 assert report.mid == 'Line 1. \nLine 2.' assert report.mstr == 'Ligne 1.\nLigne 2.' assert report.fuzzy is False # check number of errors by type errors = {} for report in result[1][1]: errors[report.idmsg] = errors.get(report.idmsg, 0) + 1 assert errors['lines'] == 2 assert errors['punct'] == 2 assert errors['whitespace'] == 4 assert errors['whitespace_eol'] == 2
def test_spelling_id(): """Test spelling on source messages (English) of gettext files.""" po_check = PoCheck() pwl_files = [local_path('pwl1.txt')] po_check.set_spelling_options('id', None, pwl_files) result = po_check.check_files([local_path('fr_spelling_id.po')]) # be sure we have 1 file in result assert len(result) == 1 # the file has 2 spelling errors: "Thsi" and "errro" errors = result[0][1] assert len(errors) == 3 for i, word in enumerate(('Thsi', 'testtwo', 'errro')): assert errors[i].idmsg == 'spelling-id' assert isinstance(errors[i].message, list) assert len(errors[i].message) == 1 assert errors[i].message[0] == word
def test_spelling_id(self): """Test spelling on source messages (English) of gettext files.""" po_check = PoCheck() pwl_files = [local_path('pwl1.txt')] po_check.set_spelling_options('id', None, pwl_files) result = po_check.check_files([local_path('fr_spelling_id.po')]) # be sure we have 1 file in result self.assertEqual(len(result), 1) # the file has 2 spelling errors: "Thsi" and "errro" errors = result[0][1] self.assertEqual(len(errors), 3) for i, word in enumerate(('Thsi', 'testtwo', 'errro')): self.assertEqual(errors[i].idmsg, 'spelling-id') self.assertTrue(isinstance(errors[i].message, list)) self.assertEqual(len(errors[i].message), 1) self.assertEqual(errors[i].message[0], word)
def test_checks(self): """Test checks on gettext files.""" po_check = PoCheck() result = po_check.check_files([local_path("fr.po"), local_path("fr_errors.po")]) # be sure we have 2 files in result self.assertEqual(len(result), 2) # first file has no errors self.assertEqual(len(result[0][1]), 0) # second file has 10 errors self.assertEqual(len(result[1][1]), 10) errors = {} for report in result[1][1]: errors[report.idmsg] = errors.get(report.idmsg, 0) + 1 self.assertEqual(errors["lines"], 2) self.assertEqual(errors["punct"], 2) self.assertEqual(errors["whitespace"], 4) self.assertEqual(errors["whitespace_eol"], 2)
def test_checks(self): """Test checks on gettext files.""" po_check = PoCheck() result = po_check.check_files([local_path('fr.po'), local_path('fr_errors.po')]) # be sure we have 2 files in result self.assertEqual(len(result), 2) # first file has no errors self.assertEqual(len(result[0][1]), 0) # second file has 10 errors self.assertEqual(len(result[1][1]), 10) errors = {} for report in result[1][1]: errors[report.idmsg] = errors.get(report.idmsg, 0) + 1 self.assertEqual(errors['lines'], 2) self.assertEqual(errors['punct'], 2) self.assertEqual(errors['whitespace'], 4) self.assertEqual(errors['whitespace_eol'], 2)
def test_checks(): """Test checks on gettext files.""" po_check = PoCheck() result = po_check.check_files( [local_path('fr.po'), local_path('fr_errors.po')]) # be sure we have 2 files in result assert len(result) == 2 # first file has no errors assert not result[0][1] # second file has 10 errors assert len(result[1][1]) == 10 errors = {} for report in result[1][1]: errors[report.idmsg] = errors.get(report.idmsg, 0) + 1 assert errors['lines'] == 2 assert errors['punct'] == 2 assert errors['whitespace'] == 4 assert errors['whitespace_eol'] == 2
def test_spelling_str(self): """Test spelling on translated messages of gettext files.""" po_check = PoCheck() po_check.set_spelling_options("str", None, local_path("pwl.txt")) result = po_check.check_files([local_path("fr_spelling_str.po"), local_path("fr_language.po")]) # be sure we have 2 files in result self.assertEqual(len(result), 2) # first file has 3 spelling errors: "CecX", "aabbcc" and "xxyyzz" errors = result[0][1] self.assertEqual(len(errors), 3) for i, word in enumerate(("CecX", "aabbcc", "xxyyzz")): self.assertEqual(errors[i].idmsg, "spelling-str") self.assertTrue(isinstance(errors[i].message, list)) self.assertEqual(len(errors[i].message), 1) self.assertEqual(errors[i].message[0], word) # second file has 1 error: dict/language "xyz" not found errors = result[1][1] self.assertEqual(len(errors), 1) self.assertEqual(errors[0].idmsg, "dict")
def test_extract(): """Test extract on a gettext file.""" po_check = PoCheck() po_check.set_check('extract', True) result = po_check.check_files([local_path('fr.po')]) assert len(result) == 1 assert 'fr.po' in result[0][0] assert len(result[0][1]) == 3 report = result[0][1][0] assert report.message == 'Ceci est un test.\n' assert report.idmsg == 'extract' assert report.filename == '-' assert report.line == 0 assert report.mid == '' assert report.mstr == '' assert report.fuzzy is False assert str(report) == 'Ceci est un test.\n\n---' report = result[0][1][1] assert report.message == 'Test sur deux lignes.\nLigne 2.' assert report.idmsg == 'extract' assert report.filename == '-' assert report.line == 0 assert report.mid == '' assert report.mstr == '' assert report.fuzzy is False assert str(report) == 'Test sur deux lignes.\nLigne 2.\n---' report = result[0][1][2] assert report.message == ' erreur : %s' assert report.idmsg == 'extract' assert report.filename == '-' assert report.line == 0 assert report.mid == '' assert report.mstr == '' assert report.fuzzy is False assert str(report) == ' erreur : %s\n---'
def test_spelling_str(self): """Test spelling on translated messages of gettext files.""" po_check = PoCheck() po_check.set_spelling_options('str', None, local_path('pwl.txt')) result = po_check.check_files([local_path('fr_spelling_str.po'), local_path('fr_language.po')]) # be sure we have 2 files in result self.assertEqual(len(result), 2) # first file has 3 spelling errors: "CecX", "aabbcc" and "xxyyzz" errors = result[0][1] self.assertEqual(len(errors), 3) for i, word in enumerate(('CecX', 'aabbcc', 'xxyyzz')): self.assertEqual(errors[i].idmsg, 'spelling-str') self.assertTrue(isinstance(errors[i].message, list)) self.assertEqual(len(errors[i].message), 1) self.assertEqual(errors[i].message[0], word) # second file has 1 error: dict/language "xyz" not found errors = result[1][1] self.assertEqual(len(errors), 1) self.assertEqual(errors[0].idmsg, 'dict')
def test_spelling_bad_pwl(): """Test spelling with a bad pwl option.""" po_check = PoCheck() with pytest.raises(IOError): pwl_files = [local_path('pwl_does_not_exist.txt')] po_check.set_spelling_options('str', None, pwl_files)
def test_spelling_bad_dict(): """Test spelling with a bad dict option.""" po_check = PoCheck() po_check.set_spelling_options('str', 'xxx', None) assert not po_check.extra_checkers
def test_spelling_bad_dict(self): """Test spelling with a bad dict option.""" po_check = PoCheck() po_check.set_spelling_options('str', 'xxx', None) self.assertEqual(len(po_check.extra_checkers), 0)