• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cisagov / skeleton-python-library / 7293313047

21 Dec 2023 09:20PM CUT coverage: 100.0%. Remained the same
7293313047

Pull #128

github

web-flow
Bump github/codeql-action from 2 to 3

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #128: Bump github/codeql-action from 2 to 3

2 of 2 branches covered (100.0%)

Branch coverage included in aggregate %.

40 of 40 relevant lines covered (100.0%)

7.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/example/example.py
1
"""example is an example Python library and tool.
2

3
Divide one integer by another and log the result. Also log some information
4
from an environment variable and a package resource.
5

6
EXIT STATUS
7
    This utility exits with one of the following values:
8
    0   Calculation completed successfully.
9
    >0  An error occurred.
10

11
Usage:
12
  example [--log-level=LEVEL] <dividend> <divisor>
13
  example (-h | --help)
14

15
Options:
16
  -h --help              Show this message.
17
  --log-level=LEVEL      If specified, then the log level will be set to
18
                         the specified value.  Valid values are "debug", "info",
19
                         "warning", "error", and "critical". [default: info]
20
"""
21

22
# Standard Python Libraries
23
import logging
7✔
24
import os
7✔
25
import sys
7✔
26
from typing import Any, Dict
7✔
27

28
# Third-Party Libraries
29
import docopt
7✔
30
import pkg_resources
7✔
31
from schema import And, Schema, SchemaError, Use
7✔
32

33
from ._version import __version__
7✔
34

35
DEFAULT_ECHO_MESSAGE: str = "Hello World from the example default!"
7✔
36

37

38
def example_div(dividend: int, divisor: int) -> float:
7✔
39
    """Print some logging messages."""
40
    logging.debug("This is a debug message")
7✔
41
    logging.info("This is an info message")
7✔
42
    logging.warning("This is a warning message")
7✔
43
    logging.error("This is an error message")
7✔
44
    logging.critical("This is a critical message")
7✔
45
    return dividend / divisor
7✔
46

47

48
def main() -> None:
7✔
49
    """Set up logging and call the example function."""
50
    args: Dict[str, str] = docopt.docopt(__doc__, version=__version__)
7✔
51
    # Validate and convert arguments as needed
52
    schema: Schema = Schema(
7✔
53
        {
54
            "--log-level": And(
55
                str,
56
                Use(str.lower),
57
                lambda n: n in ("debug", "info", "warning", "error", "critical"),
58
                error="Possible values for --log-level are "
59
                + "debug, info, warning, error, and critical.",
60
            ),
61
            "<dividend>": Use(int, error="<dividend> must be an integer."),
62
            "<divisor>": And(
63
                Use(int),
64
                lambda n: n != 0,
65
                error="<divisor> must be an integer that is not 0.",
66
            ),
67
            str: object,  # Don't care about other keys, if any
68
        }
69
    )
70

71
    try:
7✔
72
        validated_args: Dict[str, Any] = schema.validate(args)
7✔
73
    except SchemaError as err:
7✔
74
        # Exit because one or more of the arguments were invalid
75
        print(err, file=sys.stderr)
7✔
76
        sys.exit(1)
7✔
77

78
    # Assign validated arguments to variables
79
    dividend: int = validated_args["<dividend>"]
7✔
80
    divisor: int = validated_args["<divisor>"]
7✔
81
    log_level: str = validated_args["--log-level"]
7✔
82

83
    # Set up logging
84
    logging.basicConfig(
7✔
85
        format="%(asctime)-15s %(levelname)s %(message)s", level=log_level.upper()
86
    )
87

88
    logging.info("%d / %d == %f", dividend, divisor, example_div(dividend, divisor))
7✔
89

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

94
    # Access some data from our package data (see the setup.py)
95
    secret_message: str = (
7✔
96
        pkg_resources.resource_string("example", "data/secret.txt")
97
        .decode("utf-8")
98
        .strip()
99
    )
100
    logging.info('Secret="%s"', secret_message)
7✔
101

102
    # Stop logging and clean up
103
    logging.shutdown()
7✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc