rastas 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rastas-0.1.0/.gitignore +32 -0
- rastas-0.1.0/LICENSE +21 -0
- rastas-0.1.0/PKG-INFO +114 -0
- rastas-0.1.0/README.md +67 -0
- rastas-0.1.0/pyproject.toml +42 -0
- rastas-0.1.0/src/rastas/__init__.py +6 -0
- rastas-0.1.0/src/rastas/cli.py +66 -0
- rastas-0.1.0/src/rastas/say.py +128 -0
- rastas-0.1.0/tests/test_rastas.py +77 -0
rastas-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
.eggs/
|
|
11
|
+
wheels/
|
|
12
|
+
|
|
13
|
+
# Virtual environments
|
|
14
|
+
.venv/
|
|
15
|
+
venv/
|
|
16
|
+
ENV/
|
|
17
|
+
|
|
18
|
+
# Secrets & local config
|
|
19
|
+
.env
|
|
20
|
+
.env.*
|
|
21
|
+
.pypirc
|
|
22
|
+
|
|
23
|
+
# Test & coverage caches
|
|
24
|
+
.pytest_cache/
|
|
25
|
+
.coverage
|
|
26
|
+
htmlcov/
|
|
27
|
+
|
|
28
|
+
# Editor / OS
|
|
29
|
+
.vscode/
|
|
30
|
+
.idea/
|
|
31
|
+
.DS_Store
|
|
32
|
+
Thumbs.db
|
rastas-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marko Rastas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
rastas-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rastas
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A tiny, zero-dependency ASCII thrush (rastas) that speaks your messages in the terminal.
|
|
5
|
+
Project-URL: Homepage, https://github.com/markorastas/Rastas
|
|
6
|
+
Project-URL: Repository, https://github.com/markorastas/Rastas
|
|
7
|
+
Project-URL: Issues, https://github.com/markorastas/Rastas/issues
|
|
8
|
+
Author: Marko Rastas
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 Marko Rastas
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: ascii,bird,cli,cowsay,fun,rastas,thrush
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: Environment :: Console
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
43
|
+
Classifier: Topic :: Games/Entertainment
|
|
44
|
+
Classifier: Topic :: Terminals
|
|
45
|
+
Requires-Python: >=3.9
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
|
|
48
|
+
# rastas
|
|
49
|
+
|
|
50
|
+
A tiny, zero-dependency Python package and CLI that puts an ASCII thrush (*rastas* in Finnish) in your terminal to speak your messages or share a short quote.
|
|
51
|
+
|
|
52
|
+
> **Note:** This is a small personal hobby package and is not actively maintained. It uses only the Python standard library so it should keep working as-is for years.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install rastas
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Requires Python 3.9 or newer.
|
|
61
|
+
|
|
62
|
+
## Command-line usage
|
|
63
|
+
|
|
64
|
+
Say a custom message:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
rastas "Hello from the terminal!"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Output:
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
__________________________
|
|
74
|
+
< Hello from the terminal! >
|
|
75
|
+
--------------------------
|
|
76
|
+
\
|
|
77
|
+
\ __
|
|
78
|
+
( o)>
|
|
79
|
+
//\
|
|
80
|
+
V_/_
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Pick a random quote (no arguments):
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
rastas
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Change the bird's mood (`default`, `happy`, `sleepy`, `singing`) or bubble width:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
rastas --mood singing "Good morning!"
|
|
93
|
+
rastas --mood sleepy --width 25 "Time for a short break."
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Pipe text from standard input:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
echo "Piped message" | rastas --mood happy
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Python API
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import rastas
|
|
106
|
+
|
|
107
|
+
print(rastas.say("Hello from Python!"))
|
|
108
|
+
print(rastas.say("Feeling great", mood="happy", width=30))
|
|
109
|
+
print(rastas.random_quote())
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT License — see [LICENSE](LICENSE) for details.
|
rastas-0.1.0/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# rastas
|
|
2
|
+
|
|
3
|
+
A tiny, zero-dependency Python package and CLI that puts an ASCII thrush (*rastas* in Finnish) in your terminal to speak your messages or share a short quote.
|
|
4
|
+
|
|
5
|
+
> **Note:** This is a small personal hobby package and is not actively maintained. It uses only the Python standard library so it should keep working as-is for years.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install rastas
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Python 3.9 or newer.
|
|
14
|
+
|
|
15
|
+
## Command-line usage
|
|
16
|
+
|
|
17
|
+
Say a custom message:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
rastas "Hello from the terminal!"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Output:
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
__________________________
|
|
27
|
+
< Hello from the terminal! >
|
|
28
|
+
--------------------------
|
|
29
|
+
\
|
|
30
|
+
\ __
|
|
31
|
+
( o)>
|
|
32
|
+
//\
|
|
33
|
+
V_/_
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Pick a random quote (no arguments):
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
rastas
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Change the bird's mood (`default`, `happy`, `sleepy`, `singing`) or bubble width:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
rastas --mood singing "Good morning!"
|
|
46
|
+
rastas --mood sleepy --width 25 "Time for a short break."
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Pipe text from standard input:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
echo "Piped message" | rastas --mood happy
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Python API
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import rastas
|
|
59
|
+
|
|
60
|
+
print(rastas.say("Hello from Python!"))
|
|
61
|
+
print(rastas.say("Feeling great", mood="happy", width=30))
|
|
62
|
+
print(rastas.random_quote())
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
MIT License — see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rastas"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A tiny, zero-dependency ASCII thrush (rastas) that speaks your messages in the terminal."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Marko Rastas" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["ascii", "bird", "cli", "cowsay", "fun", "rastas", "thrush"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Environment :: Console",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Topic :: Games/Entertainment",
|
|
29
|
+
"Topic :: Terminals",
|
|
30
|
+
]
|
|
31
|
+
dependencies = []
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
rastas = "rastas.cli:main"
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/markorastas/Rastas"
|
|
38
|
+
Repository = "https://github.com/markorastas/Rastas"
|
|
39
|
+
Issues = "https://github.com/markorastas/Rastas/issues"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.build.targets.wheel]
|
|
42
|
+
packages = ["src/rastas"]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Command-line interface for rastas."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from typing import Optional, Sequence
|
|
8
|
+
|
|
9
|
+
from rastas import __version__
|
|
10
|
+
from rastas.say import MOODS, say
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
14
|
+
"""Create the CLI argument parser."""
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="rastas",
|
|
17
|
+
description="Let an ASCII thrush (rastas) speak your message in the terminal.",
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"message",
|
|
21
|
+
nargs="*",
|
|
22
|
+
help="Message for the thrush to say. Reads stdin if piped, or picks a random quote.",
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"-m",
|
|
26
|
+
"--mood",
|
|
27
|
+
choices=sorted(MOODS),
|
|
28
|
+
default="default",
|
|
29
|
+
help="Bird mood (default: %(default)s).",
|
|
30
|
+
)
|
|
31
|
+
parser.add_argument(
|
|
32
|
+
"-w",
|
|
33
|
+
"--width",
|
|
34
|
+
type=int,
|
|
35
|
+
default=40,
|
|
36
|
+
help="Maximum speech bubble text width (default: %(default)s).",
|
|
37
|
+
)
|
|
38
|
+
parser.add_argument(
|
|
39
|
+
"--version",
|
|
40
|
+
action="version",
|
|
41
|
+
version=f"%(prog)s {__version__}",
|
|
42
|
+
)
|
|
43
|
+
return parser
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
47
|
+
"""Run the rastas command-line interface."""
|
|
48
|
+
parser = build_parser()
|
|
49
|
+
args = parser.parse_args(argv)
|
|
50
|
+
|
|
51
|
+
if args.width < 1:
|
|
52
|
+
parser.error("--width must be at least 1")
|
|
53
|
+
|
|
54
|
+
if args.message:
|
|
55
|
+
text: Optional[str] = " ".join(args.message)
|
|
56
|
+
elif argv is None and not sys.stdin.isatty():
|
|
57
|
+
text = sys.stdin.read()
|
|
58
|
+
else:
|
|
59
|
+
text = None
|
|
60
|
+
|
|
61
|
+
print(say(text, mood=args.mood, width=args.width))
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Speech-bubble ASCII thrush (rastas) renderer."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import random
|
|
6
|
+
import textwrap
|
|
7
|
+
from typing import Optional, Sequence
|
|
8
|
+
|
|
9
|
+
QUOTES: tuple[str, ...] = (
|
|
10
|
+
"Early thrush catches the bug.",
|
|
11
|
+
"Simple code flies furthest.",
|
|
12
|
+
"No dependencies, no worries.",
|
|
13
|
+
"Even a small song brightens the morning.",
|
|
14
|
+
"Keep calm and ship small packages.",
|
|
15
|
+
"A tidy nest makes a happy developer.",
|
|
16
|
+
"Readability counts, chirped the thrush.",
|
|
17
|
+
"Test early, sing often.",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
MOODS: dict[str, str] = {
|
|
21
|
+
"default": r"""
|
|
22
|
+
\
|
|
23
|
+
\ __
|
|
24
|
+
( o)>
|
|
25
|
+
//\
|
|
26
|
+
V_/_
|
|
27
|
+
""",
|
|
28
|
+
"happy": r"""
|
|
29
|
+
\
|
|
30
|
+
\ __
|
|
31
|
+
( ^)>
|
|
32
|
+
//\
|
|
33
|
+
V_/_
|
|
34
|
+
""",
|
|
35
|
+
"sleepy": r"""
|
|
36
|
+
\
|
|
37
|
+
\ __
|
|
38
|
+
( -)> zZ
|
|
39
|
+
//\
|
|
40
|
+
V_/_
|
|
41
|
+
""",
|
|
42
|
+
"singing": r"""
|
|
43
|
+
\
|
|
44
|
+
\ __ ~
|
|
45
|
+
( o)> ~
|
|
46
|
+
//\
|
|
47
|
+
V_/_
|
|
48
|
+
""",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def random_quote(rng: Optional[random.Random] = None) -> str:
|
|
53
|
+
"""Return a random short quote."""
|
|
54
|
+
chooser = rng if rng is not None else random
|
|
55
|
+
return chooser.choice(QUOTES)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _wrap_lines(message: str, width: int) -> list[str]:
|
|
59
|
+
"""Wrap message lines to the given maximum width."""
|
|
60
|
+
if width < 1:
|
|
61
|
+
raise ValueError("width must be at least 1")
|
|
62
|
+
|
|
63
|
+
lines: list[str] = []
|
|
64
|
+
for raw_line in message.splitlines() or [""]:
|
|
65
|
+
if not raw_line.strip():
|
|
66
|
+
lines.append("")
|
|
67
|
+
continue
|
|
68
|
+
wrapped = textwrap.wrap(
|
|
69
|
+
raw_line,
|
|
70
|
+
width=width,
|
|
71
|
+
break_long_words=True,
|
|
72
|
+
break_on_hyphens=True,
|
|
73
|
+
)
|
|
74
|
+
lines.extend(wrapped or [""])
|
|
75
|
+
return lines or [""]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _format_bubble(lines: Sequence[str]) -> str:
|
|
79
|
+
"""Wrap text lines in a simple ASCII speech bubble."""
|
|
80
|
+
max_len = max((len(line) for line in lines), default=0)
|
|
81
|
+
top = " " + "_" * (max_len + 2)
|
|
82
|
+
bottom = " " + "-" * (max_len + 2)
|
|
83
|
+
|
|
84
|
+
if len(lines) == 1:
|
|
85
|
+
middle = [f"< {lines[0].ljust(max_len)} >"]
|
|
86
|
+
else:
|
|
87
|
+
middle = []
|
|
88
|
+
last_index = len(lines) - 1
|
|
89
|
+
for idx, line in enumerate(lines):
|
|
90
|
+
padded = line.ljust(max_len)
|
|
91
|
+
if idx == 0:
|
|
92
|
+
middle.append(f"/ {padded} \\")
|
|
93
|
+
elif idx == last_index:
|
|
94
|
+
middle.append(f"\\ {padded} /")
|
|
95
|
+
else:
|
|
96
|
+
middle.append(f"| {padded} |")
|
|
97
|
+
|
|
98
|
+
return "\n".join([top, *middle, bottom])
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def say(
|
|
102
|
+
message: Optional[str] = None,
|
|
103
|
+
*,
|
|
104
|
+
mood: str = "default",
|
|
105
|
+
width: int = 40,
|
|
106
|
+
) -> str:
|
|
107
|
+
"""Render an ASCII thrush speaking a message in a speech bubble.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
message: Text to display. If None or empty, a random quote is chosen.
|
|
111
|
+
mood: Bird expression. One of ``default``, ``happy``, ``sleepy``, ``singing``.
|
|
112
|
+
width: Maximum text width inside the speech bubble.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
Multi-line string containing the speech bubble and ASCII bird.
|
|
116
|
+
"""
|
|
117
|
+
if mood not in MOODS:
|
|
118
|
+
valid = ", ".join(sorted(MOODS))
|
|
119
|
+
raise ValueError(f"Unknown mood {mood!r}. Choose from: {valid}")
|
|
120
|
+
|
|
121
|
+
text = message.strip() if message is not None else ""
|
|
122
|
+
if not text:
|
|
123
|
+
text = random_quote()
|
|
124
|
+
|
|
125
|
+
lines = _wrap_lines(text, width=width)
|
|
126
|
+
bubble = _format_bubble(lines)
|
|
127
|
+
bird = MOODS[mood].strip("\n")
|
|
128
|
+
return f"{bubble}\n{bird}"
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Unit tests for the rastas package."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import io
|
|
6
|
+
import random
|
|
7
|
+
import unittest
|
|
8
|
+
from contextlib import redirect_stdout
|
|
9
|
+
|
|
10
|
+
import rastas
|
|
11
|
+
from rastas import cli
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestRastasSay(unittest.TestCase):
|
|
15
|
+
def test_say_single_line(self) -> None:
|
|
16
|
+
output = rastas.say("Hello, world!")
|
|
17
|
+
self.assertIn("< Hello, world! >", output)
|
|
18
|
+
self.assertIn("( o)>", output)
|
|
19
|
+
|
|
20
|
+
def test_say_multiline_wrapping(self) -> None:
|
|
21
|
+
text = "A very long sentence that should definitely wrap across multiple lines."
|
|
22
|
+
output = rastas.say(text, width=20)
|
|
23
|
+
self.assertIn("/ ", output)
|
|
24
|
+
self.assertIn("\\ ", output)
|
|
25
|
+
|
|
26
|
+
def test_say_random_quote_when_empty(self) -> None:
|
|
27
|
+
output = rastas.say()
|
|
28
|
+
self.assertTrue(any(quote in output for quote in rastas.QUOTES))
|
|
29
|
+
|
|
30
|
+
def test_random_quote_with_seeded_rng(self) -> None:
|
|
31
|
+
rng1 = random.Random(42)
|
|
32
|
+
rng2 = random.Random(42)
|
|
33
|
+
self.assertEqual(rastas.random_quote(rng1), rastas.random_quote(rng2))
|
|
34
|
+
|
|
35
|
+
def test_all_moods_render(self) -> None:
|
|
36
|
+
for mood in rastas.MOODS:
|
|
37
|
+
output = rastas.say("Chirp!", mood=mood)
|
|
38
|
+
self.assertIn("< Chirp! >", output)
|
|
39
|
+
|
|
40
|
+
def test_invalid_mood_raises(self) -> None:
|
|
41
|
+
with self.assertRaises(ValueError):
|
|
42
|
+
rastas.say("Hi", mood="grumpy")
|
|
43
|
+
|
|
44
|
+
def test_invalid_width_raises(self) -> None:
|
|
45
|
+
with self.assertRaises(ValueError):
|
|
46
|
+
rastas.say("Hi", width=0)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class TestRastasCLI(unittest.TestCase):
|
|
50
|
+
def test_cli_with_message(self) -> None:
|
|
51
|
+
buf = io.StringIO()
|
|
52
|
+
with redirect_stdout(buf):
|
|
53
|
+
code = cli.main(["Hello", "from", "CLI"])
|
|
54
|
+
self.assertEqual(code, 0)
|
|
55
|
+
self.assertIn("< Hello from CLI >", buf.getvalue())
|
|
56
|
+
|
|
57
|
+
def test_cli_with_mood(self) -> None:
|
|
58
|
+
buf = io.StringIO()
|
|
59
|
+
with redirect_stdout(buf):
|
|
60
|
+
code = cli.main(["--mood", "happy", "Yay!"])
|
|
61
|
+
self.assertEqual(code, 0)
|
|
62
|
+
self.assertIn("( ^)>", buf.getvalue())
|
|
63
|
+
|
|
64
|
+
def test_cli_without_message_uses_random_quote(self) -> None:
|
|
65
|
+
buf = io.StringIO()
|
|
66
|
+
with redirect_stdout(buf):
|
|
67
|
+
code = cli.main([])
|
|
68
|
+
self.assertEqual(code, 0)
|
|
69
|
+
self.assertIn("< ", buf.getvalue())
|
|
70
|
+
|
|
71
|
+
def test_version_exposed(self) -> None:
|
|
72
|
+
self.assertTrue(isinstance(rastas.__version__, str))
|
|
73
|
+
self.assertGreater(len(rastas.__version__), 0)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
unittest.main()
|