powrap/tests/test_powrap.py

45 lines
1.4 KiB
Python
Raw Permalink Normal View History

2019-12-10 09:09:21 +00:00
from pathlib import Path
import pytest
2020-09-29 15:04:53 +00:00
import os
2019-12-10 09:09:21 +00:00
from powrap import powrap
FIXTURE_DIR = Path(__file__).resolve().parent
2020-09-29 15:04:53 +00:00
@pytest.mark.parametrize("po_file", (FIXTURE_DIR / "bad" / "glossary.po",))
2020-12-03 12:10:26 +00:00
def test_fail_on_bad_wrapping(po_file, capsys):
assert powrap.check_style([po_file]) == 1
assert str(po_file) in capsys.readouterr().err
2019-12-10 09:09:21 +00:00
@pytest.mark.parametrize("po_file", (FIXTURE_DIR / "good").glob("*.po"))
2022-04-26 12:43:54 +00:00
def test_success_on_good_wrapping(po_file, capsys):
2020-12-03 12:10:26 +00:00
assert powrap.check_style([po_file]) == 0
assert str(po_file) not in capsys.readouterr().err
2020-09-29 15:04:53 +00:00
@pytest.mark.parametrize("po_file", (FIXTURE_DIR / "bad" / "invalid_po_file.po",))
2020-12-03 12:10:26 +00:00
def test_msgcat_error(po_file, capsys):
assert powrap.check_style([po_file]) == 0
assert str(po_file) not in capsys.readouterr().err
2020-09-29 15:04:53 +00:00
@pytest.mark.parametrize("po_file", ("non_existent_file.po",))
2020-12-03 12:10:26 +00:00
def test_fileread_error(po_file, capsys):
assert powrap.check_style([po_file]) == 0
assert str(po_file) not in capsys.readouterr().err
2020-09-29 15:04:53 +00:00
@pytest.mark.parametrize("po_file", (FIXTURE_DIR / "good").glob("*.po"))
def test_wrong_msgcat(po_file):
2020-12-03 12:10:26 +00:00
"""Test if msgcat is not available"""
2020-09-29 15:04:53 +00:00
environ_saved = os.environ["PATH"]
os.environ["PATH"] = ""
with pytest.raises(SystemExit) as sysexit:
powrap.check_style([po_file])
os.environ["PATH"] = environ_saved
assert sysexit.type == SystemExit
assert sysexit.value.code == 127