Skip to content

Commit

Permalink
Merge 864b99f into 1e0bd2b
Browse files Browse the repository at this point in the history
  • Loading branch information
nickviola committed Aug 9, 2023
2 parents 1e0bd2b + 864b99f commit 8bb37cf
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# These owners will be the default owners for everything in the
# repo. Unless a later match takes precedence, these owners will be
# requested for review when someone opens a pull request.
* @dav3r @felddy @jasonodoom @jsf9k @mcdonnnj
* @ameliav @jcantu248 @nickviola @schmelz21

# These folks own any files in the .github directory at the root of
# the repository and any of its subdirectories.
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
This is the setup module for the example project.
This is the setup module for the tpt_reports project.
Based on:
Expand Down Expand Up @@ -44,7 +44,7 @@ def get_version(version_file):
setup(
name="tptmple",
# Versions should comply with PEP440
version=get_version("src/example/_version.py"),
version=get_version("src/tpt_reports/_version.py"),
description="TPTmple Python library",
long_description=readme(),
long_description_content_type="text/markdown",
Expand Down Expand Up @@ -88,7 +88,7 @@ def get_version(version_file):
keywords="skeleton",
packages=find_packages(where="src"),
package_dir={"": "src"},
package_data={"example": ["data/*.txt"]},
package_data={"tpt_reports": ["data/*.txt"]},
py_modules=[splitext(basename(path))[0] for path in glob("src/*.py")],
include_package_data=True,
install_requires=["docopt", "schema", "setuptools >= 24.2.0"],
Expand All @@ -107,6 +107,6 @@ def get_version(version_file):
"pytest",
]
},
# Conveniently allows one to run the CLI tool as `example`
entry_points={"console_scripts": ["tptmple = example.etptple:main"]},
# Conveniently allows one to run the CLI tool as `tpt_reports`
entry_points={"console_scripts": ["tptmple = tpt_reports.etptple:main"]},
)
1 change: 0 additions & 1 deletion src/example/data/secret.txt

This file was deleted.

6 changes: 3 additions & 3 deletions src/example/__init__.py → src/tpt_reports/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""The example library."""
"""The tpt_reports library."""
# We disable a Flake8 check for "Module imported but unused (F401)" here because
# although this import is not directly used, it populates the value
# package_name.__version__, which is used to get version information about this
# Python package.
from ._version import __version__ # noqa: F401
from .example import example_div
from .tpt_reports import tpt_report_div

__all__ = ["example_div"]
__all__ = ["tpt_report_div"]
2 changes: 1 addition & 1 deletion src/example/__main__.py → src/tpt_reports/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Code to run if this package is used as a Python module."""

from .example import main
from .tpt_reports import main

