-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add python project template skeleton
- Loading branch information
Showing
7 changed files
with
146 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
main module initialization | ||
set up for module execution | ||
""" | ||
|
||
from helloworld.main import main | ||
|
||
__all__ = ["main"] |
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,10 @@ | ||
""" | ||
helloworld module execution | ||
Entrypoint when running module: python -m helloworld | ||
""" | ||
|
||
from helloworld import main as cli | ||
|
||
if __name__ == "__main__": # pragma: no cover | ||
cli() |
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,23 @@ | ||
""" | ||
helloworld tool main module | ||
""" | ||
|
||
import sys | ||
|
||
from rich.traceback import install | ||
|
||
from helloworld import prompt | ||
|
||
install() # setup rich | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Runs the cli application code. | ||
""" | ||
|
||
prompt.say(" ".join(sys.argv[1:])) | ||
|
||
|
||
if __name__ == "__main__": # pragma: no cover | ||
main() |
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,19 @@ | ||
""" | ||
Writes text prompts. | ||
""" | ||
|
||
|
||
def words(message: str) -> str: | ||
r""" | ||
Generates the string message. | ||
""" | ||
|
||
return message.rstrip() | ||
|
||
|
||
def say(message: str) -> None: | ||
r""" | ||
Writes the message. | ||
""" | ||
|
||
print(words(message)) |
Empty file.
Empty file.
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,85 @@ | ||
""" | ||
Cli/Main Tests | ||
""" | ||
|
||
import os.path | ||
import subprocess # nosec | ||
import sys | ||
from typing import Any, List, Union | ||
|
||
import pytest | ||
from _pytest.capture import CaptureFixture, CaptureResult | ||
|
||
# Our Project | ||
from helloworld import main as cli | ||
|
||
unit_test_data: List[List[str]] = [ | ||
[ | ||
"hello", | ||
"hello", | ||
], | ||
[ | ||
"hello world!", | ||
"hello world!", | ||
], | ||
] | ||
|
||
# [[input, expected], ...] | ||
integration_test_data: List[List[Union[str, List[str]]]] = [ | ||
[ | ||
"Hello World!", | ||
"Hello World!", | ||
], | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("message,expected", unit_test_data) | ||
def test_method_with_input(message: str, expected: List[str], capsys: CaptureFixture) -> None: | ||
"""Runs the class methods against all of our test data.""" | ||
|
||
captured_out: List[str] | ||
expected_out: List[str] | ||
|
||
sys.argv = ["helloworld"] + message.split(" ") | ||
|
||
# discard previous output | ||
captured: CaptureResult[Any] = capsys.readouterr() | ||
cli() | ||
captured = capsys.readouterr() # capture new output | ||
|
||
# captured_out = captured.out.split("\n") | ||
captured_out = [*captured.out] | ||
# expected_out = [str(number) for number in expected] | ||
expected_out = [*expected] | ||
|
||
print(f"{captured_out} == {expected_out}") | ||
assert all(e == o for e, o in zip(captured_out, expected_out)) | ||
|
||
|
||
@pytest.mark.parametrize("message,expected", integration_test_data) | ||
def test_script(message: str, expected: List[str]) -> None: | ||
"""Runs the main script against all of our test data.""" | ||
|
||
program_input: str = "" | ||
|
||
process: subprocess.CompletedProcess = subprocess.run( | ||
[ | ||
"python", | ||
os.path.dirname("src/helloworld/"), | ||
message, | ||
], | ||
check=False, | ||
input=program_input, | ||
stdout=subprocess.PIPE, | ||
) # nosec | ||
|
||
program_output: str = process.stdout.decode("utf-8").strip() | ||
# program_output: str = process.stdout.decode("utf-8") | ||
# program_out: List[str] = program_output.split("\n") | ||
program_out: List[str] = [*program_output] | ||
|
||
# expected_out: List[int] = [str(number) for number in expected] | ||
expected_out: List[str] = [*expected] | ||
|
||
print(f" program_out: {program_out}\n==\nexpected_out: {expected_out}") | ||
assert all(e == o for e, o in zip(program_out, expected_out)) |