Skip to content

Commit

Permalink
ruff fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Sep 25, 2024
1 parent 3937e8d commit 1b213b5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mark-parentheses = true
[tool.ruff.lint.per-file-ignores]
"docs/conf*.py" = ["ALL"]
"babelfish/__init__.py" = ["E402"]
"tests/*.py" = ["D", "S", "RUF012", "ANN", "FBT"]
"tests/*.py" = ["D", "S", "RUF012", "ANN", "FBT", "PT011"]

# https://docs.astral.sh/ruff/formatter/
[tool.ruff.format]
Expand Down
31 changes: 15 additions & 16 deletions tests/test_converters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from babelfish.converters import LanguageReverseConverter
# ruff: noqa: B018
import pytest
from babelfish import language_converters
from babelfish.compat import resource_stream
from babelfish.converters import LanguageReverseConverter
from babelfish.exceptions import LanguageConvertError, LanguageReverseError
from babelfish.language import Language

Expand Down Expand Up @@ -45,12 +46,12 @@ def test_converter_name():
assert len(language_converters['name'].codes) == 7874

def test_converter_scope():
assert language_converters['scope'].codes == set(['I', 'S', 'M'])
assert language_converters['scope'].codes == {'I', 'S', 'M'}
assert Language('eng').scope == 'individual'
assert Language('und').scope == 'special'

def test_converter_type():
assert language_converters['type'].codes == set(['A', 'C', 'E', 'H', 'L', 'S'])
assert language_converters['type'].codes == {'A', 'C', 'E', 'H', 'L', 'S'}
assert Language('eng').type == 'living'
assert Language('und').type == 'special'

Expand All @@ -74,20 +75,19 @@ def test_converter_opensubtitles():

# test with all the LANGUAGES from the opensubtitles api
# downloaded from: http://www.opensubtitles.org/addons/export_languages.php
f = resource_stream('babelfish', 'data/opensubtitles_languages.txt')
f.readline()
for l in f:
idlang, alpha2, _, upload_enabled, web_enabled = l.decode('utf-8').strip().split('\t')
if not int(upload_enabled) and not int(web_enabled):
# do not test LANGUAGES that are too esoteric / not widely available
continue
assert Language.fromopensubtitles(idlang).opensubtitles == idlang
if alpha2:
assert Language.fromopensubtitles(idlang) == Language.fromopensubtitles(alpha2)
f.close()
with resource_stream('babelfish', 'data/opensubtitles_languages.txt') as f:
f.readline()
for raw_line in f:
idlang, alpha2, _, upload_enabled, web_enabled = raw_line.decode('utf-8').strip().split('\t')
if not int(upload_enabled) and not int(web_enabled):
# do not test LANGUAGES that are too esoteric / not widely available
continue
assert Language.fromopensubtitles(idlang).opensubtitles == idlang
if alpha2:
assert Language.fromopensubtitles(idlang) == Language.fromopensubtitles(alpha2)

def test_converter_opensubtitles_codes():
for code in language_converters['opensubtitles'].from_opensubtitles.keys():
for code in language_converters['opensubtitles'].from_opensubtitles:
assert code in language_converters['opensubtitles'].codes

def test_register_converter():
Expand Down Expand Up @@ -118,4 +118,3 @@ def reverse(self, test):
Language.fromtest('test1')
with pytest.raises(AttributeError):
Language('fra').test

1 change: 1 addition & 0 deletions tests/test_country.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pickle

import pytest
from babelfish.country import Country

Expand Down
2 changes: 1 addition & 1 deletion tests/test_language.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import pickle

import pytest
from babelfish.country import Country
from babelfish.language import LANGUAGES, Language
from babelfish.script import Script
Expand Down
1 change: 1 addition & 0 deletions tests/test_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pickle

import pytest
from babelfish.script import Script

Expand Down

0 comments on commit 1b213b5

Please sign in to comment.