main()
File renamed without changes.
19 changes: 7 additions & 12 deletions src/example/example.py → src/tpt_reports/tpt_reports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""example is an example Python library and tool.
"""tpt_reports is a report generation Python library and tool.
Divide one integer by another and log the result. Also log some information
from an environment variable and a package resource.
Expand Down Expand Up @@ -27,15 +27,16 @@

# Third-Party Libraries
import docopt
import pkg_resources

# import pkg_resources
from schema import And, Schema, SchemaError, Use

from ._version import __version__

DEFAULT_ECHO_MESSAGE: str = "Hello World from the example default!"
DEFAULT_ECHO_MESSAGE: str = "Hello World from the tpt_reports default!"


def example_div(dividend: int, divisor: int) -> float:
def tpt_report_div(dividend: int, divisor: int) -> float:
"""Print some logging messages."""
logging.debug("This is a debug message")
logging.info("This is an info message")
Expand All @@ -46,7 +47,7 @@ def example_div(dividend: int, divisor: int) -> float:


def main() -> None:
"""Set up logging and call the example function."""
"""Set up logging and call the tpt_report function."""
args: Dict[str, str] = docopt.docopt(__doc__, version=__version__)
# Validate and convert arguments as needed
schema: Schema = Schema(
Expand Down Expand Up @@ -85,19 +86,13 @@ def main() -> None:
format="%(asctime)-15s %(levelname)s %(message)s", level=log_level.upper()
)

logging.info("%d / %d == %f", dividend, divisor, example_div(dividend, divisor))
logging.info("%d / %d == %f", dividend, divisor, tpt_report_div(dividend, divisor))

# Access some data from an environment variable
message: str = os.getenv("ECHO_MESSAGE", DEFAULT_ECHO_MESSAGE)
logging.info('ECHO_MESSAGE="%s"', message)

# Access some data from our package data (see the setup.py)
secret_message: str = (
pkg_resources.resource_string("example", "data/secret.txt")
.decode("utf-8")
.strip()
)
logging.info('Secret="%s"', secret_message)

# Stop logging and clean up
logging.shutdown()
22 changes: 11 additions & 11 deletions tests/test_example.py → tests/test_tpt_reports.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env pytest -vs
"""Tests for example."""
"""Tests for tpt_reports."""

# Standard Python Libraries
import logging
Expand All @@ -11,7 +11,7 @@
import pytest

# cisagov Libraries
import example
import tpt_reports

div_params = [
(1, 1, 1),
Expand All @@ -30,14 +30,14 @@

# define sources of version strings
RELEASE_TAG = os.getenv("RELEASE_TAG")
PROJECT_VERSION = example.__version__
PROJECT_VERSION = tpt_reports.__version__


def test_stdout_version(capsys):
"""Verify that version string sent to stdout agrees with the module version."""
with pytest.raises(SystemExit):
with patch.object(sys, "argv", ["bogus", "--version"]):
example.example.main()
tpt_reports.tpt_reports.main()
captured = capsys.readouterr()
assert (
captured.out == f"{PROJECT_VERSION}\n"
Expand All @@ -54,7 +54,7 @@ def test_running_as_module(capsys):
# package and running it, so there is nothing to use from this
# import. As a result, we can safely ignore this warning.
# cisagov Libraries
import example.__main__ # noqa: F401
import tpt_reports.__main__ # noqa: F401
captured = capsys.readouterr()
assert (
captured.out == f"{PROJECT_VERSION}\n"
Expand All @@ -81,7 +81,7 @@ def test_log_levels(level):
), "root logger should not have handlers yet"
return_code = None
try:
example.example.main()
tpt_reports.tpt_reports.main()
except SystemExit as sys_exit:
return_code = sys_exit.code
assert return_code is None, "main() should return success"
Expand All @@ -99,7 +99,7 @@ def test_bad_log_level():
with patch.object(sys, "argv", ["bogus", "--log-level=emergency", "1", "1"]):
return_code = None
try:
example.example.main()
tpt_reports.tpt_reports.main()
except SystemExit as sys_exit:
return_code = sys_exit.code
assert return_code == 1, "main() should exit with error"
Expand All @@ -108,7 +108,7 @@ def test_bad_log_level():
@pytest.mark.parametrize("dividend, divisor, quotient", div_params)
def test_division(dividend, divisor, quotient):
"""Verify division results."""
result = example.example_div(dividend, divisor)
result = tpt_reports.tpt_report_div(dividend, divisor)
assert result == quotient, "result should equal quotient"


Expand All @@ -122,23 +122,23 @@ def test_slow_division():
# Standard Python Libraries
import time

result = example.example_div(256, 16)
result = tpt_reports.tpt_report_div(256, 16)
time.sleep(4)
assert result == 16, "result should equal be 16"


def test_zero_division():
"""Verify that division by zero throws the correct exception."""
with pytest.raises(ZeroDivisionError):
example.example_div(1, 0)
tpt_reports.tpt_report_div(1, 0)


def test_zero_divisor_argument():
"""Verify that a divisor of zero is handled as expected."""
with patch.object(sys, "argv", ["bogus", "1", "0"]):
return_code = None
try:
example.example.main()
tpt_reports.tpt_reports.main()
except SystemExit as sys_exit:
return_code = sys_exit.code
assert return_code == 1, "main() should exit with error"

0 comments on commit 8bb37cf

Please sign in to comment.