-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Henry Schreiner <[email protected]>
- Loading branch information
Showing
2 changed files
with
58 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,57 @@ | ||
# Setting French as system language | ||
import os | ||
os.environ['LC_ALL'] = 'fr_FR.utf-8' | ||
from __future__ import annotations | ||
|
||
import importlib | ||
import locale | ||
|
||
import pytest | ||
import sys | ||
|
||
from plumbum import cli | ||
import plumbum.cli | ||
import plumbum.cli.i18n | ||
|
||
|
||
def reload_cli(): | ||
importlib.reload(plumbum.cli.i18n) | ||
importlib.reload(plumbum.cli.switches) | ||
importlib.reload(plumbum.cli.application) | ||
importlib.reload(plumbum.cli) | ||
|
||
|
||
@pytest.fixture() | ||
def french(): | ||
try: | ||
locale.setlocale(locale.LC_ALL, "fr_FR") | ||
reload_cli() | ||
yield | ||
finally: | ||
locale.setlocale(locale.LC_ALL, "") | ||
reload_cli() | ||
|
||
|
||
@pytest.mark.usefixtures("french") | ||
def test_nolang_switches(): | ||
class Simple(plumbum.cli.Application): | ||
foo = plumbum.cli.SwitchAttr("--foo") | ||
|
||
def main(self): | ||
pass | ||
|
||
_, rc = Simple.run(["foo", "-h"], exit=False) | ||
assert rc == 0 | ||
_, rc = Simple.run(["foo", "--version"], exit=False) | ||
assert rc == 0 | ||
|
||
class Simple(cli.Application): | ||
foo = cli.SwitchAttr("--foo") | ||
|
||
def main(self): | ||
pass | ||
@pytest.mark.usefixtures("french") | ||
def test_help_lang(capsys): | ||
class Simple(plumbum.cli.Application): | ||
foo = plumbum.cli.SwitchAttr("--foo") | ||
|
||
class TestFRCLI: | ||
def test_nolang_switches(self): | ||
_, rc = Simple.run(["foo", "-h"], exit = False) | ||
assert rc == 0 | ||
_, rc = Simple.run(["foo", "--version"], exit = False) | ||
assert rc == 0 | ||
def main(self): | ||
pass | ||
|
||
def test_help_lang(self, capsys): | ||
_, rc = Simple.run(["foo", "-h"], exit = False) | ||
assert rc == 0 | ||
stdout, stderr = capsys.readouterr() | ||
assert "Utilisation" in stdout | ||
assert "Imprime ce message d'aide et sort" in stdout | ||
_, rc = Simple.run(["foo", "-h"], exit=False) | ||
assert rc == 0 | ||
stdout, stderr = capsys.readouterr() | ||
assert "Utilisation" in stdout | ||
assert "Imprime ce message d'aide et sort" in stdout |