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:
|
||||
|
||||
* Second GitHub release update
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
* @charlesreid1
|
||||
* @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
|
||||
from typing import Any
|
||||
import os
|
||||
from .error import PittFall
|
||||
|
||||
|
||||
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:
|
||||
"""Initialize Alpha with an optional name (defaults to 'default')."""
|
||||
self.name: str = kwargs.get("name", "default")
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Donec et magna pulvinar, suscipit ante in, aliquet felis."""
|
||||
self.name = None
|
||||
if "name" in kwargs:
|
||||
self.name = kwargs["name"]
|
||||
else:
|
||||
self.name = "default"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Alpha(name={self.name!r})"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Alpha({self.name})"
|
||||
|
||||
def adder(self, *args: float) -> float:
|
||||
"""Return the sum of all provided numeric arguments."""
|
||||
def adder(self, *args):
|
||||
"""Donec placerat faucibus dignissim."""
|
||||
try:
|
||||
return sum(args)
|
||||
s = sum(args)
|
||||
except TypeError:
|
||||
raise PittFall(f"{self.__class__.__name__}: Error: could not adder() stuff")
|
||||
|
||||
def affix(self, param1: Any, param2: Any, param3: Any) -> Any:
|
||||
"""Randomly return one of the three provided parameters."""
|
||||
def affix(self, param1, param2, param3):
|
||||
"""In hac habitasse platea dictumst."""
|
||||
if random.random() < 0.5:
|
||||
if random.random() < 0.5:
|
||||
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
|
||||
|
||||
|
||||
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:
|
||||
"""Initialize Beta with a required tracking_id keyword argument."""
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Morbi dapibus ligula in posuere volutpat."""
|
||||
try:
|
||||
self.tracking_id: str = kwargs["tracking_id"]
|
||||
self.tracking_id = kwargs["tracking_id"]
|
||||
except KeyError:
|
||||
raise PittFall(
|
||||
f"{self.__class__.__name__}: Error: could not find a tracking id"
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Beta(tracking_id={self.tracking_id!r})"
|
||||
def beeps(self, **kwargs):
|
||||
"""Nulla imperdiet, turpis eu vulputate pulvinar, felis erat facilisis nisl."""
|
||||
self.storage = dict(**kwargs)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Beta({self.tracking_id})"
|
||||
|
||||
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."""
|
||||
def beers(self, **kwargs):
|
||||
"""Sed a lacus neque. Vestibulum aliquet augue nec urna aliquet, eu rutrum nisl auctor."""
|
||||
no_storage = dict(**kwargs)
|
||||
return no_storage
|
||||
|
||||
def billy(self) -> str:
|
||||
"""Return the tracking_id assigned at initialization."""
|
||||
def billy(self):
|
||||
"""Curabitur cursus leo pellentesque enim tristique, quis bibendum ante rhoncus."""
|
||||
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 .error import PittFall
|
||||
from .util import random_fact
|
||||
from . import __version__
|
||||
|
||||
|
||||
@click.group()
|
||||
@click.version_option(version=__version__, prog_name="brad-pitt")
|
||||
def main():
|
||||
"""The brad-pitt CLI - a demo Python package."""
|
||||
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.command()
|
||||
def main(args=None):
|
||||
"""Console script for brad_pitt."""
|
||||
click.echo("You are about to use the bradd-pitt library")
|
||||
click.echo(" - Using Alpha class")
|
||||
a = Alpha(name="adios")
|
||||
result = a.adder(1, 2)
|
||||
click.echo(f" adder(1, 2) = {result}")
|
||||
a.adder(1, 2)
|
||||
click.echo(" - Using Beta class")
|
||||
b = Beta(tracking_id="12345")
|
||||
data = b.beers(foo="hello", world="bar")
|
||||
click.echo(f" beers() = {data}")
|
||||
b.beers(foo="hello", world="bar")
|
||||
click.echo(f" - Brad Pitt fact: {random_fact()}")
|
||||
click.echo("Congrats! You successfully used the brad-pitt library!")
|
||||
|
||||
|
||||
@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)
|
||||
click.echo("Congrats! You successfully used the bradd-pitt library!")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
35
src/gamma.py
35
src/gamma.py
@@ -1,33 +1,28 @@
|
||||
import os
|
||||
import random
|
||||
from typing import Any, Tuple
|
||||
from .error import PittFall
|
||||
from .alpha import Alpha
|
||||
from .beta import Beta
|
||||
|
||||
|
||||
class Gamma(object):
|
||||
"""A composite entity that combines Alpha and Beta functionality."""
|
||||
"""Praesent dapibus cursus imperdiet."""
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""Initialize Gamma with internal Alpha and Beta instances."""
|
||||
self.alpha = Alpha()
|
||||
self.beta = Beta(tracking_id="abc123")
|
||||
def __init__(self, *args, **kwargs):
|
||||
""" Mauris sagittis molestie ante eget tincidunt. Integer ut leo quis nisi semper maximus."""
|
||||
a = Alpha()
|
||||
b = Beta(tracking_id="abc123")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Gamma(alpha={self.alpha!r}, beta={self.beta!r})"
|
||||
def grape(self, **kwargs):
|
||||
"""Cras vestibulum magna ut ex rhoncus faucibus. Cras eget dolor velit."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Gamma({self.alpha}, {self.beta})"
|
||||
|
||||
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)
|
||||
def gleams(self, **kwargs):
|
||||
"""Vivamus gravida, tellus a facilisis lobortis, massa neque lacinia arcu, vel bibendum ipsum felis sit amet purus."""
|
||||
x = random.randint(1,6)
|
||||
return x
|
||||
|
||||
def goopy(self) -> Tuple[Alpha, Beta]:
|
||||
"""Return the internal Alpha and Beta instances as a tuple."""
|
||||
def goopy(self):
|
||||
"""Duis ultricies risus vitae ex molestie pellentesque. Proin ornare eleifend maximus."""
|
||||
return self.alpha, self.beta
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import os
|
||||
import random
|
||||
import json
|
||||
from .error import PittFall
|
||||
|
||||
|
||||
def random_fact() -> str:
|
||||
"""Return a random Brad Pitt fact from the bundled JSON data file."""
|
||||
def random_fact():
|
||||
facts = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'brad_pitt_facts.json')
|
||||
if not os.path.exists(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