-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix testing tools, add first tests
- Loading branch information
Showing
7 changed files
with
179 additions
and
3 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,13 +1,25 @@ | ||
import subprocess | ||
|
||
import typer | ||
from typer.testing import CliRunner | ||
|
||
from first_steps.tutorial001 import main | ||
from first_steps import tutorial001 as mod | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_cli(): | ||
app = typer.Typer() | ||
app.command()(main) | ||
app.command()(mod.main) | ||
result = runner.invoke(app, []) | ||
assert result.output == "Hello World\n" | ||
|
||
|
||
def test_script(): | ||
result = subprocess.run( | ||
["coverage", "run", "--parallel-mode", mod.__file__, "--help"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
encoding="utf-8", | ||
) | ||
assert "Usage" in result.stdout |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import subprocess | ||
|
||
import typer | ||
from typer.testing import CliRunner | ||
|
||
from first_steps import tutorial002 as mod | ||
|
||
runner = CliRunner() | ||
|
||
app = typer.Typer() | ||
app.command()(mod.main) | ||
|
||
|
||
def test_1(): | ||
result = runner.invoke(app, []) | ||
assert result.exit_code != 0 | ||
assert 'Error: Missing argument "NAME"' in result.output | ||
|
||
|
||
def test_2(): | ||
result = runner.invoke(app, ["Camila"]) | ||
assert result.exit_code == 0 | ||
assert "Hello Camila" in result.output | ||
|
||
|
||
def test_script(): | ||
result = subprocess.run( | ||
["coverage", "run", "--parallel-mode", mod.__file__, "--help"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
encoding="utf-8", | ||
) | ||
assert "Usage" in result.stdout |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import subprocess | ||
|
||
import typer | ||
from typer.testing import CliRunner | ||
|
||
from first_steps import tutorial003 as mod | ||
|
||
runner = CliRunner() | ||
|
||
app = typer.Typer() | ||
app.command()(mod.main) | ||
|
||
|
||
def test_1(): | ||
result = runner.invoke(app, ["Camila"]) | ||
assert result.exit_code != 0 | ||
assert 'Error: Missing argument "LASTNAME"' in result.output | ||
|
||
|
||
def test_2(): | ||
result = runner.invoke(app, ["Camila", "Gutiérrez"]) | ||
assert result.exit_code == 0 | ||
assert "Hello Camila Gutiérrez" in result.output | ||
|
||
|
||
def test_script(): | ||
result = subprocess.run( | ||
["coverage", "run", "--parallel-mode", mod.__file__, "--help"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
encoding="utf-8", | ||
) | ||
assert "Usage" in result.stdout |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import subprocess | ||
|
||
import typer | ||
from typer.testing import CliRunner | ||
|
||
from first_steps import tutorial004 as mod | ||
|
||
runner = CliRunner() | ||
|
||
app = typer.Typer() | ||
app.command()(mod.main) | ||
|
||
|
||
def test_1(): | ||
result = runner.invoke(app, ["Camila", "Gutiérrez"]) | ||
assert result.exit_code == 0 | ||
assert "Hello Camila Gutiérrez" in result.output | ||
|
||
|
||
def test_formal_1(): | ||
result = runner.invoke(app, ["Camila", "Gutiérrez", "--formal"]) | ||
assert result.exit_code == 0 | ||
assert "Good day Ms. Camila Gutiérrez." in result.output | ||
|
||
|
||
def test_formal_2(): | ||
result = runner.invoke(app, ["Camila", "--formal", "Gutiérrez"]) | ||
assert result.exit_code == 0 | ||
assert "Good day Ms. Camila Gutiérrez." in result.output | ||
|
||
|
||
def test_formal_3(): | ||
result = runner.invoke(app, ["--formal", "Camila", "Gutiérrez"]) | ||
assert result.exit_code == 0 | ||
assert "Good day Ms. Camila Gutiérrez." in result.output | ||
|
||
|
||
def test_script(): | ||
result = subprocess.run( | ||
["coverage", "run", "--parallel-mode", mod.__file__, "--help"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
encoding="utf-8", | ||
) | ||
assert "Usage" in result.stdout |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import subprocess | ||
|
||
import typer | ||
from typer.testing import CliRunner | ||
|
||
from first_steps import tutorial005 as mod | ||
|
||
runner = CliRunner() | ||
|
||
app = typer.Typer() | ||
app.command()(mod.main) | ||
|
||
|
||
def test_help(): | ||
result = runner.invoke(app, ["--help"]) | ||
assert result.exit_code == 0 | ||
assert "--lastname TEXT" in result.output | ||
assert "--formal / --no-formal" in result.output | ||
|
||
|
||
def test_1(): | ||
result = runner.invoke(app, ["Camila"]) | ||
assert result.exit_code == 0 | ||
assert "Hello Camila" in result.output | ||
|
||
|
||
def test_option_lastname(): | ||
result = runner.invoke(app, ["Camila", "--lastname", "Gutiérrez"]) | ||
assert result.exit_code == 0 | ||
assert "Hello Camila Gutiérrez" in result.output | ||
|
||
|
||
def test_option_lastname_2(): | ||
result = runner.invoke(app, ["--lastname", "Gutiérrez", "Camila"]) | ||
assert result.exit_code == 0 | ||
assert "Hello Camila Gutiérrez" in result.output | ||
|
||
|
||
def test_formal_1(): | ||
result = runner.invoke(app, ["Camila", "--lastname", "Gutiérrez", "--formal"]) | ||
assert result.exit_code == 0 | ||
assert "Good day Ms. Camila Gutiérrez." in result.output | ||
|
||
|
||
def test_script(): | ||
result = subprocess.run( | ||
["coverage", "run", "--parallel-mode", mod.__file__, "--help"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
encoding="utf-8", | ||
) | ||
assert "Usage" in result.stdout |
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