Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add test to check spelling #1073

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
desktop-file-utils
appstream-glib
myspell-en_US myspell-cs_CZ
myspell-fr_FR
python3-pyenchant
if: ${{ contains(matrix.container, 'opensuse') && matrix.build-type == 'normal' }}
- run: zypper -n install python3-flake8-comprehensions
Expand Down Expand Up @@ -98,6 +99,7 @@ jobs:
devscripts-checkbashisms
hunspell-en
hunspell-cs
hunspell-fr
python3-enchant
if: ${{ contains(matrix.container, 'fedora') && matrix.build-type == 'normal' }}
- run: rm -rf $(rpm --eval '%_dbpath')
Expand Down
2 changes: 2 additions & 0 deletions .packit/rpmlint.spec
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ BuildRequires: /usr/bin/desktop-file-validate
%if 0%{?suse_version}
BuildRequires: myspell-en_US
BuildRequires: myspell-cs_CZ
BuildRequires: myspell-fr_FR
%else
BuildRequires: hunspell-en
BuildRequires: hunspell-cs
BuildRequires: hunspell-fr
%endif

%if 0%{?fedora} || 0%{?rhel} >= 8
Expand Down
4 changes: 4 additions & 0 deletions rpmlint/spellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def spell_check(self, text, fmt, lang='en_US', pkgname='', ignored_words=None):
warned = set()
suggestions = {}

# C lang is 'en_US'
if lang == 'C':
lang = 'en_US'

# Initialize spelling dictionary if not already done
if lang not in self._enchant_checkers:
self._init_checker(lang)
Expand Down
1 change: 1 addition & 0 deletions test/Testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def _has_dictionary(language):

HAS_ENGLISH_DICTIONARY = _has_dictionary('en_US')
HAS_CZECH_DICTIONARY = _has_dictionary('cs_CZ')
HAS_FRENCH_DICTIONARY = _has_dictionary('fr')


def get_tested_path(*paths):
Expand Down
Binary file added test/binary/spellingerrors-default-0-0.noarch.rpm
Binary file not shown.
Binary file added test/binary/spellingerrors-lang-0-0.noarch.rpm
Binary file not shown.
Binary file added test/binary/spellingerrors-lang2-0-0.noarch.rpm
Binary file not shown.
Binary file added test/binary/spellingerrors-lang3-0-0.noarch.rpm
Binary file not shown.
18 changes: 18 additions & 0 deletions test/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytest
from rpmlint.checks.TagsCheck import TagsCheck
from rpmlint.filter import Filter
import rpmlint.spellcheck

from Testing import CONFIG, get_tested_package
from Testing import HAS_ENGLISH_DICTIONARY, HAS_FRENCH_DICTIONARY


@pytest.fixture(scope='function', autouse=True)
Expand Down Expand Up @@ -421,3 +423,19 @@ def test_summary_on_multiple_lines(tmp_path, package, tagscheck):
test.check(get_tested_package(package, tmp_path))
out = output.print_results(output.results)
assert 'E: summary-on-multiple-lines' in out


@pytest.mark.skipif(not rpmlint.spellcheck.ENCHANT, reason='Missing enchant bindings')
@pytest.mark.skipif(not HAS_ENGLISH_DICTIONARY, reason='Missing English dictionary')
@pytest.mark.skipif(not HAS_FRENCH_DICTIONARY, reason='Missing French dictionary')
@pytest.mark.parametrize('package', [
'binary/spellingerrors-default',
'binary/spellingerrors-lang',
'binary/spellingerrors-lang2',
'binary/spellingerrors-lang3',
])
def test_description_spelling_error(tmp_path, package, tagscheck):
output, test = tagscheck
test.check(get_tested_package(package, tmp_path))
out = output.print_results(output.results)
assert 'E: spelling-error' in out