Skip to content

Commit

Permalink
use typer.testing.CliRunner instead of subprocess for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hitblast committed Jul 29, 2024
1 parent d10d420 commit 520988d
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
# SPDX-License-Identifier: MIT

# Import third-party Python modules.
from typer.testing import CliRunner

# Import first-party Python modules.
import subprocess
# Import the module containing the CLI commands.
from avnie.main import app


# Test cases.
def test_parse_english_to_bengali(mocker):
mocker.patch(
"subprocess.run",
return_value=subprocess.CompletedProcess(
args=["avnie", "parse", "hello"], returncode=0, stdout="হ্যালো"
),
)
result = subprocess.run(["avnie", "parse", "hello"], capture_output=True, text=True)
def test_parse_english_to_bengali():
runner = CliRunner()
result = runner.invoke(app, ["parse", "hyalO"])
assert result.exit_code == 0
assert result.stdout.strip() == "হ্যালো"


def test_reverse_bengali_to_english(mocker):
mocker.patch(
"subprocess.run",
return_value=subprocess.CompletedProcess(
args=["avnie", "reverse", "হ্যালো"], returncode=0, stdout="hello"
),
)
result = subprocess.run(
["avnie", "reverse", "হ্যালো"], capture_output=True, text=True
)
assert result.stdout.strip() == "hello"
def test_reverse_bengali_to_english():
runner = CliRunner()
result = runner.invoke(app, ["reverse", "আমি বাংলায় গান গাই"])
assert result.exit_code == 0
assert result.stdout.strip() == "ami banglay gan gai"

0 comments on commit 520988d

Please sign in to comment.