Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5dd71d77dd |
30
CHANGELOG
30
CHANGELOG
@@ -1,33 +1,3 @@
|
|||||||
v0.6.6:
|
|
||||||
|
|
||||||
* Bug fixes: alpha.adder() now returns its result, missing random import
|
|
||||||
* Bug fix: gamma.goopy() now works (instance attributes stored correctly)
|
|
||||||
* Bug fix: util.random_fact() now imports PittFall correctly
|
|
||||||
* Replaced Lorem Ipsum docstrings with meaningful documentation
|
|
||||||
* Added type hints to all modules
|
|
||||||
* Added unit test suite (17 tests covering all modules)
|
|
||||||
* Expanded CLI with subcommands: demo, fact, add
|
|
||||||
* Added __main__.py for python -m brad_pitt support
|
|
||||||
* Added __repr__ and __str__ to Alpha, Beta, and Gamma
|
|
||||||
* Implemented Gamma.grape() method
|
|
||||||
* Updated CHANGELOG with missing version entries
|
|
||||||
|
|
||||||
v0.6.5:
|
|
||||||
|
|
||||||
* Check for bump2version before running version targets
|
|
||||||
|
|
||||||
v0.6.4:
|
|
||||||
|
|
||||||
* Add links to older and newer versions in docs
|
|
||||||
|
|
||||||
v0.6.3:
|
|
||||||
|
|
||||||
* Fix author metadata in setup.py
|
|
||||||
|
|
||||||
v0.6.0:
|
|
||||||
|
|
||||||
* Versioned documentation with mike
|
|
||||||
|
|
||||||
v0.5.0:
|
v0.5.0:
|
||||||
|
|
||||||
* Second GitHub release update
|
* Second GitHub release update
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
* @charlesreid1
|
||||||
* @charlesreid1acom
|
* @charlesreid1acom
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
"""Allow running the package with: python -m brad_pitt"""
|
|
||||||
from .cli import main
|
|
||||||
|
|
||||||
main()
|
|
||||||
31
src/alpha.py
31
src/alpha.py
@@ -1,30 +1,27 @@
|
|||||||
import random
|
import os
|
||||||
from typing import Any
|
|
||||||
from .error import PittFall
|
from .error import PittFall
|
||||||
|
|
||||||
|
|
||||||
class Alpha(object):
|
class Alpha(object):
|
||||||
"""A named entity that provides arithmetic and random selection utilities."""
|
"""Ut eu augue accumsan, venenatis nulla quis, elementum dui."""
|
||||||
|
|
||||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize Alpha with an optional name (defaults to 'default')."""
|
"""Donec et magna pulvinar, suscipit ante in, aliquet felis."""
|
||||||
self.name: str = kwargs.get("name", "default")
|
self.name = None
|
||||||
|
if "name" in kwargs:
|
||||||
|
self.name = kwargs["name"]
|
||||||
|
else:
|
||||||
|
self.name = "default"
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def adder(self, *args):
|
||||||
return f"Alpha(name={self.name!r})"
|
"""Donec placerat faucibus dignissim."""
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return f"Alpha({self.name})"
|
|
||||||
|
|
||||||
def adder(self, *args: float) -> float:
|
|
||||||
"""Return the sum of all provided numeric arguments."""
|
|
||||||
try:
|
try:
|
||||||
return sum(args)
|
s = sum(args)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
raise PittFall(f"{self.__class__.__name__}: Error: could not adder() stuff")
|
raise PittFall(f"{self.__class__.__name__}: Error: could not adder() stuff")
|
||||||
|
|
||||||
def affix(self, param1: Any, param2: Any, param3: Any) -> Any:
|
def affix(self, param1, param2, param3):
|
||||||
"""Randomly return one of the three provided parameters."""
|
"""In hac habitasse platea dictumst."""
|
||||||
if random.random() < 0.5:
|
if random.random() < 0.5:
|
||||||
if random.random() < 0.5:
|
if random.random() < 0.5:
|
||||||
return param1
|
return param1
|
||||||
|
|||||||
30
src/beta.py
30
src/beta.py
@@ -1,34 +1,28 @@
|
|||||||
from typing import Any, Dict
|
import os
|
||||||
from .error import PittFall
|
from .error import PittFall
|
||||||
|
|
||||||
|
|
||||||
class Beta(object):
|
class Beta(object):
|
||||||
"""A tracked entity that stores and retrieves keyword-based data."""
|
"""Praesent dapibus cursus imperdiet."""
|
||||||
|
|
||||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize Beta with a required tracking_id keyword argument."""
|
"""Morbi dapibus ligula in posuere volutpat."""
|
||||||
try:
|
try:
|
||||||
self.tracking_id: str = kwargs["tracking_id"]
|
self.tracking_id = kwargs["tracking_id"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise PittFall(
|
raise PittFall(
|
||||||
f"{self.__class__.__name__}: Error: could not find a tracking id"
|
f"{self.__class__.__name__}: Error: could not find a tracking id"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def beeps(self, **kwargs):
|
||||||
return f"Beta(tracking_id={self.tracking_id!r})"
|
"""Nulla imperdiet, turpis eu vulputate pulvinar, felis erat facilisis nisl."""
|
||||||
|
self.storage = dict(**kwargs)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def beers(self, **kwargs):
|
||||||
return f"Beta({self.tracking_id})"
|
"""Sed a lacus neque. Vestibulum aliquet augue nec urna aliquet, eu rutrum nisl auctor."""
|
||||||
|
|
||||||
def beeps(self, **kwargs: Any) -> None:
|
|
||||||
"""Store keyword arguments as a dictionary on the instance."""
|
|
||||||
self.storage: Dict[str, Any] = dict(**kwargs)
|
|
||||||
|
|
||||||
def beers(self, **kwargs: Any) -> Dict[str, Any]:
|
|
||||||
"""Return keyword arguments as a new dictionary without storing them."""
|
|
||||||
no_storage = dict(**kwargs)
|
no_storage = dict(**kwargs)
|
||||||
return no_storage
|
return no_storage
|
||||||
|
|
||||||
def billy(self) -> str:
|
def billy(self):
|
||||||
"""Return the tracking_id assigned at initialization."""
|
"""Curabitur cursus leo pellentesque enim tristique, quis bibendum ante rhoncus."""
|
||||||
return self.tracking_id
|
return self.tracking_id
|
||||||
|
|||||||
40
src/cli.py
40
src/cli.py
@@ -5,45 +5,21 @@ from .alpha import Alpha
|
|||||||
from .beta import Beta
|
from .beta import Beta
|
||||||
from .error import PittFall
|
from .error import PittFall
|
||||||
from .util import random_fact
|
from .util import random_fact
|
||||||
from . import __version__
|
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.command()
|
||||||
@click.version_option(version=__version__, prog_name="brad-pitt")
|
def main(args=None):
|
||||||
def main():
|
"""Console script for brad_pitt."""
|
||||||
"""The brad-pitt CLI - a demo Python package."""
|
click.echo("You are about to use the bradd-pitt library")
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@main.command()
|
|
||||||
def demo():
|
|
||||||
"""Run a quick demo of the brad-pitt library."""
|
|
||||||
click.echo("You are about to use the brad-pitt library")
|
|
||||||
click.echo(" - Using Alpha class")
|
click.echo(" - Using Alpha class")
|
||||||
a = Alpha(name="adios")
|
a = Alpha(name="adios")
|
||||||
result = a.adder(1, 2)
|
a.adder(1, 2)
|
||||||
click.echo(f" adder(1, 2) = {result}")
|
|
||||||
click.echo(" - Using Beta class")
|
click.echo(" - Using Beta class")
|
||||||
b = Beta(tracking_id="12345")
|
b = Beta(tracking_id="12345")
|
||||||
data = b.beers(foo="hello", world="bar")
|
b.beers(foo="hello", world="bar")
|
||||||
click.echo(f" beers() = {data}")
|
|
||||||
click.echo(f" - Brad Pitt fact: {random_fact()}")
|
click.echo(f" - Brad Pitt fact: {random_fact()}")
|
||||||
click.echo("Congrats! You successfully used the brad-pitt library!")
|
click.echo("Congrats! You successfully used the bradd-pitt library!")
|
||||||
|
return 0
|
||||||
|
|
||||||
@main.command()
|
|
||||||
def fact():
|
|
||||||
"""Display a random Brad Pitt fact."""
|
|
||||||
click.echo(random_fact())
|
|
||||||
|
|
||||||
|
|
||||||
@main.command()
|
|
||||||
@click.argument("numbers", nargs=-1, type=float, required=True)
|
|
||||||
def add(numbers):
|
|
||||||
"""Sum the provided numbers using Alpha.adder()."""
|
|
||||||
a = Alpha()
|
|
||||||
result = a.adder(*numbers)
|
|
||||||
click.echo(result)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
33
src/gamma.py
33
src/gamma.py
@@ -1,33 +1,28 @@
|
|||||||
|
import os
|
||||||
import random
|
import random
|
||||||
from typing import Any, Tuple
|
|
||||||
from .error import PittFall
|
from .error import PittFall
|
||||||
from .alpha import Alpha
|
from .alpha import Alpha
|
||||||
from .beta import Beta
|
from .beta import Beta
|
||||||
|
|
||||||
|
|
||||||
class Gamma(object):
|
class Gamma(object):
|
||||||
"""A composite entity that combines Alpha and Beta functionality."""
|
"""Praesent dapibus cursus imperdiet."""
|
||||||
|
|
||||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize Gamma with internal Alpha and Beta instances."""
|
""" Mauris sagittis molestie ante eget tincidunt. Integer ut leo quis nisi semper maximus."""
|
||||||
self.alpha = Alpha()
|
a = Alpha()
|
||||||
self.beta = Beta(tracking_id="abc123")
|
b = Beta(tracking_id="abc123")
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def grape(self, **kwargs):
|
||||||
return f"Gamma(alpha={self.alpha!r}, beta={self.beta!r})"
|
"""Cras vestibulum magna ut ex rhoncus faucibus. Cras eget dolor velit."""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def gleams(self, **kwargs):
|
||||||
return f"Gamma({self.alpha}, {self.beta})"
|
"""Vivamus gravida, tellus a facilisis lobortis, massa neque lacinia arcu, vel bibendum ipsum felis sit amet purus."""
|
||||||
|
|
||||||
def grape(self, **kwargs: Any) -> str:
|
|
||||||
"""Combine keyword arguments into a sorted, comma-separated string."""
|
|
||||||
return ", ".join(f"{k}={v}" for k, v in sorted(kwargs.items()))
|
|
||||||
|
|
||||||
def gleams(self, **kwargs: Any) -> int:
|
|
||||||
"""Return a random integer between 1 and 6 (simulates a dice roll)."""
|
|
||||||
x = random.randint(1,6)
|
x = random.randint(1,6)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def goopy(self) -> Tuple[Alpha, Beta]:
|
def goopy(self):
|
||||||
"""Return the internal Alpha and Beta instances as a tuple."""
|
"""Duis ultricies risus vitae ex molestie pellentesque. Proin ornare eleifend maximus."""
|
||||||
return self.alpha, self.beta
|
return self.alpha, self.beta
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
from .error import PittFall
|
|
||||||
|
|
||||||
|
|
||||||
def random_fact() -> str:
|
def random_fact():
|
||||||
"""Return a random Brad Pitt fact from the bundled JSON data file."""
|
|
||||||
facts = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'brad_pitt_facts.json')
|
facts = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'brad_pitt_facts.json')
|
||||||
if not os.path.exists(facts):
|
if not os.path.exists(facts):
|
||||||
raise PittFall(f"random_fact: Error: Could not find data/brad_pitt_facts.json. Looked in {facts}")
|
raise PittFall(f"random_fact: Error: Could not find data/brad_pitt_facts.json. Looked in {facts}")
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from brad_pitt.alpha import Alpha
|
|
||||||
from brad_pitt.error import PittFall
|
|
||||||
|
|
||||||
|
|
||||||
class TestAlphaInit:
|
|
||||||
def test_default_name(self):
|
|
||||||
a = Alpha()
|
|
||||||
assert a.name == "default"
|
|
||||||
|
|
||||||
def test_custom_name(self):
|
|
||||||
a = Alpha(name="brad")
|
|
||||||
assert a.name == "brad"
|
|
||||||
|
|
||||||
|
|
||||||
class TestAdder:
|
|
||||||
def test_sum_integers(self):
|
|
||||||
a = Alpha()
|
|
||||||
assert a.adder(1, 2, 3) == 6
|
|
||||||
|
|
||||||
def test_sum_floats(self):
|
|
||||||
a = Alpha()
|
|
||||||
assert a.adder(1.5, 2.5) == 4.0
|
|
||||||
|
|
||||||
def test_empty_args(self):
|
|
||||||
a = Alpha()
|
|
||||||
assert a.adder() == 0
|
|
||||||
|
|
||||||
def test_non_numeric_raises_pittfall(self):
|
|
||||||
a = Alpha()
|
|
||||||
with pytest.raises(PittFall):
|
|
||||||
a.adder("a", "b")
|
|
||||||
|
|
||||||
|
|
||||||
class TestAffix:
|
|
||||||
def test_returns_one_of_three(self):
|
|
||||||
a = Alpha()
|
|
||||||
results = {a.affix("x", "y", "z") for _ in range(200)}
|
|
||||||
assert results.issubset({"x", "y", "z"})
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from brad_pitt.beta import Beta
|
|
||||||
from brad_pitt.error import PittFall
|
|
||||||
|
|
||||||
|
|
||||||
class TestBetaInit:
|
|
||||||
def test_requires_tracking_id(self):
|
|
||||||
with pytest.raises(PittFall):
|
|
||||||
Beta()
|
|
||||||
|
|
||||||
def test_stores_tracking_id(self):
|
|
||||||
b = Beta(tracking_id="xyz")
|
|
||||||
assert b.tracking_id == "xyz"
|
|
||||||
|
|
||||||
|
|
||||||
class TestBeeps:
|
|
||||||
def test_stores_kwargs(self):
|
|
||||||
b = Beta(tracking_id="1")
|
|
||||||
b.beeps(a=1, b=2)
|
|
||||||
assert b.storage == {"a": 1, "b": 2}
|
|
||||||
|
|
||||||
|
|
||||||
class TestBeers:
|
|
||||||
def test_returns_kwargs(self):
|
|
||||||
b = Beta(tracking_id="1")
|
|
||||||
result = b.beers(foo="bar")
|
|
||||||
assert result == {"foo": "bar"}
|
|
||||||
|
|
||||||
|
|
||||||
class TestBilly:
|
|
||||||
def test_returns_tracking_id(self):
|
|
||||||
b = Beta(tracking_id="abc")
|
|
||||||
assert b.billy() == "abc"
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
import pytest
|
|
||||||
from brad_pitt.gamma import Gamma
|
|
||||||
from brad_pitt.alpha import Alpha
|
|
||||||
from brad_pitt.beta import Beta
|
|
||||||
|
|
||||||
|
|
||||||
class TestGammaInit:
|
|
||||||
def test_creates_alpha_and_beta(self):
|
|
||||||
g = Gamma()
|
|
||||||
assert isinstance(g.alpha, Alpha)
|
|
||||||
assert isinstance(g.beta, Beta)
|
|
||||||
|
|
||||||
|
|
||||||
class TestGleams:
|
|
||||||
def test_returns_int_in_range(self):
|
|
||||||
g = Gamma()
|
|
||||||
for _ in range(100):
|
|
||||||
result = g.gleams()
|
|
||||||
assert 1 <= result <= 6
|
|
||||||
|
|
||||||
|
|
||||||
class TestGoopy:
|
|
||||||
def test_returns_alpha_beta_tuple(self):
|
|
||||||
g = Gamma()
|
|
||||||
alpha, beta = g.goopy()
|
|
||||||
assert isinstance(alpha, Alpha)
|
|
||||||
assert isinstance(beta, Beta)
|
|
||||||
|
|
||||||
|
|
||||||
class TestGrape:
|
|
||||||
def test_empty_kwargs(self):
|
|
||||||
g = Gamma()
|
|
||||||
assert g.grape() == ""
|
|
||||||
|
|
||||||
def test_sorted_output(self):
|
|
||||||
g = Gamma()
|
|
||||||
assert g.grape(z=3, a=1, m=2) == "a=1, m=2, z=3"
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
from brad_pitt.util import random_fact
|
|
||||||
|
|
||||||
|
|
||||||
class TestRandomFact:
|
|
||||||
def test_returns_string(self):
|
|
||||||
fact = random_fact()
|
|
||||||
assert isinstance(fact, str)
|
|
||||||
assert len(fact) > 0
|
|
||||||
Reference in New Issue
Block a user